In this article we will learn How to Setup Master Slave DNS Server on Cent-OS 6 and RHEL Systems.

We will assume the following Network Scenario for our Setup:

  1. Master DNS Server IP: 10.0.1.14 ( ns1.alex.net )
  2. Slave DNS Server IP: 10.0.1.15 ( ns2.alex.net )
  3. Domain Name : alex.net
  4. Domain IP : 10.0.1.16

Step 1: Install Required RPMS (at Master and Slave Both)

Install bind packages at both Master and Slave dns servers using following commands.

# yum install bind bind-chroot

Step 2: Setup Master (NS1) DNS Server

There are two types of configuration files in DNS.

  • The main dns configuration files named “named.conf”
  • Another type of configuration file are called zone file. Which is individually created for all domains. named.conf keeps an entry for all zone files.

 2.1 Configure named.conf as shown below

# vim /var/named/chroot/etc/named.conf

Content of named.conf:

// /var/named/chroot/etc/named.conf

options {

listen-on port 53 { 127.0.0.1; 192.168.1.0/24; };

directory       “/var/named”;

dump-file       “/var/named/data/cache_dump.db”;

statistics-file “/var/named/data/named_stats.txt”;

memstatistics-file “/var/named/data/named_mem_stats.txt”;

allow-query     { localhost; 192.168.1.0/24; };

recursion yes;

dnssec-enable yes;

dnssec-validation yes;

dnssec-lookaside auto;

/* Path to ISC DLV key */

bindkeys-file “/etc/named.iscdlv.key”;

managed-keys-directory “/var/named/dynamic”;

};

logging {

channel default_debug {

file “data/named.run”;

severity dynamic;

};

};

zone “.” IN {

type hint;

file “named.ca”;

};

zone “alex.net” IN {

type master;

file “/var/named/alex.net.db”;

allow-update { none; };

};

include “/etc/named.rfc1912.zones”;

 2.2 Create a zone file for you domain “alex.net”

# vim /var/named/chroot/var/named/alex.net.db

Content of zone file:

; Zone file for alex.net

$TTL 14400

@      86400    IN      SOA     ns1.alex.net. webmaster.alex.net. (

3215040200           ; serial

86400                     ; refresh, seconds

7200                       ; retry, seconds

3600000                 ; expire, seconds

86400                     ; minimum, seconds

)

alex.net. 86400 IN NS ns1.alex.net.

alex.net. 86400 IN NS ns2.alex.net.

alex.net. IN A 10.0.1.16

alex.net. IN MX 0 alex.net.

mail         IN CNAME alex.net.

www      IN CNAME alex.net.

 2.3 Add more domains in dns server.

To add more domains in dns, create zone files individually for all domain as above. After that add any entry for all zones in named.conf like below. Change alex.net with your domain name.

zone “alex.net” IN {

type master;

file “/var/named/alex.net.db”;

allow-update { none; };

};

Step 2.4: Start named service.

Start named (bind) service using following command and setup auto start on system boot.

# service named restart

# chkconfig named on

Step 3: Setup Slave (NS2) DNS Server

At slave dns server you need to update named.conf file only. All zone files will automatically synced from master dns server. Any changes done on Master will reflect on slave after a specified time interval.

3.1 Configure named.conf using below configuration

# vim /var/named/chroot/etc/named.conf

Content of named.conf:

// /var/named/chroot/etc/named.conf

options {

listen-on port 53 { 127.0.0.1; 192.168.1.0/24; };

directory       “/var/named”;

dump-file       “/var/named/data/cache_dump.db”;

statistics-file “/var/named/data/named_stats.txt”;

memstatistics-file “/var/named/data/named_mem_stats.txt”;

allow-query     { localhost; 192.168.1.0/24; };

recursion yes;

dnssec-enable yes;

dnssec-validation yes;

dnssec-lookaside auto;

/* Path to ISC DLV key */

bindkeys-file “/etc/named.iscdlv.key”;

managed-keys-directory “/var/named/dynamic”;

};

logging {

channel default_debug {

file “data/named.run”;

severity dynamic;

};

};

zone “.” IN {

type hint;

file “named.ca”;

};

zone “alex.net” IN {

type slave;

file “slaves/alex.net.db”;

masters { 10.0.1.14; };

};

include “/etc/named.rfc1912.zones”;

 

Step 3.2: Start named Service 

Start named (bind) service using below command.

# /etc/init.d/named restart

# chkconfig named on

After restarting named service, Check zone files on slave dns server at /var/named/chroot/var/named/slaves/.

Step 4: Finally Test Your DNS Setup.

Query to your Master and Slave DNS Server directly using following commands, you will get the same response from both servers.
Syntax: nslookup

Query to Master DNS Server:

# nslookup alex.net 10.0.1.14

Server:         10.0.1.14

Address:        10.0.1.14#53

Name:   alex.net

Address: 10.0.1.16

Query to Slave DNS Server:

# nslookup alex.net 10.0.1.15

Server:         10.0.1.15

Address:        10.0.1.15#53

Name:   alex.net

Address: 10.0.1.16

Above outputs is showing that dns server has successfully resolved domain alex.net from master and slave dns servers.

Posted in: Linux.
Last Modified: January 12, 2017

2 thoughts on “Step by step DNS server configuration in Linux

  1. navdeep

    great work bro 😉

Leave a reply