Table of Contents

Installing BIND

Hosting your own DNS (nameserver) is really simple and take just a few minutes before you are up and running. There are only 5 files that need configuration in order for your DNS to be opeational, and the whole process is rather intuitive.

To begin, you must first install the server application itself. Because BIND (Berkeley Internet Name Daemon) is the most * commonly used nameserver by far, we will be using that one here. The following command will install version 9, which is the latest.

apt-get install bind9 dnsutils

Configure BIND

Now for the fun part. There are several files that need at least minimal configuration:

file Purpose
named.conf.local To tell your DNS what your domain is, and where to find its zone file
named.conf.options To specify a stable IP that can take over if yours fails.
resolv.conf To specify the IP address of your nameserver
zone file Where to point your domain and subdomains to their servers
reverse DNS zone file This does the opposite of the zone file

named.conf.local

Configuration of your Bind server occurs in the named.conf.local file. That is where you will add your zones. You may edit the file using your favorite editor, for example if you use nano, simply type:

nano /etc/bind/named.conf.local

Then, to add a zone to your server, add the following (replace both instances of "whack-a-mole.eu" with the zone that you want to serve:

zone "whack-a-mole.eu" {
      type master;
      file "/etc/bind/zones/whack-a-mole.eu.db";
      };

You will also want to create a reverse DNS definition. Do this by adding the following (replace 190.70.217 with your own local network IP in reverse):

zone "190.70.217.in-addr.arpa" {
   type master;
   file "/etc/bind/zones/rev.190.70.217.in-addr.arpa";
};

named.conf.options

Be sure to edit the named.conf.options file:

nano /etc/bind/named.conf.options

Just change the forwarder to point to a secondary nameserver. For example Gandi's ns6.gandi.net (217.70.177.40). You can use the following code as an example:

options {
      directory "/var/cache/bind";
query-source address * port 53;
forwarders {
217.70.177.40;
};

      auth-nxdomain no;    # conform to RFC1035
      listen-on-v6 { any; };
};

resolv.conf

You will want to edit the resolv.conf file, and tell it the IP address of your name server. Note that it is not found in the bind folder with your other files, but in the /etc directory. To edit it, type:

nano /etc/resolv.conf  

Simply add the following, being sure to replace "whack-a-mole.eu" with your domain, and replace "217.70.190.17" with IP address of your nameserver (don't know what it is?). Anything after the first nameserver are secondary nameservers. In the below example I am using Gandi's ns6.gandi.net nameserver as a secondary nameserver.

search whack-a-mole.eu
nameserver 217.70.190.17
nameserver 217.70.177.40

zone files

The files that contain the records where you point your domain name to your hosting server, or your mail server are called the 'zone files' or the 'zone definition files'. The content of these corresponds to what you use when you edit your zone file on Gandi's interface (more) when using Gandi's default DNS.

1. Begin by making the zones directory: This is the folder that will hold all your zone files.

mkdir /etc/bind/zones

2. Make the zone files for your domains

You will now need to create your zone file where the addresses and machine names that your DNS server will use (in the following example, replace whack-a-mole.eu with your domain). Use the following command to create the file (replace whack-a-mole.eu with your domain):

nano /etc/bind/zones/whack-a-mole.eu.db

Here is a sample zone file:

whack-a-mole.eu.  IN   SOA   boom.whack-a-mole.eu. admin.whack-a-mole.eu. (

2006081401
28800
3600
604800
38400
)
  
whack-a-mole.eu. IN NS boom.whack-a-mole.eu.

whack-a-mole.eu. 10800 IN MX 10 spool.mail.gandi.net.
whack-a-mole.eu. 10800 IN MX 50 fb.mail.gandi.net.
pop 10800 IN CNAME access.mail.gandi.net.
imap 10800 IN CNAME access.mail.gandi.net.
smtp 10800 IN CNAME relay.mail.gandi.net.
webmail 10800 IN CNAME agent.mail.gandi.net.

www IN A 217.70.190.20
mta IN A 217.70.190.17
boom IN A 217.70.190.17

(you will obviously replace the values with your own. Here we are showing a zone using Gandi's mail servers and configured for GandiMail, and our own HTTP servers).

Note:

As you can see, the second half of this zone file resembles the 'expert interface' in Gandi's DNS management page. This is because it is the same thing! You would therefore enter the same commands in your zone file, as you would if you were entering them in your Gandi DNS zone file.

Reverse DNS zone files

Begin my making your file (replace 190.70.217 with your network address backwards).

nano /etc/bind/zones/rev.190.70.217.in-addr.arpa

Then create the following code, replacing:

@ IN SOA whack-a-mole.eu. admin.whack-a-mole.eu. (
                      2006081401;
                      28800;
                      604800;
                      604800;
                      86400);

                     IN    NS     boom.whack-a-mole.eu.
17                   IN    PTR    whack-a-mole.eu.

Restart

Once you have configured your DNS server, you must restart it:

/etc/init.d/bind9 restart

If everything works, you will see the following:

Stopping domain name service... bind                                         [ OK ]
Starting domain name service... bind                                         [ OK ]