Are you running DirectAdmin on your primary server and would like all of your newly-created domains (zone files) to be replicated on a secondary server automatically? If yes, then this guide is for you! This guide will help you setup a secondary (slave) DNS server, for a primary (master) server which is running DirectAdmin.
Note: This guide is intended for secondary DNS servers that are NOT running DirectAdmin. Only the primary server will be running DirectAdmin.
Please replace the IP addresses below with your own public/static IP addresses!
Let's begin...
1) Generate a set of public and private SSH keys to allow the root user to log in from 'server1' to 'server2'...
Login as root on server1 and execute the following two commands and enter nothing at the prompts:
2) Copy the public key from 'server1' to 'server2'...
(You will probably be asked for the root password for server2 - which you should enter in order to proceed!)
3) Edit the BIND configuration file on both servers to accept DNS zone transfers...
Add the following in the /etc/bind/named.conf.options file on server1 - somewhere in between the options { }; tags:
Add the following in the /etc/bind/named.conf.options file on server2 - somewhere in between the options { }; tags:
4) Restart the BIND service on both servers...
5) Create the DirectAdmin custom scripts on 'server1' which will execute after new domains are created and/or after existing domains have deleted...
6) Now add the following bash code into both the 'dns_create_post.sh' and 'dns_delete_post.sh' script files on 'server1'...
/usr/local/directadmin/scripts/custom/dns_create_post.sh must contain the following:
/usr/local/directadmin/scripts/custom/dns_delete_post.sh must contain the following:
Done!! You may now add and remove domains on your primary DirectAdmin server and all the DNS zone files will automatically be created and transferred to your secondary DNS server. You no longer need to add manual DNS entries on the secondary server and tamper with the BIND configuration files.
I hope this helps!
Note: This guide is intended for secondary DNS servers that are NOT running DirectAdmin. Only the primary server will be running DirectAdmin.
Please replace the IP addresses below with your own public/static IP addresses!
Primary server = Debian Linux with DirectAdmin
Primary server IP address = 192.168.0.1
Primary server name = server1
Required software: SSH (apt-get install ssh) and BIND9 (apt-get install bind9 dnsutils)
Secondary server = Debian Linux without DirectAdmin
Secondary server IP address = 192.168.0.2
Secondary server name = server2
Required software: SSH (apt-get install ssh) and BIND9 (apt-get install bind9 dnsutils)
Let's begin...
1) Generate a set of public and private SSH keys to allow the root user to log in from 'server1' to 'server2'...
Login as root on server1 and execute the following two commands and enter nothing at the prompts:
Code:
server1:~# cd /root/
server1:~# ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa): [B]<PRESS ENTER TO ACCEPT DEFAULT>[/B]
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): [B]<PRESS ENTER FOR NO PASSPHRASE>[/B]
Enter same passphrase again: [B]<PRESS ENTER FOR NO PASSPHRASE>[/B]
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
41:03:aa:dc:cc:b9:39:50:65:bc:ee:7b:36:d2:64:7a root@server1
2) Copy the public key from 'server1' to 'server2'...
Code:
server1:~# scp /root/.ssh/id_dsa.pub [B]192.168.0.2[/B]:/root/.ssh/authorized_keys
(You will probably be asked for the root password for server2 - which you should enter in order to proceed!)
3) Edit the BIND configuration file on both servers to accept DNS zone transfers...
Add the following in the /etc/bind/named.conf.options file on server1 - somewhere in between the options { }; tags:
Code:
notify explicit;
also-notify { 192.168.0.2; };
allow-notify { 192.168.0.2; };
allow-transfer { 192.168.0.2; };
Add the following in the /etc/bind/named.conf.options file on server2 - somewhere in between the options { }; tags:
Code:
notify explicit;
also-notify { 192.168.0.1; };
allow-notify { 192.168.0.1; };
allow-transfer { 192.168.0.1; };
4) Restart the BIND service on both servers...
Code:
server1:~# /etc/init.d/bind9 restart
server2:~# /etc/init.d/bind9 restart
5) Create the DirectAdmin custom scripts on 'server1' which will execute after new domains are created and/or after existing domains have deleted...
Code:
server1:~# touch /usr/local/directadmin/scripts/custom/dns_create_post.sh
server1:~# touch /usr/local/directadmin/scripts/custom/dns_delete_post.sh
server1:~# chmod 700 /usr/local/directadmin/scripts/custom/dns_create_post.sh
server1:~# chmod 700 /usr/local/directadmin/scripts/custom/dns_delete_post.sh
server1:~# chown diradmin:diradmin /usr/local/directadmin/scripts/custom/dns_create_post.sh
server1:~# chown diradmin:diradmin /usr/local/directadmin/scripts/custom/dns_delete_post.sh
6) Now add the following bash code into both the 'dns_create_post.sh' and 'dns_delete_post.sh' script files on 'server1'...
/usr/local/directadmin/scripts/custom/dns_create_post.sh must contain the following:
Code:
#!/bin/sh
/usr/bin/ssh root@[B]192.168.0.2[/B] '/bin/echo "zone \"'$domain'\" { type slave; file \"/var/cache/bind/'$domain'\"; masters { 192.168.0.1; }; };" >> /etc/bind/named.conf; /etc/init.d/bind9 restart'
exit 0;
/usr/local/directadmin/scripts/custom/dns_delete_post.sh must contain the following:
Code:
#!/bin/sh
/usr/bin/ssh root@[B]192.168.0.2[/B] -- /bin/sed -e "'/^zone \"$domain\"/d'" -i /etc/bind/named.conf \&\& /bin/rm -f /var/cache/bind/$domain \&\& /etc/init.d/bind9 restart
exit 0;
Done!! You may now add and remove domains on your primary DirectAdmin server and all the DNS zone files will automatically be created and transferred to your secondary DNS server. You no longer need to add manual DNS entries on the secondary server and tamper with the BIND configuration files.
I hope this helps!
Last edited: