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.

How to Reset the Directory Manager Password on RHEL 7 / CentOS 7
How to Reset the Directory Manager Password on RHEL 7 / CentOS 7

It is best practice to remember passwords, but because too many passwords, sometimes we forget. We are not encouraged to write the password on any paper or share the password...

How to Find Big Files Size on Linux RHEL/CentOS
How to Find Big Files Size on Linux RHEL/CentOS

As the linux administrator, sometimes we have to identify which files are most take much space in the linux server resulting in low free space. Low disk space can also...

Why Linux users should worry about malware and what they can do about it
Why Linux users should worry about malware and what they can do about it

Don’t drop your guard just because you’re running Linux. Preventing the spread of malware and/or dealing with the consequences of infection are a fact of life when using computers. If...

How to Reset Forgotten Root Password on Linux RHEL 7/CentOS 7
How to Reset Forgotten Root Password on Linux RHEL 7/CentOS 7

This article will explain the steps to reset a lost root password or to reset forgotten root password on Linux RHEL 7 or CentOS 7. Basically, the steps will adding...

How to Update CentOS or Upgrade CentOS to the Latest Version
How to Update CentOS or Upgrade CentOS to the Latest Version

Recently, the latest version of CentOS 7.3 was released. All users of CentOS 7.0, 7.1 and 7.2 can upgrade their system to the most recent. This quick guide will explain...

How to Change your WordPress Username, Nickname and Display Name in MySQL
How to Change your WordPress Username, Nickname and Display Name in MySQL

After you create an account log in WordPress, you may want to change your WordPress username, as appropriate or due to security reason. However, you can not do this from...

How to Enable SSH Root Login on Ubuntu 16.04
How to Enable SSH Root Login on Ubuntu 16.04

As what we wrote in the previous article on how to allow SSH root on Ubuntu 14.04, after installing a fresh new copy of Ubuntu 16.04 LTS, we find that...

How to Change UUID of Linux Partition on CentOS 7
How to Change UUID of Linux Partition on CentOS 7

UUID (Universally Unique IDentifier) should be unique and it is used to identify storage devices on a linux system. If you cloned a virtual machine from vCenter, the metadata containing...

2 Comments

  • Avatar for Akash Desai 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 for ehowstuff ehowstuff says:

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

    nameserver 192.168.1.20

2 Trackbacks and Pingbacks

Leave a Reply

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