How do I set an FQDN?


I’m trying to set my FQDN so that when I do hostname -f, it gives me my FQDN (like instead of my hostname which I used to create my Droplet.

I would appreciate any help.



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.

Accepted Answer

Hello, @amirehmarwan

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

1 Use the following command:

sudo hostnamectl set-hostname hostname

2 Update your hostname in your hosts file:

vim /etc/hosts

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

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, Alex