This short tutorial will show you how to change the hostname of a Ubuntu 16.04 installation.
Step 1: Edit the hostname configuration file.
Run the following command to open the hostname configuration file:
sudo vim /etc/hostname
There should be one line of text at the beginning of the file. Replace this with the new hostname then save the file.
Step 2: Edit the hosts configuration file.
Run the following command to open the hosts file:
sudo vim /etc/hosts
There should be a line at the beginning which starts with 127.0.0.1 and then ends with the current hostname. Change this to the new hostname then save the file. For example:
Step 3: Restart the machine to apply the changes.
Run the following command to restart the operating system.
That’s it. Once the machine has restarted the new name should be applied. You can check this by running the hostname command at the terminal.