I’m just posting this here in case someone ended up in the same boat as me.
I cloned a VM on VMware ESXi 6.5.
Tried changing the hostname using:
…and changing the hostname in /etc/hostname, but when I rebooted, the hostname went back to the old original VM name.
Tried this as well…
hostnamectl set-hostname newname
But that didn’t persist either.
What worked was this:
apt remove cloud-init cloud-initramfs-copymods cloud-initramfs-dyn-netconf
Turned out that these cloud features were jacking with the hostname. Removing this resolved the problem.
Maybe this is taking a sledgehammer to the solution, but it worked.
A more elegant resolution is to locate the setting in the cloud config that causes the cloud hostname to override the local hostname.
Also, this had nothing to do with VMware. The original VM needs to be updated so it doesn’t have this cloud junk in it so this problem will stay dead and not return like the ending of a cheesy horror show.