Ubuntu: Changing Your Computer’s Hostname
Quoted from #ubuntu @ freednode:
(07:24:34 PM) R0b0t1: Is there a way to change the computers’ name? EG, the name that appears in the terminal.
So, your computer’s name, or hostname, isn’t what you want any longer. Possibly, you misspelled it during the installation process (trust me, I’ve done it). Whatever reason you have for changing it, it’s easier than you might think.
Do It The GUI way
You have two possible options. The first is through the network-admin desktop application. On 8.04 Hardy Heron, it’s installed by default. However, on 8.10 Intrepid Ibex, it is not. Use Synaptic to install gnome-network-admin or use sudo apt-get install gnome-network-admin at a command prompt.
To run the application, choose System > Administration > Network. On the following Network Settings window, click on the General tab.

There you’ll see the Host Settings. Click the Unlock button and enter your passphrase to authenticate yourself to change the Host name. To finish, click Close and you’ll see a warning about having to login again. Click on Change Host name, and click Close again. Once you’re done, give your machine a restart and you’re set to go.
No GUI? Do It On The CLI
Your second option is from a command line. There are two files that need to be changed: /etc/hostname and /etc/hosts . Use your favorite text editor (I use nano for these edits) and open each one. You’ll need to use sudo since you’re changing system files.
First we change the /etc/hosts file.
sudo nano /etc/hosts
This is what my server’s hosts file looks like.
adam@oracle:~$ cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 oracle# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
You can see my server’s name next to 127.0.1.1 as oracle. You should see your computer’s name at that same IP. Just replace it with your new choice. Save and close that file and open your /etc/hostname file.
sudo nano /etc/hostname
This one is very simple. All that should be there is your computer’s current name. Replace it with your new choice, save and close. Now, all that’s left is to reboot the machine.
For a temporary fix, you can use the hostname command.
sudo hostname your_new_hostname
I’ve also read elsewhere that you don’t need to reboot after changing the hostname as much as you just need to re-login. I feel it’s best to be safe and just reboot. You can choose whichever is best for you.


June 15th, 2009 at 10:00 pm
I used the GUI instructions in the article in Jaunty Jackalope, Ubuntu 9.04, and they worked perfectly. When I finished, there was a message that I needed to restart the system before starting any new applications.
Thanks for the article. It was the first I found that explained how to get Network Administration, which is needed for versions after Hardy Heron.
May 21st, 2010 at 9:09 am
Thanks for the clear instructions. Worked perfectly well on 10.04 – used the cli version.