To install the server simply install the bind9 package. A very useful package for testing and troubleshooting DNS issues is the dnsutils package. Also, the BIND9 Documentation can be found in the bind9-doc package.
$ sudo aptitude install bind9 dnsutils bind9-doc
BIND9 can provide many different DNS services. Some of the most useful setups are:
Caching Server
In this configuration BIND9 will find the answer to name queries and remember the answer for the next query. This can be useful for a slow internet connection. By caching DNS queries, you will reduce bandwidth and (more importantly) latency.
Primary Master Server
BIND9 can be used to serve DNS records (groups of records are referred to as zones) for a registered domain name or an imaginary one (but only if used on a restricted network).
Secondary Master Server
A secondary master DNS server is used to complement a primary master DNS server by serving a copy of the zone(s) configured on the primary server. Secondary servers are recommended in larger setups. If you intend to serve a registered domain name they ensure that your DNS zone is still available even if your primary server is not online.
Hybrids
You can even configure BIND9 to be a Caching and Primary Master DNS server simultaneously, a Caching and a Secondary Master server or even a Caching, Primary Master and Secondary Master server. All that is required is simply combining the different configuration examples.
Stealth Servers
There are also two other common DNS server setups (used when working with zones for registered domain names), Stealth Primary and Stealth Secondary. These are effectively the same as Primary and Secondary DNS servers, but with a slight organizational difference.
For example, you have 3 DNS servers; A, B and C.
A is the Primary, B and C are secondaries.
If you configure your registered domain to use A and B as your domain's DNS servers, then C is a Stealth Secondary. It's still a secondary, but it's not going to be asked about the zone you are serving to the internet from A and B
If you configure your registered domain to use B and C as your domain's DNS servers, then A is a stealth primary. Any additional records or edits to the zone are done on A, but computers on the internet will only ever ask B and C about the zone.
Address Records
The most commonly used type of record. This record maps an IP Address to a hostname.
www IN A 1.2.3.4
Alias Records
Used to create an alias from an existing A record. You cannot create a CNAME record pointing to another CNAME record.
mail IN CNAME www
www IN A 1.2.3.4
Mail Exchange Records
Used to define where email should be sent to. Must point to an A record, not a CNAME.
IN MX mail.example.com.
[...]
mail IN A 1.2.3.4
Name Server Records
Used to define which servers serve copies of this zone. It must point to an A record, not a CNAME. This is where Primary and Secondary servers are defined. Stealth servers are intentionally omitted.
IN NS ns.example.com.
[...]
ns IN A 1.2.3.4
To add a DNS zone to BIND9, turning BIND9 into a Primary Master server, all you have to do is edit named.conf.zone:
zone "example.com" {
type master;
file "/etc/bind/example.com";
};
Edit the new zone file /etc/bind/example.com change localhost. to the FQDN of your server, leaving the additional "." at the end.
$TTL 604800
@ IN SOA ns.example.com. hostmaster.example.com. (
1 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
IN NS ns.example.com.
@ IN A 192.168.1.10
box IN A 192.168.1.10
You must increment the serial number every time you make changes to the zone file. If you make multiple changes before restarting BIND9, simply increment the serial once. Now, you can add DNS records to the bottom of the zone.
Tip: Many people like to use the last date edited as the serial of a zone, such as 2005010100 which is yyyymmddss (where s is serial)
Once you've made a change to the zone file BIND9 will need to be restarted for the changes to take affect:
$ sudo /etc/init.d/bind9 restart
Now that the zone file is setup and resolving names to IP Adresses a Reverse zone is also required. A Reverse zone allows DNS to convert from an address to a name. Edit /etc/bind/named.conf.zone and add the following:
zone "1.168.192.in-addr.arpa" {
type master;
file "/etc/bind/1.168.192.in-addr.arpa";
};
Next edit /etc/bind/1.168.192.in-addr.arpa changing the basically the same options as in /etc/bind/example.com:
$TTL 604800
@ IN SOA ns.example.com. root.example.com. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns.
10 IN PTR ns.example.com.
The serial number in the reverse zone needs to be incremented on each changes as well. For each A record you configure in /etc/bind/example.com you need to create a PTR record in /etc/bind/1.168.192.in-addr.arpa. After creating the reverse zone file restart bind9:
$ sudo /etc/init.d/bind9 restart
Check Configuration
$ named-checkconf -z /etc/bind/named.conf
Check Zone
$ named-checkzone ZONENAME FILENAME
ZONENAME - smartonline.com
FILENAME - /etc/bind/smartonline.com
Check DNS
$ host FQDN.ADDRESS [SERVER_IP]
$ nslookup FQDN.ADDRESS [SERVER_IP]
$ dig [@SERVER_IP] FQDN.ADDRESS
Check reverse DNS
$ host IP.ADDRESS
$ nslookup IP.ADDRESS [SERVER_IP]
$ dig [@SERVER_IP] -x IP.ADDRESS