How to change your computer name (hostname) in Ubuntu

When you first installed Ubuntu you were offered the chance to set the Ubuntu hostname, which is what appears at the command-prompt and is also how your computer is identified should you activate services such as file sharing.

You probably ended-up with something like john-desktop. To change the hostname to something more exiting, you'll need to edit both the /etc/hosts and /etc/hostname files. This is best done in run level 1 (rescue mode), when practically no other software is running.

Here are the steps required:

1) Logout so you return to the login screen and then switch to a virtual console. Login and type sudo telinit 1. This will switch you to rescue mode. At the text menu that appears, use the cursor keys to select Root - drop to root shell prompt and hit Enter.

2) Type nano /etc/hosts. Identify your hostname within the file (it will most likely be on the second line) and change it to what you wish. Remember that hostnames only involve letters and/or numbers, and no spaces. You should also steer-clear of symbols. When you've finished making your edits, hit Ctrl + x to quit the program. Type y to save the modified buffer (ie save the file), and then hit Enter to actually save the file and quit the program.

3) Repeat the step above, this time editing the /etc/hostname file. This file contains only the hostname. Change it to exactly what you typed earlier (it must be completely identical!). Then save the file and quit nano.

4) Reboot the computer by typing telinit 6.

When the computer reboots you should find that your hostname is changed. If the computer shares files with other computers, they may find that any shortcuts they created to your computer's shared resources no longer work. They will now have to recreate them afresh by browsing for your computer as if you had just started sharing folders.





Tags: host,hostname,sudo,telinit,nano

Related Articles