Configure DNS Server on Ubuntu

The Domain Name System (DNS) is a hierarchical distributed naming system for computers connected over network. It resolves ip address correspondence to a domain name. There are four type of dns servers .
This article will help you to configure dns server (Domain Name System) using bindpackages on Ubuntu, Debian and LinuxMint systems. Bind is also known as named service. Most of web hosting providers already provide dns server for their clients but if you want to set up your own dns server (Domain name system) go through this article.

If you are CentOS or Redhat user visit this article to set up DNS server.

Install DNS Packages

Bind9 is the most popular dns server used world-wide. It is available under default apt-get repositories. So use following commands to install Bind9 domain name system.

$ sudo apt-get update
$ sudo apt-get install bind9

Create Forward Zone File

As we are using temporary domain named demotecadmin.net. Create a forward dns zone file under /etc/bind directory.

$ sudo vi /etc/bind/demotecadmin.net.zone

and add following content

; Forward Zone file for demotecadmin.net
$TTL 14400
@      86400    IN      SOA     ns1.tecadmin.net. webmaster.tecadmin.net. (
                3013040200      ; serial, todays date+todays
                86400           ; refresh, seconds
                7200            ; retry, seconds
                3600000         ; expire, seconds
                86400          ; minimum, seconds
      )
demotecadmin.net.   86400  IN NS ns1.tecadmin.net.
demotecadmin.net.   86400  IN NS ns2.tecadmin.net.
demotecadmin.net.   IN   A     192.168.0.100
demotecadmin.net.   IN   MX  0 mail.demotecadmin.net.
mail 		    IN   A     192.168.0.200
www 		    IN   CNAME demotecadmin.net.

Create Reverse Zone File

If required, configure rDNS zone also for your ip address and domain names to resolve reverse dns. For example we are using 192.168.0.0/32 ip range in our intranet. Create reverse dns file /etc/bind/db.0.168.192 with following content.

$ sudo vi /etc/bind/db.0.168.192

and add following content

; BIND reverse data file for local loopback interface
;
$TTL    604800
@ IN SOA ns1.tecadmin.net. root.ns1.tecadmin.net. (
                     3013040200         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      ns1.tecadmin.net.

100     IN      PTR     demotecadmin.net.
101	IN 	PTR	otherdomain.com.

Add Zone Entry in Main Configuration

Now edit bind configuration file (/etc/bind/named.conf.local) and add the forward and reverse zone entries there like below.

$ sudo vi /etc/bind/named.conf.local

Append following content

zone "demotecadmin.net" IN {
        type master;
        file "/etc/bind/demotecadmin.net.zone";
};

zone "0.168.192.in-addr.arpa" {
        type master;
        file "/etc/bind/db.0.168.192";
};

Verify Configuration Files

After making all configuration, verify all files using following commands.

$ named-checkzone demotecadmin.net /etc/bind/demotecadmin.net.zone
$ named-checkzone 192.168.0.0/32 /etc/bind/db.0.168.192
$ named-checkconf  /etc/bind/named.conf.local
$ named-checkconf  /etc/bind/named.conf

If any of above commands returns any error or warning, Please fix that before proceeding to next step.

Restart DNS

After successfully verification of all files, let’s restart bind9 service.

$ sudo service bind9 restart

Test Setup

Finally your dns server is successfully configured and ready to use. Make sure your client system is using your dns server as default dns server. Let’s verify that DNS is properly responding on queries. Below is example commands to test it.

Verify Forward Zone:

$ dig demotecadmin.net


; <<>> DiG 9.9.5-3ubuntu0.5-Ubuntu <<>> demotecadmin.net
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 58754
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;demotecadmin.net.		IN	A

;; ANSWER SECTION:
demotecadmin.net.	14400	IN	A	192.168.0.100

;; AUTHORITY SECTION:
demotecadmin.net.	86400	IN	NS	ns1.tecadmin.net.
demotecadmin.net.	86400	IN	NS	ns2.tecadmin.net.

;; Query time: 0 msec
;; SERVER: 192.168.0.60#53(192.168.0.60)
;; WHEN: Thu Oct 08 10:33:17 IST 2015
;; MSG SIZE  rcvd: 106

Verify Reverse Zone:

$ dig -x 192.168.0.100

; <<>> DiG 9.9.5-3ubuntu0.5-Ubuntu <<>> -x 192.168.0.100
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 1132
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;100.0.168.192.in-addr.arpa.	IN	PTR

;; ANSWER SECTION:
100.0.168.192.in-addr.arpa. 604800 IN	PTR	demotecadmin.net.

;; AUTHORITY SECTION:
0.168.192.in-addr.arpa.	604800	IN	NS	ns1.tecadmin.net.

;; Query time: 0 msec
;; SERVER: 192.168.0.60#53(192.168.0.60)
;; WHEN: Thu Oct 08 10:34:06 IST 2015
;; MSG SIZE  rcvd: 112