HOW TO INSTALL AND CONFIGURE CACHING-ONLY DNS SERVER WITH BIND IN RHEL/CENTOS
Introduction
Today in this article we are going to discuss on 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 on 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 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 its makes us available the account by taking the username and password from cache.
Caching only DNS Server is a Server which is store the DNS query information from other servers ( eg. www.google.com ) and stores it on it’s own cache for later use.
For example when we browse for http://www.google.com 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 google.com DNS queries on it’s own cache and all clients will be able to access the website from caching DNS server within a few milliseconds.
Follow the below Steps to Configure Caching-Only DNS Server:
My Scenario :
Server Side :
IP Address : 192.168.0.105
Client Side :
IP Address : 192.168.0.103
Step: 1 Packages 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.
[root@localhost ~]# yum -y install bind Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Install Process Loading mirror speeds from cached hostfile * base: centos.excellmedia.net * extras: centos.excellmedia.net * updates: centos.excellmedia.net 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 ================================================================================ Installing: 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 Installed: 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 Complete!
Step: 2 Configure named.conf File
So we have installed all required Packages, Now we needs 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.
[root@localhost ~]# 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/named.run"; severity dynamic; }; }; zone "." IN { type hint; file "named.ca"; }; include "/etc/named.rfc1912.zones"; include "/etc/named.root.key";
After above changes just save the configuration file and start the dns service by using below command.
[root@localhost ~]# /etc/init.d/named start Generating /etc/rndc.key: [ OK ] Starting named: [ OK ]
We have to start the DNS service at at startup to start the service automatically when we restart the server, Follow the below step to do the same.
[root@localhost ~]# chkconfig --level 35 named on [root@localhost ~]# 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 informations :
- Question we have asked using dig for eg: dig @localhost www.google.com
- Answer of the Query
- Query Time – In how many time we able to get query of domain.
- Server – We get query of the domain through the Server, here it is Caching DNS Server i.e. 192.168.0.105
Test from Server Side
After configure the Caching DNS Server, First time I run dig command to get the query information of http://www.google.com ( dig @localhost www.google.com ) and it took 1348 Milliseconds to get the information. and TTL was 300 as shown on the snapshot below.
All required and noticeable information’s are highlighted in blue color.
Again I tried to get the query of google.com by execute 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 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.
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.
[elinuxbook@localhost ~]$ cat /etc/resolv.conf # Generated by NetworkManager nameserver 192.168.0.105 # IP Address of Caching-Only DNS Server
Now run the dig command to get the query of www.google.com from caching DNS Server i.e. 192.168.0.105
Command : dig @localhost www.google.com
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 commmand as shown below.
[elinuxbook@localhost ~]$ nslookup www.google.com Server: 192.168.0.105 # IP Address of the Caching-Only DNS Server Address: 192.168.0.105#53 Non-authoritative answer: Name: www.google.com Address: 172.217.26.164
If you found this Article useful then Like it, Share it, Subscribe our Site for more Linux Tutorials OR If you have any thing to say then feel free to Comment on Comment Box below.