Change Hostname on Ubuntu 18.04
Definition
A hostname is a label that identifies a machine on the network. You shouldn’t use the same hostname on two different machines on a same network.
Prerequisites
- User should have a sudo privileges
Change the Hostname
Change the hostname using hostnamectl command. If you want to change the hostname to new_hostname
sudo hostnamectl set-hostname new_hostname
It will not change the hostname directly. You want to preserve the changes permanently then you have to edit cloud.cfg
file
sudo nano /etc/cloud/cloud.cfg
# This will cause the set+update hostname module to not operate (if true)
preserve_hostname: true
Save the file and close your editor.
Verify your Changes
You can verify your changes using command hostnamectl
it will show new_hostname under Static hostname
PS: Source Link