Sunday, 22 December 2013

How To Create master and slave DNS Servers

Configuration DNS Master & Slave server on linux

The procedure below can be used with any UNIX/LINUX flavor. All the machines in this example are using Red Hat Enterprise Linux 5.

For simplicity purposes, we will assume the server will resolve names on the LAN: 192.168.0.1/24, and the LAN has 4 workstations connected:
station1.example.com: 192.168.0.1
station2.example.com: 192.168.0.2
station3.example.com: 192.168.0.3
station4.example.com: 192.168.0.4

We will configure “station1.example.com” as a master DNS server, and “station2.example.com” as a slave DNS Server.

We will start by configuring the master DNS Server:

1. The package needed for this configuration is “BIND”. Check if it’s available:

[root@station1 named]# rpm -qa|grep bind

ypbind-1.19-12.el5

bind-libs-9.3.6-4.P1.el5

bind-utils-9.3.6-4.P1.el5

bind-9.3.6-4.P1.el5

[root@station1 named]#

2. Edit “/etc/named.conf” as follows:

[root@station1 ~]# vi /etc/named.conf

options {

directory "/var/named";

};



zone "example.com" {

type master;

file "forward.zone";

};



zone "0.168.192.in-addr.arpa" {

type master;

file "reverse.zone";

};

[root@station1 ~]#

In the file above, we first specified that the Host Name to IP records will be stored in files under the directory “/var/named”, and then we created a zone for forward mapping (Host Name to IP mapping), and a zone for reverse mapping ( IP to Host Name mapping). Since we only have one LAN (one domain: example.com), so we need two zones only.

3. Create the forward zone file “forward.zone” under “/var/named” :

[root@station1 ~]# cd /var/named

[root@station1 named]# vi forward.zone

$TTL    86400

@               IN      SOA     station1.example.com.   root    (

                                                42      ; serial (d. adams)

                                                3H      ; refresh

                                                15M     ; retry

                                                1W      ; expiry

                                                1D )    ; minimum

                IN      NS      station1.example.com.

station1        IN      A       192.198.0.1

station2        IN      A       192.168.0.2

station3        IN      A       192.198.0.3

station4        IN      A       192.168.0.4



[root@station1 named]#

In the file above, we specified that the “SOA” (start of authority) is “station1.example.come”, and that error messages be sent to “root”.

Then we specified that the “NS” (Domain Name Server) is “station1.example.com.” Then we added the “A” (Address) of each machine on the network.

4. Create the forward zone file “reverse.zone” under “/var/named” :

[root@station1 ~]# cd /var/named

[root@station1 named]# vi reverse.zone

$TTL    86400

@               IN      SOA     station1.example.com    root    (

                                                42      ; serial (d. adams)

                                                3H      ; refresh

                                                15M     ; retry

                                                1W      ; expiry

                                                1D )    ; minimum

                IN      NS      station1.example.com.

1               IN      PTR     station1.example.com.

2               IN      PTR     station2.example.com.

3               IN      PTR     station3.example.com.

4               IN      PTR     station4.example.com.



[root@station1 named]#

In the reverse file, again we specified the same “SOA” and “NS”. After that, we specified the “PTR” (pointer), so that it will be appended to “0.168.192.in-addr.arpa”. For example, the record “192.168.0.4″ when queried to the DNS Server, it will be translated as “4.0.168.192.in-addr.arpa”, and then mapped to “station4.example.com.”

5. Make the sure that “forward.zone” and “reverse.zone” have the right owner/permission:

[root@station1 named]# ls -l

total 24

drwxrwx--- 2 named named 4096 Jul 29  2009 data

-rw-r--r-- 1 root  root 239 Oct 17 16:57 forward.zone

-rw-r--r-- 1 root  root  250 Oct 17 16:55 reverse.zone

drwxrwx--- 2 named named 4096 Jul 29  2009 slaves

[root@station1 named]#

Since the daemon “named” will be using these file, the permission should be changed accordingly:

[root@station1 named]# chgrp named *.zone

[root@station1 named]# ls -l

total 24

drwxrwx--- 2 named named 4096 Jul 29  2009 data

-rw-r--r-- 1 root  named  239 Oct 17 16:57 forward.zone

-rw-r--r-- 1 root  named  250 Oct 17 16:55 reverse.zone

drwxrwx--- 2 named named 4096 Jul 29  2009 slaves

[root@station1 named]#

6. Configure all the clients to use “station1″ as a DNS Server by editing “/etc/resolv.conf”:

[root@station1 ~]# vi /etc/resolv.conf

search example.com

nameserver 192.168.0.1

[root@station1 ~]#

Make sure to configure the same on all the machines: station2, station3, and station4.

7. Start the service:

[root@station1 ~]# service named start

Starting named:                                            [  OK  ]

[root@station1 ~]#

Make the sure the service starts automatically after each reboot:

[root@station1 ~]# chkconfig named on

[root@station1 ~]# chkconfig named --list

named           0:off   1:off   2:on    3:on    4:on    5:on    6:off

[root@station1 ~]#

8. Test the DNS functionality:

From Station3, for example, we can run the following tests:

[root@station3 ~]# nslookup station2

Server:         192.168.0.1

Address:        192.168.0.1#53



Name:   station2.example.com

Address: 192.168.0.2



[root@station3 ~]#

[root@station3 ~]# nslookup station1

Server:         192.168.0.1

Address:        192.168.0.1#53



Name:   station1.example.com

Address: 192.198.0.1



[root@station3 ~]# nslookup 192.168.0.4

Server:         192.168.0.1

Address:        192.168.0.1#53



4.0.168.192.in-addr.arpa        name = station4.example.com.



[root@station3 ~]#

Now we have successfully configured “station1″ as a master (primary) DNS Server. The next step is to configure “station2″ as a slave (secondary) DNS Server. It’s very easy to do so, as only one file needs to be edited on “station2″:

1. Configure “/etc/named.conf” on “station2″ :

[root@station2 ~]# vi /etc/named.conf

options {

directory "/var/named/slaves";

};



zone "example.com" {

type slave;

file "forward.zone";

masters { 192.168.0.1; };

};



zone "0.168.192.in-addr.arpa" {

type slave;

file "reverse.zone";

masters { 192.168.0.1; };

};



[root@station2 ~]#

In “/var/named.conf”, we simply specified that the files should go under “/var/named/slaves”, and the the master DNS server is “192.168.0.1″ (i.e. station1) .

2. The next step is start the DNS Service on “station2″:

[root@station2 ~]# service named start

Starting named:                                            [  OK  ]

[root@station2 ~]#

[root@station2 ~]# chkconfig named on

[root@station2 ~]# chkconfig named --list

named           0:off   1:off   2:on    3:on    4:on    5:on    6:off

[root@station2 ~]#

3. Check that all the configuration files have been automatically copied from the master DNS Server:

[root@station2 ~]# ls /var/named/slaves/

forward.zone  reverse.zone

[root@station2 ~]#

[root@station2 ~]# cat /var/named/slaves/forward.zone

$ORIGIN .

$TTL 86400      ; 1 day

example.com             IN SOA  station1.example.com. root.example.com. (

                                42         ; serial

                                10800      ; refresh (3 hours)

                                900        ; retry (15 minutes)

                                604800     ; expire (1 week)

                                86400      ; minimum (1 day)

                                )

                        NS      station1.example.com.

$ORIGIN example.com.

station1                A       192.198.0.1

station2                A       192.168.0.2

[root@station2 ~]# cat /var/named/slaves/reverse.zone

$ORIGIN .

$TTL 86400      ; 1 day

0.168.192.in-addr.arpa  IN SOA  station1.example.com.0.168.192.in-addr.arpa. root.0.168.192.in-addr.arpa. (

                                42         ; serial

                                10800      ; refresh (3 hours)

                                900        ; retry (15 minutes)

                                604800     ; expire (1 week)

                                86400      ; minimum (1 day)

                                )

                        NS      station1.example.com.

$ORIGIN 0.168.192.in-addr.arpa.

1                       PTR     station1.example.com.

2                       PTR     station2.example.com.

[root@station2 ~]#

4. Now, on all the clients (station1, station2, station3, and station4 ), Edit the file “/etc/resolv.conf” to specify that “station2″ is a slave DNS Server:

[root@station1 ~]# cat /etc/resolv.conf

search example.com

nameserver 192.168.0.1

nameserver 192.168.0.2

[root@station1 ~]#


No comments:

Post a Comment

What is RAID ?

  What is RAID?   RAID Levels - How the drives are organized   How to determine your RAID level  RAID 0 - Disk Striping   RAID 1 - Disk Mirr...

most viewed