Set host name on Ubuntu Server

To change the computer name on Ubuntu, be it on your home server or an Ubuntu server in the cloud, you can proceed as follows:

  1. Type the hostnamectl command :
    sudo hostnamectl set-hostname newNameHere
    Delete the old name and setup new name.
  2. Next, edit the /etc/hosts file:
    sudo nano /etc/hosts
    Replace any occurrence of the existing computer name with your new one.
  3. Reboot the system to changes take effect:
    sudo reboot