Custom Search

How to change hostname in Ubuntu server

Change a hostname in Ubuntu server is very easy. From the command line terminal, type hostname newname. View the new hostname with hostname command. See the step by step example on how to change Ubuntu server hostname below:

1) View current hostname:

luzar@hitam:~$ hostname

2) Change hostname and view latest hostname:

luzar@hitam:~$ sudo hostname ubuntu
luzar@hitam:~$ hostname

See, that's how easy it is. Heh, don't fall for it. That doesn't change anything. The hostname is still the same as you can see at the prompt. Even reboot won't change anything. The exact method to change the hostname permanently is by editing /etc/hostname file. Here is the step:

1) Open /etc/hostname with your favorite text editor:

luzar@hitam:~$ sudo vim /etc/hostname
[sudo] password for luzar:

Here the vim /etc/hostname screenshot:

Now you can change hostname and save. The changed is permanent even after you reboot your system.

Important: You also need to edit the /etc/hosts file and apply the changes. Otherwise, you won't be able to use sudo after the reboot.

That's it.


  1. Worked like a charm for me. THanks.

  2. Don't forget the entry in the /etc/hosts file may still be the old name next to

  3. sweet man thanks, remember to edit the /etc/hosts like Gregor said as sudo quits working and you have to unlock your root account to fix it.

  4. I just hosted my server because of this guide. The requirement of editing /etc/hosts needs to be in your article, not just the comments. Lesson learned, and chances are I had to rebuild anyway after the hostname change with everything else on the box, so no huge loss. Please update your article so others do not have to go though this. Thanks

  5. If you want learn how to change your hostname (computer name) on Ubuntu Server you can take a look at Change hostname (computer name) on Ubuntu Server (video tutorial).


Please keep comment relevant and strictly no spam will be tolerated. Thank you.