Change Hostname in Ubuntu

I had this problem where the hostname I had chosen was the same on another Windows machine on the network. Therefore, I was unable to browse the network in Gutsy Gibbon. I wanted to change the hostname so I tried the following:

sudo hostname mybrandnewname

But it would not change. It would say the name had changed but after a reboot the old name would be restored. So people at Ubuntu Forums helped someone in the same predicament. The user was unable to change hostname. I followed their instructions and here they are

sudo vim /etc/hosts

Change the old hostname to the new one. For example, my /etc/hosts file said oldhostname

So I changed it to newhostname

I also edited the /etc/hostname file.

sudo vim /etc/hostname

It read


So I changed it to


After doing the following, the new hostname stuck as required.

sudo /etc/init.d/ stop

sudo /etc/init.d/ start

And then logout of your shell and log back in.

sudo /etc/init.d/network restart
sudo /etc/init.d/networking restart

You should really read hostname error not resolving for more details.

As for my original problem of not being able to browse the network, it was solved with this fix.

10 Responses to Change Hostname in Ubuntu

  1. Pingback: OrgaNeLaS - Shell script para backup usando rsync e ssh em DHCP no Ubuntu

  2. Anonymous says:

    instead: “sudo /etc/init.d/network restart”, the right line: “sudo /etc/init.d/networking restart”

  3. hs says:

    Thanks for pointing it out. It’s been fixed.

  4. Pingback: Ubuntu/Debian hostname 바꾸는 방법 « turtle9

  5. abu azam says:

    Hi, thanks for your post. it solved my problem. I tried to do it myself but i forgot to add it in the /etc/hosts.

  6. adandoush says:

    Nice post. and It is important to follow the order of things

  7. this is my test comment

  8. Gyp The Cat says:

    Old post, but a good one, fixed my problem on a VPS :) Thanks.

  9. Anonymous says:

    For Ubuntu:

    gksudo gedit /etc/home

  10. saurabh says:

    For Ubuntu:

    gksudo gedit /etc/home

%d bloggers like this: