How-To: Setting up a DNS zone with Bind9

2 minute read

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.

1. 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.

2. 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

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. On the second part of this tutorial, we will set up reverse name resolution.