How to Install and Configure Caching-Only DNS Server on Linux

This article will show you – how to configure the DNS caching or forwarding server in the local environment with the use of DNS. DNS (Domain Name System) are often critical servers to get right, when we are learning things such as configure websites and servers. Most of the people will choose to use the DNS servers which is provided by the hosting company or the domain controllers.

Caching DNS Server

The configuration will cache the DNS server. This type of servers are called as resolvers because it handles recursive queries and can handle the grunts of tracking the DNS data from servers.

Installing the BIND Packages

To install bind packages we can use the below command. Also, caching-nameserver package has been included with bind package.

# yum install bind bind-chroot
Resolving Dependencies
--> Running transaction check
---> Package bind.x86_64 32:9.8.2-0.37.rc1.el6_7.7 will be installed
--> Processing Dependency: bind-libs = 32:9.8.2-0.37.rc1.el6_7.7 for package: 32:bind-9.8.2-0.37.rc1.el6_7.7.x86_64
---> Package bind-chroot.x86_64 32:9.8.2-0.37.rc1.el6_7.7 will be installed
--> Running transaction check
---> Package bind-libs.x86_64 32:9.8.2-0.37.rc1.el6 will be updated
--> Processing Dependency: bind-libs = 32:9.8.2-0.37.rc1.el6 for package: 32:bind-utils-9.8.2-0.37.rc1.el6.x86_64
---> Package bind-libs.x86_64 32:9.8.2-0.37.rc1.el6_7.7 will be an update
--> Running transaction check
---> Package bind-utils.x86_64 32:9.8.2-0.37.rc1.el6 will be updated
---> Package bind-utils.x86_64 32:9.8.2-0.37.rc1.el6_7.7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

Package Arch Version Repository Size
bind x86_64 32:9.8.2-0.37.rc1.el6_7.7 updates 4.0 M
bind-chroot x86_64 32:9.8.2-0.37.rc1.el6_7.7 updates 75 k
Updating for dependencies:
bind-libs x86_64 32:9.8.2-0.37.rc1.el6_7.7 updates 887 k
bind-utils x86_64 32:9.8.2-0.37.rc1.el6_7.7 updates 186 k

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

Total download size: 5.1 M
Is this ok [y/N]: y
Downloading Packages:
(1/4): bind-9.8.2-0.37.rc1.el6_7.7.x86_64.rpm | 4.0 MB 00:00
(2/4): bind-chroot-9.8.2-0.37.rc1.el6_7.7.x86_64.rpm | 75 kB 00:00
(3/4): bind-libs-9.8.2-0.37.rc1.el6_7.7.x86_64.rpm | 887 kB 00:00
(4/4): bind-utils-9.8.2-0.37.rc1.el6_7.7.x86_64.rpm | 186 kB 00:00
Total 1.4 MB/s | 5.1 MB 00:03
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Updating : 32:bind-libs-9.8.2-0.37.rc1.el6_7.7.x86_64 1/6
Installing : 32:bind-9.8.2-0.37.rc1.el6_7.7.x86_64 2/6
Installing : 32:bind-chroot-9.8.2-0.37.rc1.el6_7.7.x86_64 3/6
Updating : 32:bind-utils-9.8.2-0.37.rc1.el6_7.7.x86_64 4/6
Cleanup : 32:bind-utils-9.8.2-0.37.rc1.el6.x86_64 5/6
Cleanup : 32:bind-libs-9.8.2-0.37.rc1.el6.x86_64 6/6
Verifying : 32:bind-chroot-9.8.2-0.37.rc1.el6_7.7.x86_64 1/6
Verifying : 32:bind-utils-9.8.2-0.37.rc1.el6_7.7.x86_64 2/6
Verifying : 32:bind-9.8.2-0.37.rc1.el6_7.7.x86_64 3/6
Verifying : 32:bind-libs-9.8.2-0.37.rc1.el6_7.7.x86_64 4/6
Verifying : 32:bind-libs-9.8.2-0.37.rc1.el6.x86_64 5/6
Verifying : 32:bind-utils-9.8.2-0.37.rc1.el6.x86_64 6/6
bind.x86_64 32:9.8.2-0.37.rc1.el6_7.7 bind-chroot.x86_64 32:9.8.2-0.37.rc1.el6_7.7
Dependency Updated:
bind-libs.x86_64 32:9.8.2-0.37.rc1.el6_7.7 bind-utils.x86_64 32:9.8.2-0.37.rc1.el6_7.7
Config the Configuration File

For security, we needed to copy the bind configuration file from bind sample files with below command. Needed to change the path of files as per version we have installed.

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

Update the Configuration File

We can edit bind configuration file in your favorite editor and make necessary changes as per the below requirements and settings –

# /var/named/chroot/etc/named.conf
options {
   listen-on port 53 {; 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/";
      severity dynamic;
include "/etc/named.rfc1912.zones";

Now update the required permissions on configuration files using below command.

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

Check Configuration File

We recommend to check the DNS configuration file before restarting services, with the below command –

# named-checkconf named.conf

Restart Bind Service

Now the installation & configuration of bind service have been completed. We start bind (named) services using below command.

# service named restart

Enable auto start bind service on system boot.

# chkconfig named on

Finally Test Caching Only DNS

Send the query to the DNS server directly using below command.

Syntax: nslookup <domain name> <caching dns server name/IP address>
# nslookup
[Sample Output:]
Non-authoritative answer:

If we configure the above configuration, we have successfully configured the caching DNS server on your Linux system which we can use it as a caching server in the local environment.

Sharon Christine
Sharon Christine

An investment in knowledge pays the best interest

Updated on: 20-Jan-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started