How to install BIND on Ubuntu

Introduction

DNS Stands for Domain Name Service.On the Internet, the Domain Name Service (DNS) stores and associates many types of information with domain names; most importantly, it translates domain names (computer hostnames) to IP addresses. It also lists mail exchange servers accepting e-mail for each domain. In providing a worldwide keyword-based redirection service, DNS is an essential component of contemporary Internet use.

BIND (Berkeley Internet Name Domain) is an open reference implementation of the Domain Name System (DNS) protocol and provides a redistributable implementation of the major components of the Domain Name System.

  • a name server (named)
  • a resolver library
  • troubleshooting tools like nslookup and dig

The BIND DNS Server is used on the vast majority of name serving machines on the Internet, providing a robust and stable architecture on top of which an organization’s naming architecture can be built. The resolver library included in the BIND distribution provides the standard APIs for translation between domain names and Internet addresses and is intended to be linked with applications requiring name service.

Installing Bind

Become a super user

user@server:~# sudo su -
Password:

Install Bind 9 using apt-get

root@server:~# apt-get install bind9 bind9-doc dnsutils

Configuring Bind

Now go to the directory where the Bind’s configuration files is located and delete all the configuration files (except rndc.key) as we will create anew one.

root@server:~# cd /etc/bind/
root@server:~# ls
db.0 db.127 db.255 db.empty db.local db.root named.conf named.conf.local named.conf.options rndc.key zones.rfc1918
root@server:~# rm db* named* zone*

Create bind main configuration file “named.conf” as per sample below. You may modified to fit your requirements.
named.conf

options {
directory "/var/cache/bind";
version "Bind";
#hostname of this server
hostname "ns1.example.com";

#set from which IP the bind server should listen. We set only from local. 192.168.0.5 is IP address of bind servers machine
listen-on { 127.0.0.1; 192.168.0.5; };

#set from which IP range the bind server should allow query
allow-query { 127.0.0.1; 192.168.0.0/24; };

#forward all the request to external DNS server first
forward first;
forwarders {
202.188.0.133;
202.188.1.5;
};
};
#create a zone
zone "example.com" IN {
type master;
#location of the zone configuration file
file "/etc/bind/zone.example.com";
allow-update { none; };
};

DNS zone is a portion of the global DNS namespace. This namespace is defined by RFC 1034, Domain Names – Concepts and Facilities and RFC 1035, Domain Names – Implementation and Specification, and is laid out in a tree structure from right to left, such that divisions of the namespace are performed by prepending a series of characters followed by period (‘.’), to the upper namespace

Now create the zone file as what we defined above. Below the is the sample file.

zone.example.com

$TTL 3D
@ IN SOA ns1.example.com. web.example.com. (
19 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns1.example.com.
@ IN NS ns2.example.com.
example.com. IN A 202.9.109.254
www IN CNAME @
xchl IN A 192.168.0.2
intranet IN A 192.168.0.3
reports IN A 192.168.0.3
web IN A 192.168.0.3

Add the DNS server’s IP address in /etc/resolv.conf. (Note: This also need to be done on clients site)

domain example.com
search example.com
nameserver 127.0.0.1 #Local DNS server. On client site, change to servers IP (e.g: 192.168.0.x)
nameserver 202.188.0.133 #ISP DNS server. Do not add this on clients machine
nameserver 202.188.1.5 #ISP DNS server. Do not add this on clients machine

We are done with the configuration. Start the bind server

root@server:~# /etc/init.d/bind9 start
* Starting domain name service... [ ok ]