Setting up your own DNS server on Ubuntu

Setting up a master server

This blog was written in a hurry and I apologize for typos and grammatical errors. Firstly you have to install a package called bind9, which is most widely used DNS software on the internet

$ sudo apt-get install bind9

Configure the DNS to cache requests and forward unknown requests to other DNS servers

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

Add this line to the same

zone "am" {
     type master;
     file "/etc/bind/db.am";
     notify no;
};

Now use an existing zone file as a template:

sudo cp /etc/bind/db.local /etc/bind/db.am

Make it to look something like this:

;
; BIND data file for local loopback interface
;
$TTL    604800
@       IN      SOA     ns.am. root.am. (
                             10         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL

@       IN      NS      ns.am.
ns      IN      A       10.30.10.90
@       IN      MX      9 mail.am.
;@       IN      A       127.0.0.1
;@       IN      AAAA    ::1
cs      IN      A       10.30.11.55
wna     IN      A       10.30.9.46

After saving the am.db file, restart the bind server

$ sudo /etc/init.d/bind9 restart

Now, lets move to client machine.
Edit /etc/resolv.conf file to change the nameserver IP to that of the master DNS server.

# 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 10.30.11.55

Restart the network

$ sudo /etc/init.d/networking restart

That’s it! Now we will be able to ping to cs.am and wna.am servers.

(We used different machines when we did it in lab and when we were writing this blog – hence IP differs!)

assignment

Setting up a secondary server

In case if the primary server fails, we would need a slave server as back up.
Edit /etc/bind/named.conf.local in the primary master as follows:

zone "am" {
             type master;
             file "/etc/bind/db.am";
             allow-transfer { 10.30.10.90; };
        };

We gave cs.am as the secondary server

In the cs.am, we need to install bind9 package and then edit the /etc/bind/named.conf.local file in-order to make it as a secondary server.

zone "am"{
               type slave;  
               file "/var/cache/bind/db.am";  
               masters { 10.30.11.55; }; 
      };

You may need to restart the bind server to take the effect in secondary server. In-order to check the secondary server, you can shut down the bind9 sevrer and ping to cs.am for any echo replies.

In the client machines, we need to make changes in /etc/resolv of the client machines as follows to apply the effects of secondary server that we have just added now:

# 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 10.30.11.55
nameserver 10.30.10.90

In-order to add an IP address of a stable DNS server to a named.conf.options file. This IP address is used when a local DNS server do not know to answer a name resolution query.
You can add these lines to /etc/bind/named.local.options

forwarders {
              8.8.8.8;
        };

Reference:
[1] https://help.ubuntu.com/community/BIND9ServerHowto

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s