AMP AMP

How to configure Caching DNS Server in Ubuntu

To configure Caching DNS Server in Ubuntu

Domain Name System is a naming device that maps the IP addresses and fully qualified domain names to one another. The Internet maintains two main namespaces - the domain name format and the Internet Protocol (IP) address format. The DNS controls the domain name hierarchy and helps in transforming the name server and IP address. The server that caches the DNS entries for a domain is called as DNS name server. The default port number for DNS is 53. This article explains the installation and configuration of DNS Server .

1. Installation of DNS Server

DNS server information:
IP Address: 192.168.5.230
Hostname: dns.linuxhelpedu.com
Install the DNS bind Packages by executing the below command.

root@dns:~# apt-get install bind9*
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting ' bind9-host'  for glob ' bind9*' 
.
.
.
wrote key file " /etc/bind/rndc.key" 
Setting up bind9-doc (1:9.10.3.dfsg.P4-8ubuntu1) ...
Setting up bind9-dyndb-ldap (8.0-4) ...
Processing triggers for libc-bin (2.23-0ubuntu3) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (229-4ubuntu4) ...
Processing triggers for ufw (0.35-0ubuntu2) ...

Now the installation of bind packages is successfully completed.

2. DNS Cache Server Setup

Using nano editor, go to the directory ' /etc/bind' and edit the file ' named.conf.options' .

root@dns:~# nano /etc/bind/named.conf.options

Remove ' //' in front of forwarders tag and replace 0.0.0.0 to 8.8.8.8 as shown below.

forwarders {
    8.8.8.8 
     } 

Save and quit the file.
After editing, restart bind service to apply the changes.

root@dns:~# service bind9 restart

3. Master DNS Server Setup

Open /etc/bind/named.conf file using nano editor.

root@dns:~# nano /etc/bind/named.conf

The configuration file must contains following lines. If it is not available then type it inside the configuration file.

Include “ /etc/bind/named.conf.option”  
Include “ /etc/bind/named.conf.local”  
Include “ /etc/bind/named.conf.default-zones”  

And then save and quit the file.
Next go to the configuration file inside ' /etc/bind' .

root@dns:~# nano /etc/bind/named.conf.local

And then declare the forward and reverse zone file and its path as follows.

zone " linuxhelpedu.com"  {
    type master 
    file " /etc/bind/forward.linuxhelpedu"  
    allow-transfer { 192.168.5.230  } 
    also-notify { 192.168.5.230  } 
    } 
zone " 5.168.192.in-addr.arpa"  {
    type master 
    file " /etc/bind/reverse.linuxhelpedu"  
    allow-transfer { 192.168.5.230  } 
    also-notify { 192.168.5.230  } 
    } 


Inside ' /etc/bind/' directory create forward zone file.

root@dns:~# nano /etc/bind/forward.linuxhelpedu

Type the following configuration inside the forward zone file.

$TTL    86400
@    IN    SOA    dns.linuxhelpedu.com. root.linuxhelpedu.com. (
            2011071002      Serial
            3600          Refresh
            1800          Retry
            604800      Expire
            86400           Minimum TTL
)
@    IN    NS    dns.linuxhelpedu.com.
@    IN    A    192.168.5.230
@    IN    A    192.168.5.233
dns    IN    A    192.168.5.230
client    IN    A    192.168.5.233


In the same way, inside ' /etc/bind/' directory create reverse zone file .

root@dns:~# nano /etc/bind/reverse.linuxhelpedu

Type the following configuration inside the reverse zone file.

$TTL    86400
@    IN    SOA    dns.linuxhelpedu.com. root.linuxhelpedu.com. (
            2011071002      Serial
            3600          Refresh
            1800          Retry
            604800      Expire
            86400           Minimum TTL
)
@    IN    NS    dns.linuxhelpedu.com.
@    IN    PTR    linuxhelpedu.com.
dns    IN    A    192.168.5.230
client    IN    A    192.168.5.233
230    IN    PTR    dns.linuxhelpedu.com.
233    IN    PTR    client.linuxhelpedu.com.

Syntax validation

Check ' named.conf' and ' named.conf.local' file for any syntax error.

root@dns:~# named-checkconf /etc/bind/named.conf
root@dns:~# named-checkconf /etc/bind/named.conf.local

And then check forward zone and reverse zone by executing the following command.

root@dns:~# named-checkzone linuxhelpedu.com /etc/bind/forward.linuxhelpedu
zone linuxhelpedu.com/IN: loaded serial 2011071002
OK
root@dns:~# named-checkzone linuxhelpedu.com /etc/bind/reverse.linuxhelpedu
zone linuxhelpedu.com/IN: loaded serial 2011071002
OK

Restart the ' bind' service by executing the following command.

root@dns:~# service bind9 restart

Configuring network interface

Go to the ' /etc/network/' path, and edit the ' interface' configuration file.

root@dns:~# nano /etc/network/interfaces

Add ' dns-nameserver' and ' dns-search' as follows.

auto ens33
iface ens33 inet static
    address 192.168.5.230
    netmask 255.255.255.0
    network 192.168.5.0
    broadcast 192.168.5.255
    gateway 192.168.5.1
    dns-nameservers 192.168.5.230
    dns-search linuxhelpedu.com

Then save and quit the file. Restart the network service.

Test DNS server

After rebooting, test the dns server using ' dig’ and ' nslookup' command.

root@dns:~# dig dns.linuxhelpedu.com
  < < > >  DiG 9.10.3-P4-Ubuntu < < > >  dns.linuxhelpedu.com
   global options: +cmd
   Got answer:
   -> > HEADER< < -opcode: QUERY, status: NOERROR, id: 32897
   flags: qr aa rd ra  QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1

   OPT PSEUDOSECTION:
  EDNS: version: 0, flags:  udp: 4096
   QUESTION SECTION:
 dns.linuxhelpedu.com.        IN    A

   ANSWER SECTION:
dns.linuxhelpedu.com.    86400    IN    A    192.168.5.230

   AUTHORITY SECTION:
linuxhelpedu.com.    86400    IN    NS    dns.linuxhelpedu.com.

   Query time: 0 msec
   SERVER: 192.168.5.230#53(192.168.5.230)
   WHEN: Fri Apr 29 15:21:37 IST 2016
   MSG SIZE  rcvd: 79

root@dns:~# nslookup dns.linuxhelpedu.com
Server:        192.168.5.230
Address:    192.168.5.230#53

Name:    dns.linuxhelpedu.com
Address: 192.168.5.230

root@dns:~#

Now we have configured and tested the Server side DNS.


For further information about the ' dig’ command visit,
https://www.linuxhelp.com/dig-command-query-dns/
For further information about the ' nslookup' command visit,
https://www.linuxhelp.com/troubleshoot-dns-using-nslookup/

4. Client Machine Setup

Set ' nameserver' and ' search' .
Nameserver is dns server ip
Search is dns server host name.
To check ' hostname' , run the following command.

user1@client:~$ hostname
client.linuxhelpedu.com.

Edit ' /etc/resolv.conf' file using nano editor.

user1@client:~$ nano /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 192.168.5.230
search linuxhelpedu.com

Restart network service or reboot client system to apply the changes.

Test Dns server in client machine

Test dns server from client machine using ' dig' and ' nslookup' .

user1@client:~$ dig dns.linuxhelpedu.com

  < < > >  DiG 9.10.3-P4-Ubuntu < < > >  dns.linuxhelpedu.com
   global options: +cmd
   Got answer:
   -> > HEADER< < -opcode: QUERY, status: NOERROR, id: 42737
   flags: qr aa rd ra  QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1

   OPT PSEUDOSECTION:
  EDNS: version: 0, flags:  udp: 4096
   QUESTION SECTION:
 dns.linuxhelpedu.com.        IN    A

   ANSWER SECTION:
dns.linuxhelpedu.com.    86400    IN    A    192.168.5.230

   AUTHORITY SECTION:
linuxhelpedu.com.    86400    IN    NS    dns.linuxhelpedu.com.

   Query time: 1066 msec
   SERVER: 192.168.5.230#53(192.168.5.230)
   WHEN: Sat Apr 30 14:12:59 IST 2016
   MSG SIZE  rcvd: 79

user1@client:~$ nslookup dns.linuxhelpedu.com
Server:        192.168.5.230
Address:    192.168.5.230#53

Name:    dns.linuxhelpedu.com
Address: 192.168.5.230
Tag : Cache
Comment
Hassan0711
Apr 24 2023
Very helpfull. Thank you.
Add a comment
FAQ
Q
What exactly is DNS Caching?
A
DNS cache is just a memory of recent DNS lookups that your computer can quickly refer to when it's trying to figure out how to load a website.
Q
How to check the created domain in DNS is getting resolved or not?
A
Make use of "dig" command. For more info regarding dig follow "https://www.linuxhelp.com/dig-command-query-dns/".
Q
In comparison with Bind and Power DNS? Which one is more efficient?
A
Both the DNS are almost the same in properties except with the "views" concept, on Bind, it is more flexible than in Power DNS.
Q
How to have a separate mail domain and where to create the same in DNS?
A
Add MX record in your named.conf file and also add "mail.yourdomainname" in NameServer configuration file.
Q
Where you exactly provide cache time for DNS?
A
Under each zone configuration, a value for expiring is given.