Primary DNS Server on RHEL 5.x

Step- 1: Check bind and caching-nameserver rpm package is installed or not by following this command:

[root@ns1 ~]# rpm -qa | grep –i bind*    or
[root@ns1 ~]#  rpm –qa bind*            (if installed then it will show all the bind related packages)

bind-chroot-9.3.6-4.P1.el5
bind-libs-9.3.6-4.P1.el5
ypbind-1.19-12.el5
bind-9.3.6-4.P1.el5
bind-utils-9.3.6-4.P1.el5
bind-sdb-9.3.6-4.P1.el5
bind-devel-9.3.6-4.P1.el5
bind-libbind-devel-9.3.6-4.P1.el5
system-config-bind-4.0.3-4.el5

[root@ns1 ~]# rpm -qa caching-nameserver* 

Caching-nameserver-9.3.6-4.P1.el5

If not installed, then install the packages using  Yum command:

[root@ns1 ~]# Yum Install bind* caching-nameserver* -y

Step-2: Check and Configure the Network Card:

[root@ns1 ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0

(Original File):

#Broadcom Corporation Net link BCM57875 Gigabyte Ethernet PCI Express

DEVICE=eth0
BOOTPROTO=dhcp

HWADDR=00:0C:29: EB: B2: CA

ONBOOT=yes

 (Modified File):

#Broadcom Corporation Net link BCM57875 Gigabyte Ethernet PCI Express

DEVICE=eth0
BOOTPROTO=static
HWADDR=00:0C:29: EB: B2: CA
ONBOOT=yes
TYPE=Ethernet
PEERDNS=no
USERCTL=no
IPV6INIT=no
IPADDR=210.207.201.1
NETMASK=255.255.255.0
NETWORK=210.207.201.0
BROADCAST=210.207.201.255

After changing you have to reload/restart the NIC(eth0) card by following command:

[root@ns1 ~]# ifdown eth0
[root@ns1 ~]# ifup eth0
[root@ns1 ~]# service network restart

Step-3: After complete the NIC configure you have to change the host name by following this command:

[root@ns1 ~]# vi /etc/sysconfig/network

(Original File):

NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=localhost.localdomain

(Modified File):

NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=ns1

Step-4: Now Edit hosts file for host name resolution by following this command:

[root@ns1 ~]# vi /etc/hosts

(Original File):

# Do not remove the following line, or various programs
# that require network functionality will fail.

127.0.0.1       localhost.localdomain localhost

(Modified File):

# Do not remove the following line, or various programs
# that require network functionality will fail.

127.0.0.1       localhost.localdomain localhost
210.207.201.1   ns1.mydomain.com          ns1

Step-5: Copy & Rename the named.rfc1912.zones file to named.conf file & Change the ownership & permission by following this command:

[root@ns1 ~]# cd /var/named/chroot/etc/
[root@ns1 etc]# cp named.rfc1912.zones  named.conf
[root@ns1 etc]# chown root:named named.conf
[root@ns1 etc]# chmod 777 named.conf

Now Create A Link into /etc directory of named.conf then edit.

[root@ns1 etc]# ln –s /var/named/chroot/etc/named.conf  /etc/named.conf
[root@ns1 ~]# vi /etc/named.conf

Original File:

// named.rfc1912.zones:
//
// Provided by Red Hat caching-nameserver package
//
// ISC BIND named zone configuration for zones recommended by
// RFC 1912 section 4.1 : localhost TLDs and address zones
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//

zone “.” IN {
     type hint;
     file “named.ca”;
};

zone “localdomain” IN {
     type master;
     file “localdomain.zone”;
     allow-update { none; };
};

zone “localhost” IN {
     type master;
     file “localhost.zone”;
     allow-update { none; };
};

zone “0.0.127.in-addr.arpa” IN {
     type master;
     file “named.local”;
     allow-update { none; };
};

zone “0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa” IN {
        type master;
     file “named.ip6.local”;
     allow-update { none; };
};

zone “255.in-addr.arpa” IN {
     type master;
     file “named.broadcast”;
     allow-update { none; };
};

zone “0.in-addr.arpa” IN {
     type master;
     file “named.zero”;
     allow-update { none; };
};

Modified File:

// named.rfc1912.zones:
//
// Provided by Red Hat caching-nameserver package
//
// ISC BIND named zone configuration for zones recommended by
// RFC 1912 section 4.1 : localhost TLDs and address zones
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//

options {

     directory “/var/named”;
};

zone “.” IN {
type hint;
file “named.ca”;
};

zone “localdomain” IN {
type master;
file “localdomain.zone”;
allow-update { none; };
};

zone “localhost” IN {
type master;
file “localhost.zone”;
allow-update { none; };
};

zone “0.0.127.in-addr.arpa” IN {
type master;
file “named.local”;
allow-update { none; };
};

zone “0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa” IN {
type master;
file “named.ip6.local”;
allow-update { none; };
};

zone “255.in-addr.arpa” IN {
type master;
file “named.broadcast”;
allow-update { none; };
};

zone “0.in-addr.arpa” IN {
type master;
file “named.zero”;
allow-update { none; };
};

zone “mydomain.com” IN {
type master;
file “mydomain.fz”;
};

zone “201.207.210.in-addr.arpa” IN {
type master;
file “mydomain.rz”;
};

Step-6: Copy, rename & change the ownership & permission of  localhost.zone file  for Forward lookup zone.

[root@ns1 ~]# cd /var/named/chroot/var/named/
[root@ns1 named]# cp localhost.zone mydomain.fz
[root@ns1 named]# chown root:named mydomain.fz
[root@ns1 named]# chmod 777 mydomain.fz
[root@ns1 named]# vi mydomain.fz

Original File:  localhost.zone

$TTL 86400
@          IN SOA    @      root (
                             42         ; serial (d.adams
                             3H         ; refresh
                             15M        ; retry
                             1W         ; expiry
                             1D )       ; minimum

           IN  NS    @
           IN  A          127.0.0.1
           IN  AAAA             ::1

Modified File:  mydomain.fz

$TTL 86400
@          IN SOA    ns1.mydomain.com.      root.mydomain.com. (
                                    20111022500; serial (d.adams
                                    3H         ; refresh
                                    15M        ; retry
                                    1W         ; expiry
                                    1D )       ; minimum

           IN  NS    ns1.mydomain.com.
ns1        IN  A     210.207.201.1

Step-7: copy & rename the mydomain.fz  file  for Reverse lookup zone.

[root@ns1 named]# cp mydomain.fz mydomain.rz
[root@ns1 named]# vi mydomain.rz

Original File:  mydomain.fz

$TTL 86400
@          IN SOA    ns1.mydomain.com.      root.mydomain.com. (
                                    20111022500; serial (d.adams
                                    3H         ; refresh
                                    15M        ; retry
                                    1W         ; expiry
                                    1D )       ; minimum

           IN  NS    ns1.mydomain.com.
ns1        IN  A     210.207.201.1

Modified File:  mydomain.rz

$TTL 86400
@          IN SOA    ns1.mydomain.com.      root.mydomain.com. (
                                    20111022500; serial (d.adams
                                    3H         ; refresh
                                    15M        ; retry
                                    1W         ; expiry
                                    1D )       ; minimum

 

           IN  NS    ns1.mydomain.com.
1          IN  PTR   ns1.mydomain.com.

Step-8:  Edit the resolv.conf file by following this command.

[root@ns1 named]# vi /etc/resolv.conf

search mydomain.com
nameserver 210.207.201.1

Step-9:    Check the named.conf & zone file by following this commands.

[root@ns1 ~]# named-checkconf /var/named/chroot/etc/named.conf
[root@ns1 ~]# named-checkzone mydomain.com /var/named/chroot/var/named
/mydomain.fz

[root@ns1 ~]# named-checkzone mydomain.com /var/named/chroot/var/named
/mydomain.rz

Step-10: DNS check

[root@ns1 ~]# service iptables stop
[root@ns1 ~]# service network restart
[root@ns1 ~]# chkconfig named on
[root@ns1 ~]# service named restart/status/start/stop/configtest
[root@ns1 ~]# host 210.207.201.1
[root@ns1 ~]# host ns1.mydomain.com
[root@ns1 ~]# Ping ns1.mydomain.com
[root@ns1 ~]# nslookup ns1.mydomain.com
[root@ns1 ~]# nslookup 210.207.201.1
[root@ns1 ~]# dig ns1.mydomain.com
[root@ns1 ~]# dig –x 210.207.201.1
[root@ns1 ~]# dig –x ns1.mydomain.com
[root@ns1 ~]# dig –t SOA mydomain.com
[root@ns1 ~]# dig –t axfr mydomain.com

Author Info

Md. Kamrul Hassan

Myself is a Computer Network Specialist. Working in a training center (name - Acme IT) in Bangladesh. Basically most of the tutorial I have written here is created for my students. Happy to know if it become useful for visitors. You can find me at Facebook