Richard G
Verified User
This is a guide on how to create a correct FQDN hostname on a sever or VPS.
I created this newly here in this section, for easier reference and it's also easier to find.
There is also another method, but the method described here is another method which is also still very usable.
Before you install Directadmin you can already take care the correct hostname is used bij Directadmin.
The domain mydomain.com is used her as example and 192.168.0.1 as example server ip. Ofcourse replace all examples with the domain or hostname your are using. So don't use 192.168.0.1 in the real situation, same for mydomain.com!
Commands before installation of DA:
Via SSH as root:
after that check your /etc/hostname file to see if the hostname is fully in there.
So it should read: server.mydomain.com
After that check your /etc/hosts file. Adjust it if needed. Should look like:
Just to be sure reboot your server/vps and issue these commands check if they return the correct hostname.
and
both commands should give the full server.mydomain.com hostname as a result.
Then your fine and the DA setup will take over your hostname.
Changing hostname after installation.
Check if the above settings are correct.
Then also change the hostname in Directadmin.
Login as admin, go to DNS administration, check for the server-xx-xx-xx-xx.da.direct and delete it if present.
Be aware! By default Directadmin also will set this as nameservers so like:
ns1.server-xx-xx-xx-xx.da.direct and
ns2.server-xx-xx-xx-xx.da.direct
which ofcourse also needs changing. Change that to for example ns1.mydomain.com and ns2.mydomain.com. You have to setup the nameservers and this can be done via DA too, but the howto is not included in this manual. It's just a reminder that it's best to change these defaults.
Then still under admin, in DNS administration, create your new hostname like you would for a domain. So use the "Add DNS zone" option.
You will have to fill in the server ip and the nameservers too.
Now there is a bug (might be solved at some point), so login to SSH and go to the /etc/virtual directory and make sure that the directory server.mydomain.com is present in there too., If not then create it and chown it to mail and chmod to 711.
Like this, but only if it does not exist yet.
If you are using an external nameserver, be sure to create the appropriate A record for the hostname there too.
That might need a bit of time to synchronise over wordly DNS, but after that your hostname should be working.
Additionally: Dont forget to create a new hostname certificate for your hostname.
As of Directadmin version 1.661 it's made easier and you can issue this new command:
or just:
Older DA versions use:
NB! Often if the hostname is changed after installation, when trying to create a certificate for the hostname, LE will still try to get a certificate for the server-xx-xx-xx.da.direct hostname which is generated by the DA installation.
In that case doublecheck your /etc/hosts and /etc/hostname file that it contains your new hostname and the old is removed. If not, adjust the file(s) accordingly.
If that doesn't help, use the solution @zEitEr gave us, because that wil work for 100% sure.
Remove these files (as far as present) if the server.xx.xx.da.direct hostname stays present after a hostname change and everything is setup correctly:
If mydomain.com is also created on the server, then the hostname record can also have SPF and even DKIM records created. This could come in handy when you have scripts using php mail() instead of SMTP. I would advise SMTP.
External nameserver usage.
Be aware! If you set it up like this and create a DKIM record for your hostname, then this can be different from your mydomain.com DKIM record. So if you're using external nameservers/DNS for example like Cloudflare, you can't setup a seperate hostname dns record like in DA. So be sure to take over the DKIM record for your hostname too. You can have multiple DKIM records, that is no problem.
Probably you also need to include your hostname in the SPF record, I'm not 100% sure of that.
Hostnames and e-mail usage in all hostname cases.
If you are running e-mail from your server (default) then be sure to have a valid rDNS/PTR record for your hostname. You can normally set this in the control panel of the one who gave you the server ip, so mostly datacenter control panel or panel of VPS provider.
E-mail can be used without this, but many systems will raise spam points for this and it can easily lead to your e-mail being blocked if you don't have set this up correctly.
This guide will be adjusted as/if needed in the future.
I created this newly here in this section, for easier reference and it's also easier to find.
There is also another method, but the method described here is another method which is also still very usable.
Before you install Directadmin you can already take care the correct hostname is used bij Directadmin.
The domain mydomain.com is used her as example and 192.168.0.1 as example server ip. Ofcourse replace all examples with the domain or hostname your are using. So don't use 192.168.0.1 in the real situation, same for mydomain.com!
Commands before installation of DA:
Via SSH as root:
hostnamectl set-hostname server.mydomain.com
after that check your /etc/hostname file to see if the hostname is fully in there.
So it should read: server.mydomain.com
After that check your /etc/hosts file. Adjust it if needed. Should look like:
Code:
127.0.0.1 localhost.localdomain localhost
::1 ip6-localhost ip6-loopback
192.168.0.1 server.mydomain.com server
Just to be sure reboot your server/vps and issue these commands check if they return the correct hostname.
hostname
and
hostname -f
both commands should give the full server.mydomain.com hostname as a result.
Then your fine and the DA setup will take over your hostname.
Changing hostname after installation.
Check if the above settings are correct.
Then also change the hostname in Directadmin.
Login as admin, go to DNS administration, check for the server-xx-xx-xx-xx.da.direct and delete it if present.
Be aware! By default Directadmin also will set this as nameservers so like:
ns1.server-xx-xx-xx-xx.da.direct and
ns2.server-xx-xx-xx-xx.da.direct
which ofcourse also needs changing. Change that to for example ns1.mydomain.com and ns2.mydomain.com. You have to setup the nameservers and this can be done via DA too, but the howto is not included in this manual. It's just a reminder that it's best to change these defaults.
Then still under admin, in DNS administration, create your new hostname like you would for a domain. So use the "Add DNS zone" option.
You will have to fill in the server ip and the nameservers too.
Now there is a bug (might be solved at some point), so login to SSH and go to the /etc/virtual directory and make sure that the directory server.mydomain.com is present in there too., If not then create it and chown it to mail and chmod to 711.
Like this, but only if it does not exist yet.
Code:
cd /etc/virtual
mkdir server.mydomain.com
chown mail. server.mydomain.com
chmod 711 server.mydomain.com
If you are using an external nameserver, be sure to create the appropriate A record for the hostname there too.
That might need a bit of time to synchronise over wordly DNS, but after that your hostname should be working.
Additionally: Dont forget to create a new hostname certificate for your hostname.
As of Directadmin version 1.661 it's made easier and you can issue this new command:
Code:
cd /usr/local/directadmin/scripts
./letsencrypt.sh server_cert
/usr/local/directadmin/scripts/letsencrypt.sh server_cert
Older DA versions use:
Code:
cd /usr/local/directadmin/scripts
./letsencrypt.sh request_single server.mydomain.com 4096
NB! Often if the hostname is changed after installation, when trying to create a certificate for the hostname, LE will still try to get a certificate for the server-xx-xx-xx.da.direct hostname which is generated by the DA installation.
In that case doublecheck your /etc/hosts and /etc/hostname file that it contains your new hostname and the old is removed. If not, adjust the file(s) accordingly.
If that doesn't help, use the solution @zEitEr gave us, because that wil work for 100% sure.
Remove these files (as far as present) if the server.xx.xx.da.direct hostname stays present after a hostname change and everything is setup correctly:
- /usr/local/directadmin/conf/ca.csr
- /usr/local/directadmin/conf/ca.san_config
- /usr/local/directadmin/conf/cacert.pem
- /usr/local/directadmin/conf/cacert.pem.combined
- /usr/local/directadmin/conf/cacert.pem.creation_time
- /usr/local/directadmin/conf/cakey.pem
- /usr/local/directadmin/conf/carootcert.pem
- /usr/local/directadmin/conf/letsencrypt.key
- /usr/local/directadmin/conf/letsencrypt.key.json
If mydomain.com is also created on the server, then the hostname record can also have SPF and even DKIM records created. This could come in handy when you have scripts using php mail() instead of SMTP. I would advise SMTP.
External nameserver usage.
Be aware! If you set it up like this and create a DKIM record for your hostname, then this can be different from your mydomain.com DKIM record. So if you're using external nameservers/DNS for example like Cloudflare, you can't setup a seperate hostname dns record like in DA. So be sure to take over the DKIM record for your hostname too. You can have multiple DKIM records, that is no problem.
Probably you also need to include your hostname in the SPF record, I'm not 100% sure of that.
Hostnames and e-mail usage in all hostname cases.
If you are running e-mail from your server (default) then be sure to have a valid rDNS/PTR record for your hostname. You can normally set this in the control panel of the one who gave you the server ip, so mostly datacenter control panel or panel of VPS provider.
E-mail can be used without this, but many systems will raise spam points for this and it can easily lead to your e-mail being blocked if you don't have set this up correctly.
This guide will be adjusted as/if needed in the future.
Last edited: