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


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 ‘’.

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 ‘’.

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?




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.


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

  1. Change the hostname with the hostnamectl command:
sudo hostnamectl set-hostname
  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