Question

I cannot change hostname on FreeBSD

Hello Dear Community

I’m not able to change the hostname on my FreeBSD droplet from the one I was to create it.

I added this line hostname=“new.host.name” to my /etc/rc.conf, rebooted many time but my droplet still keeps my original hostname I’ve chosen when creating it.

Is It a DigitalOcean issue ?

Regards

Subscribe
Share

The problem appears to be in the /etc/rc.d/hostname script

...
elif [ -n "`/bin/hostname -s`" ]; then
		return
...

if the hostname is already set, then it aborts, so no overriding. Solution maybe to edit the hostname name from all the rc.digitalocean.d/*.conf – so that the default action happens as expected, although I am currently unsure as to whether these configuration files will be overridden at a later date by DO automation?

On a fresh droplet, changing the hostname in the control panel does the trick, but when you launch a droplet from a snapshot it does nothing as the meta-data from the snapshot persists. In this case, disabling cloudinit in /etc/rc.conf with: $ sudo sysrc cloudinit_enable="NO" seems to be the only solution.

This problem persists. It seems like it’s coming from cloud-init. If you set cloudinit_enable="NO" in /etc/rc.conf after you change the hostname, it will do the trick.

Also if you:

# grep 'hostname' /var/lib/cloud/seed/config_drive/digitalocean_meta_data.json

You’ll notice the meta-data contains the old hostname. Perhaps cloud-init is picking this up and wiping out rc.conf. This is all speculation at this point, but the above hack is working. Cloud-init only facilitates the early initialization of a droplet. Disabling it won’t hurt anything unless you need it of course.

This comment has been deleted

Although this will work, is this really the correct way to do it? Considering that load_rc_config() in rc.subr in fact will try /etc/rc.digitalocean.d/ before trying /etc/rc.conf, I’m under the impression the intended behavior was to override hostname in /etc/rc.conf.

Feel free to correct me; I only took a quick glance at the rc scripts.

I found the solution.

This file /etc/rc.digitalocean.d/droplet.conf must be edited because it overwrites the hostname=“new.host.name entry in /etc/rc.conf

Regards


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

This question was answered by @matthewa:

The problem appears to be in the /etc/rc.d/hostname script

...
elif [ -n "`/bin/hostname -s`" ]; then
		return
...

if the hostname is already set, then it aborts, so no overriding. Solution maybe to edit the hostname name from all the rc.digitalocean.d/*.conf – so that the default action happens as expected, although I am currently unsure as to whether these configuration files will be overridden at a later date by DO automation?

View the original comment