Question

How to set a persistant FQDN for an Ubuntu 18.04 droplet?

Posted December 4, 2019 2.6k views
Initial Server Setup

Hi,

I created a new droplet today. Named it ‘fred’. If I query the hostname, it returns 'fred’. If I ask for the FQDN via hostname –fqdn, I get 'fred’.

My DNS (external provider) is pointing at 'fred.example.org’.

Reading various articles here, I’ve tried changing the name of the droplet via the control panel (no change after a reboot), using the hostname command (lasts until the next reboot), using the hostnamectl command, which seems to change the hostname and the FQDN to 'fred.example.org’.

Normally, I’d change the hostname file and the resolv.conf file. But, both files have comments that they should be changed elsewhere in part of the cloud init system. Which seems to be tied into systemd.

This will be a mail server, eventually, and its really important to get the names set up properly.

I keep looking for a tutorial that would address this with the specifics of the Digital Ocean setup, but I’m not finding it.

What am I missing?

Thanks,

johnbo

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

Hello,

I believe that there are 3 things that you need to do:

  1. Change the hostname with the hostnamectl command:
sudo hostnamectl set-hostname fred.example.org
  1. Update your hostname in your hosts file:
vim /etc/hosts

Find the references to the old FQDN and update them to the new one.

  1. Update the cloud.cfg file. Edit the following file:
vim /etc/cloud/cloud.cfg

Find the reference for preserve_hostname and change it from false to true.

That is pretty much it, you can try to reboot your server and then test the change by running only the hostnamectl command.

Hope that this helps!
Regards,
Bobby

  • Hi,

    Thanks for your response. Its possible that I’m a bit out of date here. Most of my experience has been with the 16.04 LTS systems.

    On my existing systems, the hostname command will return ‘barney’, while the hostname –fqdn command returns 'barney.example.org’. With the changes made as you described, both the hostname and hostname –fqdn return 'fred.example.org’.

    Using the hostnamectl query on the 16.04 system mentioned above gives 'barney’ as the static hostname. Whereas on the new 18.04 system, with the changes made above, 'fred.example.org’ is returned.

    My experience with Postfix has been that it is quite sensitive to confusion about machine names and FQDN. Is this just a change to the behavior of the hostname system or am I missing a configuration elsewhere?

    Thanks for your help.

    johnbo

    • Hi @johnbo,

      Yes, I think that you are correct. On newer systems it should be fine to follow the steps above. On older systesm what I used to do was to edit the /etc/hostname manually along with the /etc/hosts. I believe that this should fix the inconsistent result that you are getting between the hostname and the hostname --fqdn commands.

      Regards,
      Bobby

Submit an Answer