Change/update hostname Ubuntu

To change the hostname of an Ubuntu machine you can run the following commands:

sudo hostname your-new-name

This will only update the hostname when the service or machine is restarted. To restart the service run:

sudo service hostname start

Also ensure you change your hostname in the following file:

sudo nano /etc/hosts