[How-To] Create or change your server's hostname in Directadmin

Richard G

Verified User
Joined
Jul 6, 2008
Messages
13,357
Location
Maastricht
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:
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
or just:
/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
In this case LE can't use the old certificates anymore, which will fix the issue and you can request the hostname certificate again.

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:
Hahaha good idea :) now you can redirect people to this topic instead tell it over and over again
 
Why is it so hard to change the hostname after setup? Surely it should just be a case of updating it in CB
 
Surely it should just be a case of updating it in CB
Yes it is, if you don't need a new hostname SSL certificate or mail from hostname and/or if everthing is working correctly. The basic change is mostly not hard at all.

But as you can read from the howto, there are cases in which not everything is change correctly and often the new SSL certificate gives issues. So it's written to also prevent/fix these issues if/when they arise.
 
Yes it is, if you don't need a new hostname SSL certificate or mail from hostname and/or if everthing is working correctly. The basic change is mostly not hard at all.

But as you can read from the howto, there are cases in which not everything is change correctly and often the new SSL certificate gives issues. So it's written to also prevent/fix these issues if/when they arise.
Yep, sorry, what I meant was, surely updating in the CB should do all the change requirements.
 
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
You will need to set the i= tag in the exim config for dkim alignment of these subdomains right?
 
Back
Top