• Categories
    Category
  • Categories
    Category
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial Comments FAQ Related Articles

How to setup cache only DNS server using Bind in CentOS 7

817

Using Bind for Setting Up Caching-Only DNS Server in CentOS 7

There are many types of DNS servers like master, slave, forwarding and cache, among them Caching-Only DNS is one, that is easier to setup. DNS employs UDP protocol that will reduce the query time since UDP protocol does not have an acknowledgement. The caching-only DNS server is also called as a resolver, it queries DNS records and collects all DNS information from other servers and stores each query request in its cache.

My Testing Environment

IP Address : 192.168.5.221
Host-name : dns.linuxhelp.com
OS : Centos 7
Ports Used : 53
Config File : /etc/named.conf

Installation of Caching-Only DNS

The Caching-Only DNS, can be installed with the package bind. We use the following command to search for the package name.


[root@dns Desktop]# yum search bind*
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.excellmedia.net
 * extras: centos.excellmedia.net
 * updates: centos.excellmedia.net
=================================== N/S matched: bind ===================================
PackageKit-device-rebind.x86_64 : Device rebind functionality for PackageKit
bind.x86_64 : The Berkeley Internet Name Domain (BIND) DNS (Domain Name System) server
bind-chroot.x86_64 : A chroot runtime environment for the ISC BIND DNS server, named(8)
.
.
.
telepathy-glib.x86_64 : GLib bindings for Telepathy
telepathy-glib.i686 : GLib bindings for Telepathy
telepathy-glib-vala.x86_64 : Vala bindings for telepathy-glib
texlive-fontwrap.noarch : Bind fonts to specific unicode blocks
vala-tools.x86_64 : Tools for creating projects and bindings for vala
  Name and summary matches only, use " search all"  for everything.


We need to choose the bind and bind-utils packages, from the above displayed list of packages by using yum command.

[root@dns Desktop]# yum install bind*
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.excellmedia.net
 * extras: centos.excellmedia.net
 * updates: centos.excellmedia.net
Package 32:bind-devel-9.9.4-29.el7_2.3.x86_64 already installed and latest version
Package 32:bind-libs-9.9.4-29.el7_2.3.x86_64 already installed and latest version
Package 32:bind-license-9.9.4-29.el7_2.3.noarch already installed and latest version
Package 32:bind-pkcs11-libs-9.9.4-29.el7_2.3.x86_64 already installed and latest version
.
.
.
  Verifying  : 32:bind-sdb-9.9.4-29.el7_2.3.x86_64                                   1/6 
  Verifying  : bind-dyndb-ldap-8.0-1.el7.x86_64                                      2/6 
  Verifying  : 32:bind-chroot-9.9.4-29.el7_2.3.x86_64                                3/6 
  Verifying  : 32:bind-sdb-chroot-9.9.4-29.el7_2.3.x86_64                            4/6 
  Verifying  : 32:bind-9.9.4-29.el7_2.3.x86_64                                       5/6 
  Verifying  : 32:bind-pkcs11-9.9.4-29.el7_2.3.x86_64                                6/6 

Installed:
  bind.x86_64 32:9.9.4-29.el7_2.3         bind-chroot.x86_64 32:9.9.4-29.el7_2.3        
  bind-dyndb-ldap.x86_64 0:8.0-1.el7      bind-pkcs11.x86_64 32:9.9.4-29.el7_2.3        
  bind-sdb.x86_64 32:9.9.4-29.el7_2.3     bind-sdb-chroot.x86_64 32:9.9.4-29.el7_2.3    

Complete!

Configuring Caching-Only DNS

After the DNS packages are installed we need to configure DNS to do that open and edit named.conf file using the vim editor.

[root@dns Desktop]# vi /etc/named.conf


Following are the mandatory changes, that we need to perform for a caching-only DNS server. By default the localhost will be available and we need to add any to accept the query from any range of network.

listen-on port 53 { 127.0.0.1  any  } 
allow-query     { localhost  any  } 
allow-query-cache       { localhost  any  } 


DNS server

listen-on port 53: This means that Cache server want to use the port 53 for query.
allow-query:This Specifies which ip address may query the server.
allow-query-cache: This will add the query request to the bind.
recursion: This will query the answer and returns to us, during query it may send query to other DNS server over the internet and get back the query.


After completing, we need to confirm whether the named.conf files ownership was not modified from root:named, since the DNS runs under a system user named

[root@dns Desktop]# ls -l /etc/named.conf
-rw-r-----. 1 root named 1608 Apr 26 09:09 /etc/named.conf
[root@dns Desktop]# ls -l /etc/named.rfc1912.zones 
-rw-r-----. 1 root named 931 Jun 21  2007 /etc/named.rfc1912.zones


Next we need to verify the selinux context, every named config files is required to be in system_u:object_r:named_conf_t:s0

[root@dns Desktop]# ls -lZ /etc/named.conf
-rw-r-----. root named system_u:object_r:named_conf_t:s0 /etc/named.conf
[root@dns Desktop]# ls -lZ /etc/named.rfc1912.zones 
-rw-r-----. root named system_u:object_r:named_conf_t:s0 /etc/named.rfc1912.zones


Now you need to test the DNS configuration for syntax error.

[root@dns Desktop]# named-checkconf /etc/named.conf 


Restart the service to take effect for above changes and then allow the service to run persistent while rebooting the server.

[root@dns Desktop]# systemctl enable named.service
[root@dns Desktop]# systemctl restart named.service


Once the above step completes, open the port 53 on the firewall to allow the access.

[root@dns Desktop]# iptables -I INPUT -p udp --dport 53 -j ACCEPT

Chroot Caching-Only DNS

If you like to run the DNS caching-server under chroot environment, it is necessary to install the chroot package only.

[root@dns Desktop]# yum install bind-chroot -y
Loaded plugins: fastestmirror, langpacks
base                                                              | 3.6 kB  00:00:00     
extras                                                            | 3.4 kB  00:00:00     
linuxhelp                                                         | 2.9 kB  00:00:00     
updates                                                           | 3.4 kB  00:00:00     
Loading mirror speeds from cached hostfile
 * base: centos.webwerks.com
 * extras: centos.webwerks.com
 * updates: centos.webwerks.com
.
.
.
Installed:
bind-chroot-9.9.4-29.el7_2.3.x86_64 installed
Complete!


Once chroot package installation is complete, you can restart the named service to bring new changes into effect.

[root@dns Desktop]# systemctl restart named.service


Restarting the named service, creates a hard-link from the /etc/named config files to /var/named/chroot/etc/ directory automatically.

[root@dns Desktop]#  cat /var/named/chroot/etc/named.conf


Some time the hard link will never be generated automatically that time you must create that hard link.

Setting Up DNS Client Side

Append the DNS caching servers IP 192.168.5.221 as resolver to the client systems.
In Linux environment it will be under /etc/resolv.conf or you can edit manually under /etc/sysconfig/network-scripts/ifcfg-eth0 file in RPM based systems.

[root@linuxhelp Desktop]# vi /etc/sysconfig/network-scripts/ifcfg-eno16777736

TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777736
UUID=ed83592b-49f0-4bed-b548-f8b824f92c0b
ONBOOT=no
HWADDR=00:0C:29:D6:7E:93
IPADDR0=192.168.5.225
PREFIX0=24
GATEWAY0=192.168.5.1
DNS1=192.168.5.221
~     
" /etc/sysconfig/network-scripts/ifcfg-eno16777736"  18L, 338C


Finally verify the cache server using some tools, here we use dig & nslookup commands in Linux systems and in windows you can use the nslookup command.
Now we query google.co.in for first time, so it will cache its query.

[root@linuxhelp Desktop]# dig google.co.in

  < < > >  DiG 9.9.4-RedHat-9.9.4-14.el7 < < > >  google.co.in
   global options: +cmd
   Got answer:
   -> > HEADER< < - opcode: QUERY, status: NOERROR, id: 63485
   flags: qr rd ra  QUERY: 1, ANSWER: 1, AUTHORITY: 3, ADDITIONAL: 4

   OPT PSEUDOSECTION:
  EDNS: version: 0, flags:  udp: 4096
   QUESTION SECTION:
 google.co.in.            IN    A

   ANSWER SECTION:
google.co.in.        295    IN    A    216.58.197.67

   AUTHORITY SECTION:
google.co.in.        86393    IN    NS    ns1.google.com.
google.co.in.        86393    IN    NS    ns3.google.com.
google.co.in.        86393    IN    NS    ns2.google.com.

   ADDITIONAL SECTION:
ns3.google.com.        172793    IN    A    216.239.36.10
ns2.google.com.        172793    IN    A    216.239.34.10
ns1.google.com.        172793    IN    A    216.239.32.10

   Query time: 303 msec
   SERVER: 192.168.5.221#53(192.168.5.221)
   WHEN: Tue Apr 26 14:52:39 IST 2016
   MSG SIZE  rcvd: 169


For more info about dig command: https://www.linuxhelp.com/dig-command-query-dns/

Use nslookup command in order to confirm the same.

[root@linuxhelp Desktop]# nslookup google.co.in
Server:        192.168.5.221
Address:    192.168.5.221#53

Non-authoritative answer:
Name:    google.co.in
Address: 216.58.197.67


For more info about nslookup command: https://www.linuxhelp.com/troubleshoot-dns-using-nslookup/

Tags:
jacob
Author: 

Comments ( 0 )

No comments available

Add a comment

Frequently asked questions ( 5 )

Q

Is DNS support IPv6?

A

DNS Made Easy has full IPv6 support. our name servers and we also support the addition of AAAA records within our web interface.

Q

Can PfSense be used as full fledged DNS server ?

A

Yes of course. pfSense includes two different DNS daemons, and you can install Bind as a package

Q

Which command can I use to achieve the cache DNS?

A

You can dump the BIND DNS cache to a file with the command:
Syntax: "rndc dumpdb -cache"

Q

What is the configuration file of DNS?

A

When configure DNS to do that open and edit named.conf file
/etc/named.conf

Q

It is possible to change the Port number of DNS?

A

Yes, You can change the port number in this configuration file
/etc/named.conf

Related Tutorials in How to setup cache only DNS server using Bind in CentOS 7

Related Tutorials in How to setup cache only DNS server using Bind in CentOS 7

How to install and configure Bind DNS on Webmin
How to install and configure Bind DNS on Webmin
Jan 5, 2018
How to Block a Domain in Bind DNS Server on CentOS
How to Block a Domain in Bind DNS Server on CentOS
Sep 26, 2017
How to Block a domain using RPZ on Bind DNS server on CentOS
How to Block a domain using RPZ on Bind DNS server on CentOS
Sep 28, 2017
How to install and configure bind as an Authoritative Name Server on Centos
How to install and configure bind as an Authoritative Name Server on Centos
Jun 11, 2018
How to setup cache only DNS server using Bind in CentOS 7
How to setup cache only DNS server using Bind in CentOS 7
May 7, 2016
How to configure bind with rndc on centos 6
How to configure bind with rndc on centos 6
Jun 4, 2018
How to Create bind-mounts On CentOS 7.6
How to Create bind-mounts On CentOS 7.6
Jan 7, 2020
How to create a bind-mount on Rocky Linux 9.3
How to create a bind-mount on Rocky Linux 9.3
May 10, 2024

Related Forums in How to setup cache only DNS server using Bind in CentOS 7

Related Forums in How to setup cache only DNS server using Bind in CentOS 7

Bind
issacjoseph class=
How to check bind configuration
Feb 4, 2018
Bind
ismail class=
How to block particular websites in linux bind DNS
Sep 26, 2017
Bind
obisesanbabajide class=
BIND 9.10 ON UBUNTU SERVER 16.4 NOT ABLE TO ACCESS THE INTERNET
Jul 19, 2019
Bind
keeljohnston class=
How to check bind Reverse Zone configuration
Mar 5, 2018
CentOS
adhitiroy class=
zone 7.168.192.in-addr.arpa: already exists
Mar 12, 2018
Linux
benjamin class=
what is the difference between * and 0.0.0.0 for bind-address in mysql server
May 6, 2017
CentOS
raven class=
Bind restart failed
Feb 15, 2018
CentOS
baseer class=
Bind : How to verify zone files
Feb 17, 2018
Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Ryan ?
how to use visual traceroute tool

Am using traceroute command to check for the route. i got this tool while surfing. So pls help me out installation and usage of Visual traceroute tool.

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.