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:
Edit /etc/cloud/cloud.cfg and set the following to true:
# This will cause the set+update hostname module to not operate (if true)
To disable it altogether:
At this point, editing /etc/hostname will preserve the name after reboot