How to change a machine name.

Terminology: the machine name is also called the hostname. There is a temporary machine name called the 'pretty hostname', this is not what we want to change.

Best way is to use the systemd utility. If it is not installed then install it using:

sudo apt install systemd

You can check if you have it already by getting the version number:

systemd --version

Run the following command to view detailed information about your system including the hostname.

hostnamectl

In this output, the Static hostname lists the permanent hostname of your machine. The Pretty hostname lists the Device name you have set up through the UI in the Settings utility. The hostnamectl lists the Pretty hostname(device name) only if it is different from the static hostname.

In order to change your computer's hostname through the hostnamectl command, use the following syntax:

hostnamectl set-hostname new-hostname

Now when you see, the hostname through the hostnamectl command, it will show the static hostname as the new hostname you have set. The system has also changed the device name to the hostname you specified through the set-hostname command.

You can verify through the UI that your device name will also be the same as your static hostname. Open the Settings utility and move to the Details tab to view your device name.

The plus point of the Hostnamectl command is that you do not need to restart your computer in order to permanently change the hostname.

The above information came from: How to Change your Ubuntu Computer Name (Hostname) This is an online Linux Compendium. Thank you for providing this information!