Question

I cannot change hostname on FreeBSD

Posted September 5, 2015 4.1k views
Miscellaneous DigitalOcean 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

5 comments
  • 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

  • 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.

  • 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?

  • 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.

  • Show 1 more comments

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.

1 answer

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

Submit an Answer