Add New Zone To Bind DNS Server

Overview

Welcome to the second of my DNS articles. It is more of a prequel to my first article in which I explained the steps in Creating A DNS Entry For A SubDomain.

This article assumes you have already installed bind and it is all running. If not, then you will need to setup bind first.

What is a DNS Zone?

My previously article explained what a zone is so I won’t go into to much detail here, but essentially a zone is the term used to describe a config file which contains a specific domain/subdomain collection in your DNS server. Bear in mind that a DNS server has multiple zones (and thus domains) associated to it. Each domain generally has its own zone file however in some situations, you can have multiple domains per zone file. For example, mydomain.com and mydomain.net and mydomain.org could all be in the same zone file as long as they all need to point to the same ip address.

Create the DNS zone file

The zone file we will create for this example will be for the domain example.com. The zone file will tell the DNS server which IP the domain should point to as well as configuring expiry and refresh times for the domain. Generally, the naming format for a zone file is db.example.com.conf where the domain in this case is example.com. Now to create the zone file and add the contents shown in the Sample DNS Domain Zone File

sudo vi /etc/bind/db.example.com.conf

Sample DNS Domain Zone File

In this sample DNS domain zone file, there are a couple changes you need to make to ensure it works in your situation. Firstly, change ns1.exampledns.com and ns2.exampledns.com with your own ns1 and ns2 dns servers. Secondly you can change example.com to the domain you are adding.

Optionally leave out $ORIGIN if you are adding multiple domains to a single zone file. The @ symbol simply means the current zone which is great for when you have multiple domains to a single zone file.

; Zone file for example.com
$TTL    3600
$ORIGIN example.com
@       IN      SOA     ns1.exampledns.com.    root.example.com. (
                     2012033101         ; Serial
                           3600         ; Refresh
                           1800         ; Retry
                         604800         ; Expire
                          43200 )       ; Negative Cache TTL

        IN      NS      ns1.exampledns.com.
        IN      NS      ns2.exampledns.com.

@       IN      A       192.168.0.2
www     IN      A       192.168.0.2

Add New Zone To Bind DNS Server

Above we created the zone config file. Now we need to add the zone file to our dns config file which tells our DNS server that it should control and serve requests for this new domain zone.

Open your DNS config file and add a zone in for your domain. I will be using example.com in my example. Here the file is located under /etc/bind/named.conf.local however depending on the way your DNS server was configured, it may be under /etc/bind/named.conf.options or rarely even /etc/bind/named.conf

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

Add a zone to your DNS config file

At the end of the file add an entry similar to the following

zone "example.com" {
	type master;
	file "/etc/bind/db.example.com.conf";
};

As you will see, the type of zone is a master zone. This means that it is the primary holder for dns information regarding this domain.

Restarting Bind DNS Server

Once you have added your new zone to your bind dns server, you need to restart the bind daemon in order to reload the new config file. You can do so by issuing the following command.

Debian / Ubuntu Linux

Restart bind dns server on Debian and Ubuntu Linux.

service bind9 start

Alternate method to restart bind dns server on Debian and Ubuntu Linux.

/etc/init.d/bind9 restart

Redhat / Fedora Linux

Restart bind dns server on Redhat and Fedora Linux.

service named restart

Alternate method to restart bind dns server on Redhat and Fedora Linux.

/etc/init.d/named restart

Note: you may need to use sudo to run these commands if your account doesn’t have enough privileges.