How To Find And Change Your Hostname On An Ubuntu System

In this tutorial we will look at how to change the hostname of your Ubuntu Linux system. The following steps will work both on the desktop and server platform.


How To Check What The Hostname is:

Open up a termnial or ssh into the machine that you want to check. Enter the following command.




Ubuntu - Enter command: hostname - to view the linux system hostname



You should now see your hostname





You should now see the output of your hostname




How To Change Ubuntu Hostname:

To change the hostname you will need to edit the hostname file located in the /etc directory. We will also need to update the hosts file. In this example i will update my hostname from ubuntu-server to server100.


Edit /etc/hostname:

sudo nano /etc/hostname



edit /etc/hostname with nano - sudo nano /etc/hostname



Enter your password




Enter your password



Change the name in this file. In this example my current name is ubuntu-server and I will change it to server100.



Example of Hostname file - before



Hit CTRL + X to exit nano


hostname file after changes - New Name



Enter Y to save changes



Enter Y to confirm saving changes




Edit /etc/resolv.conf

The /etc/hosts file holds some static DNS information.If this is not set somethings can get a little weird at times.  We will use the nano text editor again to make our changes.  

sudo nano /etc/hosts



sudo nano /etc/hosts - update hostname



You will need to change your old hostname to the new one. 




Update your /etc/hosts file to reflect your new hostname




Note: The loven.linux was handed out by my DNS server when I setup my machine. Yours will be something different. 



Example of hostfile after being updated - Note: Don't add loven.linux because this is from my internal dns server.



Hit CTRL + X to exit out of nano

Enter Y to save the file



Hit CTRL + X > Then Enter Y to save the file



Hit enter to overwrite the file.



Hit Enter to overwrite the file



Restarting The System:


Now that we have everything configured all we should need to do is restart and check to make sure the hostname has been update. 


sudo shutdown -r now



Restart your system with the command : sudo shutdown -r now



If you enjoyed this post, please share it on your favorite social network by clicking on the “Share / Save” bar below.