CoreOS hostname on reboot

Rick asked:

Recently, I created a CoreOS droplet on DigitalOcean. Everything works well, except for the fact that I’m not able to change the hostname of my VPS. When I change the hostname to what it should be using sudo hostnamectl set-hostname (the documented way of doing so), it indeed changes the hostname system-wide (e.g. /etc/hostname reflects the new hostname). However, when I reboot the VPS, the hostname gets reverted to what it used to be.

It might not be a coincidence, but the hostname always reverts to the original name of the droplet. I’ve already changed that name about one week ago to the correct hostname. I have read stories about DHCP influencing the hostname on reboot, but I’m not able to find a solution to avoid that on CoreOS.

How to change the hostname of CoreOS in such a way that it will remain the same after a reboot?

Thanks in advance!

I answered:

CoreOS uses cloud-init to configure each machine in your fleet, and cloud-init reconfigures the hostname if told to do so in its configuration file (by default /etc/cloud/cloud.cfg). You also need to change the hostname in this file, or remove the hostname configuration entirely.

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.