I have a script that runs at boot (via rc.local) and sets my hostname based on the instance name it queries from the AWS CLI. It works, and at the end of the boot log it says " login:"
At figured that cloud-init was overwriting my hostname, so I:
But in the cloud-init logs I still see "Running module update-hostname" and " Migrated semaphore update_hostname.always to config-update-hostname with frequency always", and a minute or two after boot the hostname returns to the AWS default.
What is going on? How do I stop it?
I know this is an old post, but I found it useful to know.
In the /etc/cloud/cloud.cfg
file, add hostname: <fqdn/hostname>
just below preserve_hostname: <true/false>
:
# This will cause the set+update hostname module to not operate (if true) preserve_hostname: false hostname: myhostname
Source: https://cloudinit.readthedocs.io/en/latest/topics/modules.html#set-hostname.
https://aws.amazon.com/premiumsupport/knowledge-center/linux-static-hostname-rhel7-centos7/
Be sure to use the full command "sudo hostnamectl set-hostname --static "
Slightly different for Ubuntu: https://aws.amazon.com/premiumsupport/knowledge-center/linux-static-hostname/
sudo hostnamectl set-hostname my.persistent.hostname
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With