Follow these simple steps to change the hostname on a ubuntu machine:
Step 1: Update /etc/hostname file
This file contains the current hostname of the machine. Update the name to your
desired name.
$ sudo vi /etc/hostname
Step 2: Update /etc/hosts file
Replace the current hostname in the file with the desired name.
$ sudo vi /etc/hosts
Step 3: Set the hostname using the hostnamectl command
$ sudo hostnamectl set-hostname new_hostname