Vps – CoreOS hostname on reboot

coreoshostnamevps

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 myhostname.org (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!

Best Answer

On DigitalOcean (and some other cloud providers; Openstack for example) they're providing metadata on each boot of the machine (either provided via cloud-config or via the options you provided in the DigitalOcean web interface). When you bestowed a name on the droplet/VM you signified to the metadata service that you wanted the hostname to be called that value. cloud-config is honoring the request put forth by the DigitalOcean metadata service. This is actually a design pattern and operating outside of it would me much like trying to avoid uing convention over configuration in Rails. You can do it, but you're only making things harder on yourself.

Inside the DigitalOcean web interface you can rename the droplet Select Droplet->"Settings"->"Rename"

As to why the option in previous answer does not exist, CoreOS does not ship Python cloud-init had to be re-written in a compiled language (hence it being written in Go. To view the metadata on DigitalOcean log into the host and run the command:

$ curl http://169.254.169.254/metadata/v1/user-data