Change
Linux (Ubuntu) Hostname Permanently
1) Modify /etc/cloud/cloud/cfg to allow persistent name change.
sudo nano /etc/cloud/cloud.cfg
Set ‘preserve_hostname’
to ‘true’
preserve_hostname: true
2) Use the hostnamectl command to change the hostname
sudo hostnamectl
set-hostname <new hostname>
3) Change /etc/hosts file
127.0.0.1 <new hostname>
4) Add hostname to /etc/hostname
<new hostname>
5) Reboot