Hostname reverts after reboot in Ubuntu
Q. When setting a hostname in Ubuntu 18 (using traditional methods: /etc/hostname and hostnamectl), it reverts back after reboot.
A.The setting is being reset by the service: cloud-init. This service has to be either disabled or a value set to bypass the hostname reset:
To bypass:
Edit /etc/cloud/cloud.cfg and set the following to true:
# This will cause the set+update hostname module to not operate (if true)
preserve_hostname: true
To disable it altogether:
touch /etc/cloud/cloud-init.disabled
At this point, editing /etc/hostname will preserve the name after reboot