Setup DNS Server for IPv6 and IPv4 queries using Bind9 in CentOS Linux

So here’s how to setup your own IPv6 and IPv4 capable dns server in linux using bind v9. I will make this short only and straight forward so you wont get bored 😉

Let’s get started! First, we need to install Bind v9 through yum software package manager.

yum -y install bind

If you want to use MySQL to store your zone files then you can do so by installing its driver. This is however optional as you can use plain text file to store zone entries.

yum -y install bind-sdb

Now, start that named daemon.

service named start


Now, modify your configuration file in /etc/named.conf to have your domain’s zone file. In this guide, I configured it to answer for mikrotiksystems.com’s dns queries. Refer to sample code below.

//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//

options {
        listen-on port 53 { 127.0.0.1; 192.168.1.103;};
        listen-on-v6 port 53 { ::1; 2001:fe0:1111:1::103;};
        directory       "/var/named";
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
        allow-query     { any;};
        recursion yes;

        dnssec-enable yes;
        dnssec-validation yes;
        dnssec-lookaside auto;

        /* Path to ISC DLV key */
        bindkeys-file "/etc/named.iscdlv.key";

        managed-keys-directory "/var/named/dynamic";
};

logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};

zone "." IN {
        type hint;
        file "named.ca";
};

zone "mikrotiksystems.com" IN {
        type master;
        file "/etc/named/mikrotiksystems.com";
};

include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";


Below is a sample zone file of the domain mikrotiksystems.com which you can copy and modify it to reflect to your domain, aliases and address

$TTL 1200

mikrotiksystems.com.     IN      SOA     ns1.mikrotiksystems.com [email protected] (
        2012090804 ; serial
        1200 ; refresh
        1200 ; retry
        2149200 ; expire
        3600 ) ; negative cache ttl

@       IN AAAA 2001:fe0:1111:1::103
@       IN MX 10 mail.mikrotiksystems.com.
@       IN NS ns1.mikrotiksystems.com.
@       IN NS ns2.mikrotiksystems.com.

; A Records
ns1     IN A 222.127.128.114
ns2     IN A 121.96.67.18
mail    IN A 121.96.67.18

; AAAA Records
ns2     IN AAAA 2001:fe0:1111:1:a00:27ff:fe2f:78bb
ns1     IN AAAA 2001:fe0:1111:1::103
www     IN AAAA 2001:fe0:1111:1:a00:27ff:fe2f:78bb
mail    IN AAAA 2001:fe0:1111:1:a00:27ff:fe2f:78bb

Before you perform any dns lookups for your domain, you need to set your name servers first in your domain registrar to the name server you’ve just setup, then to check if your configured dns server answers queries for your domain, you use the nslookup tool.

Below is the output of the nslookup performed for the hostname www.mikrotiksystems.com

shell# nslookup www.mikrotiksystems.com
Server:  google-public-dns-a.google.com
Address:  8.8.8.8

Name:    www.mikrotiksystems.com
Address:  2001:fe0:1111:1:a00:27ff:fe2f:78bb

Leave a Reply

Your email address will not be published. Required fields are marked *