How to Setup Caching NameServer on CentOS/RHEL 6/5

 Caching name servers, also called DNS caches, store DNS query results for a period of time determined in the configuration (time-to-live) of each domain-name record. DNS caches improve the efficiency of the DNS by reducing DNS traffic across the Internet, and by reducing load on authoritative name-servers, particularly root name-servers. Because they can answer questions more quickly, they also increase the performance of end-user applications that use the DNS. Read more



This article will help you to setup caching nameserver on your CentOS/RHEL 6 system.

Step 1: Install BIND Packages

Install bind packages using below command. In CentOS/RHEL 6 chaching-nameserver package has been included with bind package.

# yum install bind bind-chroot

Step 2: Create Configuration File

Copy bind configuration file from bind sample files using below command. Change the path of files as per version you have installed.

# cd /var/named/chroot/etc
# cp /usr/share/doc/bind-9.8.2/sample/etc/named.conf  .
# cp /usr/share/doc/bind-9.8.2/sample/etc/named.rfc1912.zones  .

Step 3: Update Configuration File

Edit bind configuration file in your favorite editor and make necessary changes as per below settings or use below configuration.

#vi /var/named/chroot/etc/named.conf
options {
        listen-on port 53 { 127.0.0.1; any; };
        listen-on-v6 port 53 { ::1; };
        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; any; };
        allow-query-cache    { localhost; any; };
        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;
        };
};

include "/etc/named.rfc1912.zones";

Now update required permissions on configuration files using below command.

# chown root:named named.conf named.rfc1912.zones

Step 4: Check Configuration File

We recommend to check DNS configuration file before restarting service.

# named-checkconf named.conf

Step 5: Restart Bind Service

Now installation of bind service has been completed. Lets start bind (named) service using following command.

# service named restart

Enable auto start bind service on system boot.

# chkconfig named on

Step 6: Finally Test Caching Only DNS

Send query to your dns server directly using below command.

Syntax: nslookup <domainname> <caching dns server name/ip>

# nslookup yahoo.com 192.168.1.1

[Sample Output:]

Address:        192.168.1.1#53

nslookup yahoo.com
Server:		192.168.1.1
Address: 192.168.1.1#53
Non-authoritative answer:
Name:	yahoo.com
Address: 74.6.143.25
Name:	yahoo.com
Address: 74.6.143.26
Name:	yahoo.com
Address: 74.6.231.20
Name:	yahoo.com
Address: 74.6.231.21
Name:	yahoo.com
Address: 98.137.11.163
Name:	yahoo.com
Address: 98.137.11.164
Name:	yahoo.com
Address: 2001:4998:24:120d::1:1
Name:	yahoo.com
Address: 2001:4998:44:3507::8000
Name:	yahoo.com
Address: 2001:4998:44:3507::8001
Name:	yahoo.com
Address: 2001:4998:124:1507::f000
Name:	yahoo.com
Address: 2001:4998:124:1507::f001
Name:	yahoo.com
Address: 2001:4998:24:120d::1:0

troubleshooting :- 
#tail /var/log/messages  -f

Mar  9 10:31:04 WMsystem named[30190]: error (network unreachable) resolving 'yahoo.ae/A/IN': 2001:500:7d::1#53
Mar  9 10:31:04 WMsystem named[30190]: error (network unreachable) resolving 'yahoo.ae/A/IN': 2a00:d30:125

All of the addresses are IPv6. Seems an IPv6 issue, you probably have no IPv6 networking configured. Disable IPv6 suport in Bind:

Edit /etc/sysconfig/named and set:

OPTIONS="-4"

Then restart bind:

service named restart