Hello,
I understand the frustration when changes like hostname reverts back after a reboot. Based on a similar experience I had while troubleshooting a VMware Appliance, and this is the solution that I found which worked for me
In my case, even though the hostname was set correctly in both /etc/hostname and /etc/hosts files, it reverted to the default after a reboot. This issue seemed to be related to cloud-init resetting the hostname settings.
Here's what worked for me:
Set the Hostname: First, make sure your hostname is set correctly using hostnamectl. For example:
sudo hostnamectl set-hostname your-fqdn-here
Replace your-fqdn-here with your desired Fully Qualified Domain Name (FQDN).
Disable Cloud-Init: It turns out cloud-init might be resetting the hostname on reboot. To prevent this, create a file named /etc/cloud/cloud-init.disabled:
sudo touch /etc/cloud/cloud-init.disabled
This step will disable cloud-init from interfering with your hostname settings.
Reboot and Verify: After these changes, reboot your system. Post-reboot, verify if the hostname persists:
hostname hostname -s hostname -f
This solution worked well in my case and the hostname persisted correctly after the reboot. It's worth noting that even if you haven't explicitly set up your system with cloud-init, it might still be affecting your configuration, especially if it was enabled in newer updates or used under the hood.
I hope this helps resolve your issue!