How-To: Setting up a DNS zone with Bind9

Bind is a well known Unix name server, it is a powerfull piece of software which is used by the majority of nameservers.
This article will go though setting up a local area network that can be used at home or inside a small company.

In this article, we suppose that we are going to set a DNS zone for the domain: debuntu.foo, this is a fictionnal zone which is going to be used as a local network domain such as an intranet.

The name server is not accessible from the outside and only has 1 private LAN adress network interface.

All other computer in the LAN are going to use 192.168.1.5 as a nameserver, this can be set manually by setting statically:

nameserver 192.168.1.5

in their /etc/resolv.conf files, or via a DHCP server (beyond the scope of this article).

In the end, the nameserver is going to provide name resolution as well as reverse name resolution for our local network. For the rest of the domain name, it will query other DNS server and cache the result, behaving as a resolving, caching name server.

In the first part we are going to deal with name resolution and then in the second part, we are going to set up the reverse name resolution.

Requirements:

This how-to has been made using bind9, first of all, you need to install this package:

sudo apt-get install bind9

Now, we are going to set up debuntu.foo domain name. 

Setting up Domain name resolution:

edit the local configuration file:

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

and at the following entry:

 zone "debuntu.foo" {
        type master;
        file "debuntu.foo.db";
        notify no;
};

As I don't use any slave server in that example, I turn the value of notify to no. 

What we say here, is that we are the master server for debuntu.foo, and the configuration file of that zone will be located at: /var/cache/bind/debuntu.foo.db.

Notice: the directory value (/var/cache/bind/) might vary depending on your distribution. Check its value in  /etc/bind/named.conf.options .On a Ubuntu Dapper, the default value is:

 options {
        directory "/var/cache/bind";
....
....

Now, we are going to fill up the required values to define the domain debuntu.foo.

 Create and edit /var/cache/bind/debuntu.foo.db, and add:

;
; Zone file for debuntu.foo
;
; The full zone file
;
$TTL 3D
@       IN      SOA     ns.debuntu.foo. chantra.debuntu.foo. (
                        200608081       ; serial, todays date + todays serial #
                        8H              ; refresh, seconds
                        2H              ; retry, seconds
                        4W              ; expire, seconds
                        1D )            ; minimum, seconds
;
                NS      ns              ; Inet Address of name server
                MX      10 mail         ; Primary Mail Exchanger
                MX      20 mail2        ; Secondary Mail Exchanger
;
ns              A       192.168.1.5
www             CNAME   www.debuntu.org.
ftp             CNAME   ns
gw              A       192.168.1.1
                TXT     "Network gateway"
mail            A       192.168.1.2
mail2           CNAME   otherbox
otherbox         A      192.168.1.3
                TXT     "Otherbox"

In this file, we define:

  1. the adress of the name server; 192.168.1.5,
  2.  an alias from www.debuntu.foo to www.debuntu.org,
    (mind the dot "." at the end of an external name),
  3. another alias from ftp.debuntu.foo to ns.debuntu.foo,
  4. An adresse for the local network gateway with a description
  5. ...

 From now on, any machine from your local network, using this name server, will be able to access the others using the domain names we defined above instead of IP adresses.

How-To: Setting up a DNS zone with Bind9 -- page 2

Setting up Reverse Name Resolution:

In order to be able to get the name of the machine located at IP 192.168.1.X, we need to set up a reverse name zone which is going to be call, in this example 1.168.192.in-addr.arpa,

edit /etc/bind/named.conf.local and add:

 zone "1.168.192.in-addr.arpa" {
        type master;
        notify no;
        file "reverse/192.168.1";
};

This time, wa are going to write the information for reverse dns in a specific directory ("reverse"). Create that directory and edit the zone file:

mkdir /var/cache/bind/reverse
vi  /var/cache/bind/reverse/192.168.1

and copy the following lines: 

 $TTL 3D
@       IN      SOA     ns.debuntu.foo. chantra.debuntu.foo (
                        200608051 ; Serial, todays date + todays serial
                        8H      ; Refresh
                        2H      ; Retry
                        4W      ; Expire
                        1D)     ; Minimum TTL
                NS      ns.debuntu.foo

1               PTR     gw.debuntu.foo.
2               PTR     mail.debuntu.foo.
3               PTR     otherbox.debuntu.foo.
5               PTR     ns.debuntu.foo.

now, doing a nslookup on 192.168.1.2 will return mail.debuntu.foo.