How to Install and Configure Bind 9 DNS on CentOS 6.2 x86_64

Bind is the most popular software and the most widely used Domain Name System (DNS) software on the Internet for providing DNS services. The name BIND stands for “Berkeley Internet Name Domain” and it’s an implementation of the DNS protocols. In this post i will show the steps how to install and configure Bind 9 DNS service on linux CentOS 6.2 64 bit server.

To install Bind 9 on linux CentOS 6.2 server, run the following command :

[root@CentOS6.2 ~]# yum install bind -y

Example :

[root@CentOS6.2 ~]# yum install bind -y
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: centos.biz.net.id
 * extras: centos.biz.net.id
 * updates: centos.idrepo.or.id
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package bind.x86_64 32:9.7.3-8.P3.el6_2.2 will be installed
--> Processing Dependency: bind-libs = 32:9.7.3-8.P3.el6_2.2 for package: 32:bind-9.7.3-8.P3.el6_2.2.x86_64
--> Running transaction check
---> Package bind-libs.x86_64 32:9.7.3-8.P3.el6 will be updated
--> Processing Dependency: bind-libs = 32:9.7.3-8.P3.el6 for package: 32:bind-utils-9.7.3-8.P3.el6.x86_64
---> Package bind-libs.x86_64 32:9.7.3-8.P3.el6_2.2 will be an update
--> Running transaction check
---> Package bind-utils.x86_64 32:9.7.3-8.P3.el6 will be updated
---> Package bind-utils.x86_64 32:9.7.3-8.P3.el6_2.2 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================
 Package               Arch              Version                           Repository          Size
====================================================================================================
Installing:
 bind                  x86_64            32:9.7.3-8.P3.el6_2.2             updates            3.9 M
Updating for dependencies:
 bind-libs             x86_64            32:9.7.3-8.P3.el6_2.2             updates            840 k
 bind-utils            x86_64            32:9.7.3-8.P3.el6_2.2             updates            178 k

Transaction Summary
====================================================================================================
Install       1 Package(s)
Upgrade       2 Package(s)

Total download size: 4.9 M
Downloading Packages:
(1/3): bind-9.7.3-8.P3.el6_2.2.x86_64.rpm                                    | 3.9 MB     01:16
(2/3): bind-libs-9.7.3-8.P3.el6_2.2.x86_64.rpm                               | 840 kB     00:15
(3/3): bind-utils-9.7.3-8.P3.el6_2.2.x86_64.rpm                              | 178 kB     00:02
----------------------------------------------------------------------------------------------------
Total                                                                50 kB/s | 4.9 MB     01:39
warning: rpmts_HdrFromFdno: Header V4 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Importing GPG key 0xC105B9DE:
 Userid : CentOS-6 Key (CentOS 6 Official Signing Key) 
 Package: centos-release-6-2.el6.centos.7.x86_64 (@anaconda-CentOS-201112091719.x86_64/6.2)
 From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating   : 32:bind-libs-9.7.3-8.P3.el6_2.2.x86_64                                           1/5
  Updating   : 32:bind-utils-9.7.3-8.P3.el6_2.2.x86_64                                          2/5
  Installing : 32:bind-9.7.3-8.P3.el6_2.2.x86_64                                                3/5
  Cleanup    : 32:bind-utils-9.7.3-8.P3.el6.x86_64                                              4/5
  Cleanup    : 32:bind-libs-9.7.3-8.P3.el6.x86_64                                               5/5

Installed:
  bind.x86_64 32:9.7.3-8.P3.el6_2.2

Dependency Updated:
  bind-libs.x86_64 32:9.7.3-8.P3.el6_2.2           bind-utils.x86_64 32:9.7.3-8.P3.el6_2.2

Complete!

2. Setup and configure zone with the name of example.com :

[root@CentOS6.2 ~]# vi /var/named/example.com

Create example.com zone as below. You can have different IP addresses if you have installed separate mail server and DNS server :

;
;       Addresses and other host information.
;
@       IN      SOA     example.com. hostmaster.example.com. (
                               2011030801      ; Serial
                               43200      ; Refresh
                               3600       ; Retry
                               3600000    ; Expire
                               2592000 )  ; Minimum

;       Define the nameservers and the mail servers

               IN      NS      ns.example.com.
               IN      A       192.168.1.20
               IN      MX      10 mail.example.com.

mail            IN      A       192.168.1.20
ns              IN      A       192.168.1.20

3. Add example zone below to named.conf. named.conf is main configuration file for bind dns server.

zone "example.com" {
    type master;
    file "example.com";
};

Open named.conf :

[root@CentOS6.2 ~]# vi /etc/named.conf

Add zone “example.com” into the named.conf as 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; };
        listen-on-v6 port 53 { ::1; };
        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     { localhost; };
        recursion yes;

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

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

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

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

zone "example.com" {
    type master;
    file "example.com";
};

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

4. Start named service :

[root@CentOS6.2 ~]# service named start

or

[root@CentOS6.2 ~]# /etc/init.d/named start

5. Configure /etc/resolv.conf to point to this bind dns server (192.168.1.20).

6. Test your dns configuration whether working or not :

[root@CentOS6.2 ~]# host -t mx example.com
example.com mail is handled by 10 mail.example.com.

Comments

2 Comments

  • Avatar Akash Desai says:

    Hi
    I can’t seem to get this to work. If I make the only nameserver (comment out the original ones) I get this:
    host -t mx example.com
    ;; connection timed out; no servers could be reached

    And if I just add 192.168.1.20 to the nameserver list, I get this:
    # host -t mx example.com
    example.com has no MX record

    What’s the problem?

  • Avatar ehowstuff says:

    Have you change /etc/resolv.conf on you server?

    nameserver 192.168.1.20

Leave a Reply

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