How to change Hostname (Computer Name) in Linux Ubuntu 14.04. You can change the Hostname or Computer name in Linux Ubuntu PCs. This trick to change the Computer Name also applies for other Linux Ubuntu derivatives.
The default Hostname (Computer Name) is set during the Linux Ubuntu instalation. Let us see how can we easily change the Hostname (Computer Name) by editing the hosts and hostname files in Linux Ubuntu.
Find Hostname in Ubuntu
Hostname Command: Hostname is used to either set or display the current host or domain name of the system. This name is used by many of the networking programs to identify the machine. The domain name is also used by NIS/YP.
Find Hostname in Ubuntu: When called without any arguments, the program displays the current names. Run the command “Hostname” (without quotes) to display the current Hostname.
Edit Your /etc/hostname File
Ubuntu and other Debian-based Linux distros store the hostname in /etc/hostname. Open Terminal and run the following command to edit the /etc/hostname file.
sudo gedit /etc/hostname
To change the /etc/hostname file entry, just delete the existing hostname and write your new hostname and then save the text file.
Edit Your /etc/hosts File
The Hostname (Computer Name) is also stored in the /etc/hosts file. You’ll need to change the hostname in your /etc/hosts file. Run the following command to open the /etc/hosts file:
sudo gedit /etc/hosts
Search the old hostname in the hosts file. The hostname in the /etc/hosts file looks like:
127.0.1.1 YOUR-HOSTNAME
To change the /etc/hosts file entry, just delete the existing hostname and write your new hostname and then save the text file.
Thats’ it, but the change won’t take effect immediately. You must reboot (restart) the system to change it immediately. You can also use the hostname command.
Change Your Hostname Immediately
The change the hostname immediately without restart, use the hostname command in a terminal:
sudo hostname your-new-hostname
or
sudo /etc/init.d/hostname.sh start
Your computer’s hostname will be changed immediately. Close the Terminal, if open to reflect the new name.