First of all, if you want to check your current hostname, use the hostname command:

hostname

Change your Ubuntu host name

To change your host name, run the following command:

hostname hostname.example.com

(Replace hostname.example.com in the above command with the hostname you wish to use)

Now when you run the hostname command, it should show you your new hostname.

How to make hostname stay the same after reboot

One issue you may encounter is that after changing your hostname, it goes back to what it was previously when you reboot Ubuntu. 

  • You might be able to fix this by editing the file, /etc/hostname, and replacing the hostname stored in the file with the hostname you choose.
  • You may also need to edit the /etc/hosts file by replacing the name of the old hostname with the new hostname that you've chosen.