Change Host Name on Ubuntu 18.04 and above

Sometimes you need to change the host name of a machine and this is how you do it

By editing the /etc/hosts file

This is as simple as opening the file and changing the old host name to a new one.

Using hostnamectl command

To view the cureent host name:

$ hostnamectl 
   Static hostname: ubuntu
         Icon name: computer
        Machine ID: a3d9197b765643568af09eb2bd3e5ce7
           Boot ID: 4cce352e3b074b829eaa7cffc968260c
  Operating System: Ubuntu 18.04.5 LTS
            Kernel: Linux 4.9.253-tegra
      Architecture: arm64

to change the system static hostname, you would use the following command:

sudo hostnamectl set-hostname <new host name>