So now that I have my web servers all setup and working I need a way to be able to define URI’s internally (such as FTP, SSH etc) I also wanted to be able to access these sites internally and my modem will not allow hairpin routing so I needed something to direct me to the correct location inside the network. So I needed to setup a DNS server with the correct entries.

First things first is install BIND.

sudo apt-get install bind9

Now that BIND9 is installed the first thing to do is to setup the forwarders. These are the addresses that  we will send any requests that are not defined. i.e. if you dont host www.google.com it will forward that request onto these servers to get the correct IP. So we edit

vi /etc/bind/named.conf.options

And add or modify the following

forwarders {
        8.8.8.8;
        8.8.4.4;
};

After the forwarders are setup, we are going to create a folder for the Zone records. A zone is domain that the server will look after. (For example nbird.com.au) all of the entries related to that domain are grouped together in a zone file.

sudo mkdir /etc/bind/zones

Now we setup the Zone file for the domain in my case I am setting up nbird.com.au so I will create a zone file called db.nbird.com.au

sudo vi /etc/bind/zones/db.nbird.com.au.db

Inside that file I will add the following.

; BIND data file for nbird.com.au
;
$TTL    604800
@       IN      SOA     ns1.nbird.com.au. root.localhost. (
                              2         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      ns1.nbird.com.au.
@       IN      A       192.168.0.254
@       IN      AAAA    fe80::20c:29ff:fe50:a7a6
nbird.com.au    IN      NS      ns1.nbird.com.au.
nbird.com.au    IN      A       192.168.0.254
accounts        IN      A       192.168.0.254
www     IN      CNAME   nbird.com.au.
dea     IN      CNAME   nbird.com.au.
ns1     IN      A       192.168.0.254

To get started you can copy the existing local zone file and then modify it do this run

sudo cp /etc/bind.db.local /etc/bind/zones/db.nbird.com.au

The SOA part is quite a thing to wrap your head around. For more information about what is in the file check out http://support.microsoft.com/kb/163971. After the SOA there is just a single line for each record or sub domain. (In the example above you can see the records for the domain @, accounts, www, dea and ns1)

Now that you have a zone file ready for the domain you need to add it into the named.conf.local

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

Once you are into the file add the following to the file

zone "nbird.com.au" in{
 type master;
 file "/etc/bind/zones/db.nbird.com.au";
 };

After that is done you can restart bind

sudo service bind9 restart

and then point a DNS client to the server and try to resolve the addresses.

dean@remote:~$ dig nbird.com.au

; <<>> DiG 9.8.1-P1 <<>> nbird.com.au
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 8185
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1

;; QUESTION SECTION:
;nbird.com.au.                  IN      A

;; ANSWER SECTION:
nbird.com.au.           604800  IN      A       192.168.0.254

;; AUTHORITY SECTION:
nbird.com.au.           604800  IN      NS      ns1.nbird.com.au.

;; ADDITIONAL SECTION:
ns1.nbird.com.au.       604800  IN      A       192.168.0.254

;; Query time: 1 msec
;; SERVER: 192.168.0.254#53(192.168.0.254)
;; WHEN: Sat May  3 08:21:46 2014
;; MSG SIZE  rcvd: 80

Now you can add the other domains you want to add by repeating the process and pointing other URI’s to different locations around your network.