setup dns caching server

How to Setup DNS Caching Server in CentOS, Redhat

DNS Cache, also known as Cache Nameserver cache the results of DNS queries for a specific period of time, defined in the time to live (TTL) value for each domain. It reduces DNS traffic and improves browsing speed of end users. It also reduces load on popular name servers. In this article, we will learn how to setup DNS caching server in CentOS, Redhat Linux systems.


How to Setup DNS Caching Server in CentOS, Redhat

Here are the steps to setup DNS caching server in CentOS, Redhat.


1. Install Bind Packages

Open terminal and run the following command to install bind packages for CentOS/RHEL.

# yum install bind bind-chroot


2. Create Configuration file

The bind packages contain sample configuration file, which we will copy to create our own configuration file. Update the file path depending on your installation location.

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


3. Update Configuration File

Open the newly created configuration file in a text editor.

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

Update the following configuration as shown below.

// /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";

Basically, we are setting the locations for different files (dump file, stats file, etc) required by our name server.

Also update the file permissions of the 2 configuration files.

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


4. Test Configuration File

Run the following command to check the configuration file.

# named-checkconf named.conf


5. Restart Bind Service

Now we have installed bind service. Run the following command to restart the bind service.

# service named restart

Run the following command to enable autostart on system boot.

# chkconfig named on


6. Test Caching on DNS

Run the following command to send a DNS lookup query. Replace <domainname> and <caching dns server name/ip> with the domain name and caching server’s IP address respectively.

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

Here is an example.

# nslookup yahoo.com 192.168.1.90

You will see a similar output as shown below.

Server:         192.168.1.90
Address:        192.168.1.90#53

Non-authoritative answer:
Name:   yahoo.com
Address: 92.148.243.109
Name:   yahoo.com
Address: 92.149.163.24
Name:   yahoo.com
Address: 205.180.136.45

In this article, we have learnt how to setup DNS caching server, also known as name caching server in CentOS/RHEL systems. You can also use these steps on Fedora/SUSE Linux.

Also read:

How to Delete Linux Partition
How to Backup SAP HANA database
How to Add Multiple Hosts in PHPMyAdmin
Git Compare Difference Between Branches
How to Uninstall Ubuntu from Dual Boot

Leave a Reply

Your email address will not be published. Required fields are marked *