Reputation: 301
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?
Upvotes: 8
Views: 21681
Reputation: 751
https://aws.amazon.com/premiumsupport/knowledge-center/linux-static-hostname-rhel7-centos7/
Be sure to use the full command: sudo hostnamectl set-hostname --static <persistent_host_name>
Upvotes: 3
Reputation: 107
Slightly different for Ubuntu: https://aws.amazon.com/premiumsupport/knowledge-center/linux-static-hostname/
sudo hostnamectl set-hostname my.persistent.hostname
Upvotes: -1
Reputation: 71
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.
Upvotes: 7
Reputation: 6764
Try this:
$ sudo vi /etc/cloud/cloud.cfg
and then comment out 'set_hostname', 'update-hostname', and 'update_etc_hosts' as you require.
Upvotes: 0
Reputation: 301
My really nasty hack-around is to create a cron job that sets the hostname every minute. Improved suggestions appreciated.
Upvotes: -11