How to Install and Configure Caching-Only DNS Server with Bind in Rhel/Centos

Today in this article we are going to discuss how to install and configure caching-only DNS server with BIND in Linux. As we all know that DNS is a Service used to resolve the IP Address to Name and from Name to IP Address, The type of DNS Servers are Master/Primary DNS Server, Slave/Secondary DNS Server and Caching Only DNS Server. Here we are going to discuss Caching-Only DNS Server. Caching-Only DNS Server is also known as DNS Resolver.

Let’s first understand what is Caching. Caching is nothing but a process which is stores the data temporarily on a local database for later use, for example when we access our Gmail or Facebook account on browser for the first time it’s asking to save the password and then next time it makes us available the account by taking the username and password from the cache.

Caching only DNS Server is a Server that stores the DNS query information from other servers ( eg. ) and stores it on its own cache for later use.

For example, when we browse for it takes some time to open the webpage as it is directly querying from google server but if we configure a caching-only DNS server and configure all clients to use that then caching DNS server will store the DNS queries on its own cache and all clients will be able to access the website from caching DNS server within a few milliseconds.

Centos” src=”data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7″ data-src=”” alt=”How to Install and Configure Caching-Only DNS Server with Bind in Rhel/Centos” width=”771″ height=”435″ data-srcset=” 771w,×433.jpg 768w” data-sizes=”(max-width: 771px) 100vw, 771px”>

How to Install and Configure Caching-Only DNS Server with Bind in Rhel/Centos

Follow the below Steps to Install and Configure Caching-Only DNS Server with Bind in Rhel/Centos:

My Scenario :

Server Side :

IP Address :

Client-Side :

IP Address :

Step: 1 Package Required

We need to install Required Packages for BIND i.e. :

  • bind
  • bind-utils
  • bind-libs

Follow the below command to install bind, bind-utils, and bind-libs Packages.

   [[email protected] ~]# yum -y install bind
   Loaded plugins: fastestmirror, refresh-packagekit, security
   Setting up Install Process
   Loading mirror speeds from cached hostfile
    * base:
    * extras:
    * updates:
   Resolving Dependencies
   --> Running transaction check
   ---> Package bind.x86_64 32:9.8.2-0.47.rc1.el6_8.3 will be installed
   --> Processing Dependency: bind-libs = 32:9.8.2-0.47.rc1.el6_8.3 for package: 32:bind-9.8.2-0.47.rc1.el6_8.3.x86_64
   --> Running transaction check
   ---> Package bind-libs.x86_64 32:9.8.2-0.47.rc1.el6 will be updated
   --> Processing Dependency: bind-libs = 32:9.8.2-0.47.rc1.el6 for package: 32:bind-utils-9.8.2-0.47.rc1.el6.x86_64
   ---> Package bind-libs.x86_64 32:9.8.2-0.47.rc1.el6_8.3 will be an update
   --> Running transaction check
   ---> Package bind-utils.x86_64 32:9.8.2-0.47.rc1.el6 will be updated
   ---> Package bind-utils.x86_64 32:9.8.2-0.47.rc1.el6_8.3 will be an update
   --> Finished Dependency Resolution

   Dependencies Resolved

    Package         Arch        Version                         Repository    Size
    bind            x86_64      32:9.8.2-0.47.rc1.el6_8.3       updates      4.0 M
   Updating for dependencies:
    bind-libs       x86_64      32:9.8.2-0.47.rc1.el6_8.3       updates      890 k
    bind-utils      x86_64      32:9.8.2-0.47.rc1.el6_8.3       updates      187 k

   Transaction Summary
   Install       1 Package(s)
   Upgrade       2 Package(s)

   Total download size: 5.0 M
   Downloading Packages:
   (1/3): bind-9.8.2-0.47.rc1.el6_8.3.x86_64.rpm            | 4.0 MB     00:49     
   (2/3): bind-libs-9.8.2-0.47.rc1.el6_8.3.x86_64.rpm       | 890 kB     00:01     
   (3/3): bind-utils-9.8.2-0.47.rc1.el6_8.3.x86_64.rpm      | 187 kB     00:00     
   Total                                           100 kB/s | 5.0 MB     00:51     
   Running rpm_check_debug
   Running Transaction Test
   Transaction Test Succeeded
   Running Transaction
     Updating   : 32:bind-libs-9.8.2-0.47.rc1.el6_8.3.x86_64                   1/5 
     Updating   : 32:bind-utils-9.8.2-0.47.rc1.el6_8.3.x86_64                  2/5 
     Installing : 32:bind-9.8.2-0.47.rc1.el6_8.3.x86_64                        3/5 
     Cleanup    : 32:bind-utils-9.8.2-0.47.rc1.el6.x86_64                      4/5 
     Cleanup    : 32:bind-libs-9.8.2-0.47.rc1.el6.x86_64                       5/5 
     Verifying  : 32:bind-utils-9.8.2-0.47.rc1.el6_8.3.x86_64                  1/5 
     Verifying  : 32:bind-libs-9.8.2-0.47.rc1.el6_8.3.x86_64                   2/5 
     Verifying  : 32:bind-9.8.2-0.47.rc1.el6_8.3.x86_64                        3/5 
     Verifying  : 32:bind-libs-9.8.2-0.47.rc1.el6.x86_64                       4/5 
     Verifying  : 32:bind-utils-9.8.2-0.47.rc1.el6.x86_64                      5/5 

     bind.x86_64 32:9.8.2-0.47.rc1.el6_8.3                                         

   Dependency Updated:
     bind-libs.x86_64 32:9.8.2-0.47.rc1.el6_8.3                                    
     bind-utils.x86_64 32:9.8.2-0.47.rc1.el6_8.3                                   


Step: 2 Configure named.conf File

So we have installed all required Packages, Now we need to configure the main configuration file of DNS Server i.e. named.conf to work as a caching-only DNS server.

Here below I have mentioned my named.conf file and Highlighted all required changes I did in Blue Color.

   [[email protected] ~]# nano /etc/named.conf   
   // named.conf
   // Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
   // server as a caching only nameserver (as a localhost DNS resolver only).
   // See /usr/share/doc/bind*/sample/ for example named configuration files.

   options {
    listen-on port 53 { any; };     # Allowed to Listen Port 53 on any System
           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     { any; };    # Allowed to Listen Port 53 on any Network
           recursion yes; 

           dnssec-enable yes;
           dnssec-validation yes;

           /* Path to ISC DLV key */
           bindkeys-file "/etc/named.iscdlv.key";

           managed-keys-directory "/var/named/dynamic";

   logging {
        channel default_debug {
                   file "data/";
                   severity dynamic;

   zone "." IN {
    type hint;
           file "";

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

After the above changes just save the configuration file and start the DNS service by using the below command.

   [[email protected] ~]# /etc/init.d/named start
   Generating /etc/rndc.key:                                  [  OK  ]
   Starting named:                                            [  OK  ]

We have to start the DNS service at a startup to start the service automatically when we restart the server, follow the below step to do the same.

   [[email protected] ~]# chkconfig --level 35 named on
   [[email protected] ~]# chkconfig --list named
   named           0:off 1:off 2:off 3:on 4:off 5:on 6:off

So we have successfully configured the Caching Only DNS Server, Now it’s time for testing, We have tools like dig, nslookup to check the DNS service working status. So let’s first use the dig command as shown below.

dig command gives us the below useful information:

  • The question we have asked using dig for eg: dig @localhost
  • The answer of the Query
  • Query Time – In how many times we able to get a query of the domain.
  • Server – We get a query of the domain through the Server, here it is Caching DNS Server i.e.

Test from Server Side

After configuring the Caching DNS Server, the First time I run dig command to get the query information of ( dig @localhost ) and it took 1348 Milliseconds to get the information. and TTL was 300 as shown on the snapshot below.
All required and noticeable information are highlighted in blue color.

How to Install and Configure Caching-Only DNS Server with Bind in Rhel/Centos

Test from Server Side

Again I tried to get the query of by executing the same command and just have look at the output below.

Query Time dropped to 0 msec (milliseconds)
TTL ( Time To Alive )- 243

We able to get a quick response because the DNS query of the site was already cached in our Caching DNS server, hence it didn’t take much time to deliver the result.

How to Install and Configure Caching-Only DNS Server with Bind in RhelCentos

Also Read – How to Configure Slave DNS Server With Bind ( Secondary Dns Server ) In Linux

Test from Client-Side

We need to configure the client-side to take the query from Caching DNS Server for that just edit the /etc/resolv.conf  and enter the IP Address of the Caching Only DNS Server as shown below.

 [[email protected] ~]$ cat /etc/resolv.conf 
   # Generated by NetworkManager
   nameserver     # IP Address of Caching-Only DNS Server

Now run the dig command to get the query of from caching DNS Server i.e.

Command: dig @localhost

How to Install and Configure Caching-Only DNS Server with Bind in RhelCentos

As we can see above on the snapshot we got the query within 0 msec (milliseconds), Also we can check the name resolution by running nslookup command as shown below.

   [[email protected] ~]$ nslookup
   Server:     # IP Address of the Caching-Only DNS Server

   Non-authoritative answer:

Download Free Linux eBook HERE! Learn Linux in 5 Days - A Free Linux eBooks for Beginners

That’s all, In this article, we have explained How to Install and Configure Caching-Only DNS Server with Bind in Rhel/Centos. I hope you enjoy this article. If you like this article, then just share it. If you have any questions about this article, please comment.