create master slave dns server

How to Configure DNS Master-Slave Server in Linux

DNS (Domain Name System) is a distributed system that allows you to lookup domain names and get their IP addresses, and do vice versa. It supports different types of configuration. However, among them, the master/slave configuration is the most popular. In this case, the master holds all latest records and slaves update themselves automatically on regular basis. In this article, we will look at how to configure DNS master-slave server in Linux.


How to Configure DNS Master-Slave Server in Linux

Here are the steps to configure DNS master-slave server in Linux. Here is our setup.

Master DNS Server IP: 54.43.32.21 ( ns1.example.com )
Slave  DNS Server IP: 54.43.32.22 ( ns2.example.com )
Domain Name : example.com   ( For Testing Purpose )
Domain IP   : 54.43.32.20  ( For Testing Purpose )


1. Install Required RPMs

Open terminal in both Master & Slave and run the following command to install pre-requisite RPMs.

$ yum install bind bind-chroot


2. Setup Master DNS Server

In our Master DNS server, we need to configure two files – main DNS config file called named.conf and zone file created specifically for each domain. named.conf file maintains entry for all zone files.


2.1 Configure named.conf file

Open terminal and run the following command to open named.conf file.

$ vi /var/named/chroot/etc/named.conf

Update listen-on and allow-query variables’ values in the options block as shown with the address CIDR for your server, shown in bold.

options {
        listen-on port 53 { 127.0.0.1; 54.43.32.0/24; };
 ...
        allow-query     { localhost; 54.43.32.0/24; };
        recursion yes;

 ...
};


2.2. Create Zone File

We need to create separate zone for each of our domain. Since we have only 1 domain example.com, we create zone file for it.

$ vi /var/named/chroot/var/named/example.com.db

Add the following lines to it. Replace example.com with your domain name, ns1.example.com with subdomain of your master, ns2.example.com with subdomain of your slave.

; Zone file for example.com
$TTL 14400
@      86400    IN      SOA     ns1.example.com. webmaster.example.com. (
                3215040200      ; serial, todays date+todays
                86400           ; refresh, seconds
                7200            ; retry, seconds
                3600000         ; expire, seconds
                86400 )         ; minimum, seconds

example.com. 86400 IN NS ns1.example.com.
example.com. 86400 IN NS ns2.example.com.
example.com. IN A 192.168.1.100
example.com. IN MX 0 example.com.
mail IN CNAME example.com.
www IN CNAME example.com.

Now we need to add details of this zone file in our named.conf file updated in previous step. Open it again in text editor and add the following lines. Replace example.com with your domain name.

zone "example.com" IN {
        type master;
        file "/var/named/example.com.db";
	allow-update { none; };
};

Save and close the file. Run the following command to start named service.

$ /etc/init.d/named restart
$ chkconfig named on


3. Setup Slave DNS Server

Now we need to configure Slave DNS server. In this case, we need to update only named.conf file. All changes made on Master will be automatically synced with its slaves at regular intervals of time. Open named.conf file in text editor.

$ vi /var/named/chroot/etc/named.conf

In this case also, update listen-on and allow-query variables’ values in the options block as shown with the address CIDR for your server, shown in bold.

options {
        listen-on port 53 { 127.0.0.1; 54.43.32.0/24; };
 ...
        allow-query     { localhost; 54.43.32.0/24; };
        recursion yes;

 ...
};

Start named service with the following command.

$ /etc/init.d/named restart
$ chkconfig named on

After restarting named service, you will be able to see zone files in slave DNS at /var/named/chroot/var/named/slaves/.


4. Test DNS Setup

Now you can query your DNS master & slaves with the following command.

nslookup <domainname.com> <dns server name/ip>

You should get the same response from both of them. Here’s the query to Master DNS server.

$ nslookup example.com 54.43.32.21

Server:         54.43.32.21
Address:        54.43.32.21#53

Name:   example.com
Address: 54.43.32.20

Here’s the query for SLave DNS server.

# nslookup example.com 54.43.32.22

Server:         54.43.32.22
Address:        54.43.32.22#53

Name:   example.com
Address: 54.43.32.20

The above output shows that both DNS master and slave have correctly resolved domain example.com. In this article, we have learnt how to setup DNS Master-Slave server. You can customize it according to your requirements. Although the above steps are for RHEL/Fedora/CentOS, you can also use it for Ubuntu/Debian Linux.

Also read:

How to Restrict SFTP Users to Specific Directory in Linux
How to Create Password Protected ZIP File in Linux
How to Determine File System Type in Linux
How to Password Protect File in Linux
How to Block or Disable User Login in Linux

Leave a Reply

Your email address will not be published.