How to Change the Host Name in Ubuntu
Ubuntu has become one of the most popular Linux distributions available. As part of the Ubuntu installation, a generic host name is created. It is possible to edit the Host Name during the installation or anytime later if there is a need to clarify the system's identity or if there is a change in the system's ownership. Two files need to be edited through the command line in an editor such as Gedit, though Vi would work as well.
Instructions
-
-
1
Open a Terminal window and edit the /etc/hostname file using the following command: "sudo gedit /etc/hostname" (without the quotation marks) and press the Enter key. Type in your password when prompted and press the Enter key. Change the current host name to the host name of your choice. Select Save, then select Quit to exit Gedit.
-
2
Edit the the /etc/hosts file using the following command: "sudo gedit /etc/hosts" (without the quotation marks) and press the Enter key. You will not be prompted to enter your password this time. Modify the current Host Name to the exact same host name you used earlier in the hostname file. Select Save, then select Quit to exit Gedit.
-
-
3
Stop the the host name service by typing the following command at the command prompt: "sudo /etc/init.d/hostname.sh stop" (without the quotation marks) and press the Enter key.
-
4
Restart the host name service by typing the following command at the command prompt: "sudo /etc/init.d/hostname.sh start" (without the quotation marks) and press the Enter key.
-
5
Check to ensure that the modification is complete by typing in the command "hostname" (without the quotation marks) and pressing the Enter key.
-
1
Tips & Warnings
Make sure that both files are edited and that the names are identical in both files before stopping and restarting the host name service.
As an alternative to stopping and restarting the host name service, rebooting the computer will also enable the changes to take effect.
Differences in the host name files, misspellings or not editing both of the configuration files will cause an "hostname: Unknown Host" when you attempt to restart the host name service. If you elected to reboot and cannot access your system due to mistakes in this process, use a Linux Live CD to re-edit both files and restart the system when you have corrected the mistakes.