How to install dns server in centos 6

DNS

DNS helps to resolve domain name to ip address and ip address to domain name . In this post we can see how to configure DNS server on centos 6.

Install dns server in centos 6 :

Just follow the step by step instruction to setup dns server on centos 6 .
You can also refer the below posts for Centos OS installation and network configuration

» Centos 6 installation step by step screenshots

» How to setup network in centos 6

Step 1 » Install bind packages by issuing the below command.
[root@localhost ~]# yum install bind*

Step 2 » Assign static IP address.
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE="eth0"
HWADDR="00:0C:29:0D:FB:E2"
NM_CONTROLLED="yes"
ONBOOT="yes"
BOOTPROTO="static"
IPADDR=172.16.28.5
NETMASK=255.255.255.0
GATEWAY=172.16.28.1

Step 3 » Assign fully qualified domain name for the server ( Ex: dns1.krizna.com )
[root@localhost ~]# vim /etc/sysconfig/network

NETWORKING=yes
HOSTNAME=dns1.krizna.com

Step 4 » Add a host entry in the host file .
[root@localhost ~]# vim /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.28.5   dns1.krizna.com

Step 5 » Add server ip to the resolve.conf file.
[root@localhost ~]# vim /etc/resolv.conf

search krizna.com
nameserver 172.16.28.5

Just We completed pre requirements for DNS server . Lets start main configuration
Step 6 » Open /etc/named.conf file and Edit the following line Nos 11,12 and 17 like below
[root@localhost ~]# vim /etc/named.conf

//
// 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 { 172.16.28.5; };    ## replace with your IP <-----------
#       listen-on-v6 port 53 { ::1; };         ## comment this line    <-----------
        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; };              ## Edit this line       <-----------
        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";
};

include "/etc/named.rfc1912.zones";                      ##Check this line <--------
include "/etc/named.root.key";

Step 6 » Now open /etc/named.rfc1912.zones file and edit the following line nos 13,14,31 and 32
[root@localhost ~]# vim /etc/named.rfc1912.zones

// named.rfc1912.zones:
//
// Provided by Red Hat caching-nameserver package
//
// ISC BIND named zone configuration for zones recommended by
// RFC 1912 section 4.1 : localhost TLDs and address zones
// and http://www.ietf.org/internet-drafts/draft-ietf-dnsop-default-local-zones-02.txt
// (c)2007 R W Franks
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//

zone "krizna.com" IN {                 ## Your domain name       <----------
        type master;
        file "forward.zone";           ## Forward zone file name <----------
        allow-update { none; };
};

zone "localhost" IN {
        type master;
        file "named.localhost";
        allow-update { none; };
};

zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {
        type master;
        file "named.loopback";
        allow-update { none; };
};

zone "28.16.172.in-addr.arpa" IN {         ##Edit as per your IP address <-----            
        type master;
        file "reverse.zone";               ## Reverse zone file name <---------
        allow-update { none; };
};

zone "0.in-addr.arpa" IN {
        type master;
        file "named.empty";
        allow-update { none; };
};

Step 7 » Now create forward and reverse zone files like below
[root@localhost ~]# cp /var/named/named.localhost /var/named/forward.zone
[root@localhost ~]# cp /var/named/named.loopback /var/named/reverse.zone

Step 8 » Open the forward zone file and replace with your hostname like below
[root@localhost ~]# vim /var/named/forward.zone

$TTL 1D
@ IN SOA dns1.krizna.com. root.dns1.krizna.com. (       
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        IN NS   dns1.krizna.com.                      
dns1    IN A    172.16.28.5

Step 9 » Now open the reverse zone file and replace like below .
[root@localhost ~]# vim /var/named/reverse.zone

$TTL 1D
@ IN SOA dns1.krizna.com. root.dns1.krizna.com. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        IN NS      dns1.krizna.com.
5       IN PTR     dns1.krizna.com.

Step 10 » Now set group permissions for the files

[root@localhost ~]# chgrp named /var/named/forward.zone
[root@localhost ~]# chgrp named /var/named/reverse.zone

Step 11 » That's it , now start the service by typing the below command

[root@localhost ~]# service named start
Generating /etc/rndc.key:                                  [  OK  ]
Starting named:                                            [  OK  ]

Step 12 » Issue the below command to start service on bootup and Reboot the server
[root@localhost ~]# chkconfig --levels 235 named on

Step 13 » After rebooting .Just issue the below commands to test your dns server
[root@dns1 ~]# dig

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.10.rc1.el6_3.6 <<>>
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 45720
;; flags: qr rd ra; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;.				IN	NS

;; ANSWER SECTION:
.			518400	IN	NS	e.root-servers.net.
.			518400	IN	NS	c.root-servers.net.
.			518400	IN	NS	d.root-servers.net.
.			518400	IN	NS	m.root-servers.net.
.			518400	IN	NS	a.root-servers.net.
.			518400	IN	NS	f.root-servers.net.
.			518400	IN	NS	k.root-servers.net.
.			518400	IN	NS	h.root-servers.net.
.			518400	IN	NS	b.root-servers.net.
.			518400	IN	NS	j.root-servers.net.
.			518400	IN	NS	l.root-servers.net.
.			518400	IN	NS	g.root-servers.net.
.			518400	IN	NS	i.root-servers.net.

;; Query time: 1457 msec
;; SERVER: 172.16.28.5#53(172.16.28.5)
;; WHEN: Mon Dec 17 22:47:52 2012
;; MSG SIZE  rcvd: 228
[root@dns1 ~]# nslookup dns1.krizna.com
Server:		172.16.28.5
Address:	172.16.28.5#53

Name:	dns1.krizna.com
Address: 172.27.16.5
[root@dns1 ~]# nslookup 172.16.28.5
Server:		172.16.28.5
Address:	172.16.28.5#53

5.28.16.172.in-addr.arpa	name = dns1.krizna.com.

[root@dns1 ~]# 

All the best

56 Comments

  1. Your tutorials are way high in aleague less competed,they hit on the bulls eye,thanks so so much and infact they are simple to the letter

  2. Your tutorials are way high in aleague less competed,they hit on the bulls eye,thanks so so much and infact they are simple to the letter

  3. mine says #.sakar.com bad ownername, i gave name as
    HOSTNAME = dns1.sakar.com asu said to.. what is the problem?? is my name bad lol

  4. mine says #.sakar.com bad ownername, i gave name as
    HOSTNAME = dns1.sakar.com asu said to.. what is the problem?? is my name bad lol

  5. [root@rpidvoproxy rpidavao]#
    service named start
    Starting named:
    Error in named configuration:
    zone rpidvoproxy.proxydavao.com/IN: NS ‘rpidvoproxy.proxydavao.com’ has no address records (A or AAAA)
    zone rpidvoproxy.proxydavao.com/IN: not loaded due to errors.
    _default/rpidvoproxy.proxydavao.com/IN: bad zone
    zone localhost/IN: loaded serial 0
    zone 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa/IN: loaded serial 0
    zone 172.11.1.in-addr.arpa/IN: loaded serial 0
    zone 0.in-addr.arpa/IN: loaded serial 0
    [FAILED]
    [root@rpidvoproxy rpidavao]#

    hello author, can you help what this error?

    Thanks

  6. [root@rpidvoproxy rpidavao]#
    service named start
    Starting named:
    Error in named configuration:
    zone rpidvoproxy.proxydavao.com/IN: NS ‘rpidvoproxy.proxydavao.com’ has no address records (A or AAAA)
    zone rpidvoproxy.proxydavao.com/IN: not loaded due to errors.
    _default/rpidvoproxy.proxydavao.com/IN: bad zone
    zone localhost/IN: loaded serial 0
    zone 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa/IN: loaded serial 0
    zone 172.11.1.in-addr.arpa/IN: loaded serial 0
    zone 0.in-addr.arpa/IN: loaded serial 0
    [FAILED]
    [root@rpidvoproxy rpidavao]#

    hello author, can you help what this error?

    Thanks

  7. hello, I got this error message.

    pls. help how to fix this error.

    My configuration are

    eth0 : DYNAMIC IP

    eth1:
    IP: 172.11.1.56
    SM: 255.255.255.0
    DG: 0.0.0.0
    DNS: 172.11.1.56

    [root@rpidvoproxy rpidavao]# service named start
    Starting named:
    Error in named configuration:
    zone rpidvoproxy.proxydavao.com/IN: NS ‘rpidvoproxy.proxydavao.com’ has no address records (A or AAAA)
    zone rpidvoproxy.proxydavao.com/IN: not loaded due to errors.
    _default/rpidvoproxy.proxydavao.com/IN: bad zone
    zone localhost/IN: loaded serial 0
    zone 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa/IN: loaded serial 0
    zone 172.11.1.in-addr.arpa/IN: loaded serial 0
    zone 0.in-addr.arpa/IN: loaded serial 0
    [FAILED]
    [root@rpidvoproxy rpidavao]#

      • this is my host..
        nano /etc/hosts

        27.0.0.1 localhost.localdomain localhost
        ::1 rpidvoproxy.proxydavao.com rpidvoproxy localhost6.localdomain6 localhost6
        172.11.1.56 rpidvoproxy.proxydavao.com

        • hello krizna, after of my some modification at /etc/named.rfc1912.zones.

          afterwards, I come up a little miss of error.

          pls. give some advice..

          [root@rpidvoproxy rpidavao]# service named start
          Starting named:
          Error in named configuration:
          /etc/named.rfc1912.zones:15: ‘}’ expected near ‘”‘
          [FAILED]
          [root@rpidvoproxy rpidavao]#

          • Yes, I know about the braces, like open and close braces..
            but the error way of pointing is in my “named.rfc1912.zones”

            please tell me where brace ang missing up?

            need your help…

            zone “proxydavao.com” IN {

            type master;

            “file “forward.zone”;

            allow-update { none; };

            };

            zone “localhost” IN {

            type master;

            file “named.localhost”;

            allow-update { none; };

            };

            zone
            “1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa”
            IN {

            type master;

            file “named.loopback”;

            allow-update { none; };

            };

            zone “1.11.172.in-addr.arpa”
            IN {

            type master;

            file “reverse.zone”;

            allow-update { none; };

            };

            zone “0.in-addr.arpa” IN {

            type master;

            file “named.empty”;

            allow-update { none; };

            };

          • thanks for that little miss-up… I thought I almost got to the top… but after removing that quotation.

            then, service named start. I got this back error…

            [root@rpidvoproxy rpidavao]# service named start
            Starting named:
            Error in named configuration:
            zone proxydavao.com/IN: NS ‘rpidvoproxy.proxydavao.com’ has no address records (A or AAAA)
            zone proxydavao.com/IN: not loaded due to errors.
            _default/proxydavao.com/IN: bad zone
            zone localhost/IN: loaded serial 0
            zone 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa/IN: loaded serial 0
            zone 1.11.172.in-addr.arpa/IN: loaded serial 0
            zone 0.in-addr.arpa/IN: loaded serial 0
            [FAILED]
            [root@rpidvoproxy rpidavao]#

          • hellow krizna… finally it run perfectly…
            thanks for the help..
            your amazing and great mod…

          • still same with your’s

            $TTL 1D
            @ IN SOA rpidvoproxy.proxydavao.com. root.rpidvoproxy.proxydavao.com. (
            0 ; serial
            1D ; refresh
            1H ; retry
            1W ; expire
            3H ) ; minimum
            IN NS rpidvoproxy.proxydavao.com.
            dns1 IN A 172.11.1.56

  8. hello, I got this error message.

    pls. help how to fix this error.

    My configuration are

    eth0 : DYNAMIC IP

    eth1:
    IP: 172.11.1.56
    SM: 255.255.255.0
    DG: 0.0.0.0
    DNS: 172.11.1.56

    [root@rpidvoproxy rpidavao]# service named start
    Starting named:
    Error in named configuration:
    zone rpidvoproxy.proxydavao.com/IN: NS ‘rpidvoproxy.proxydavao.com’ has no address records (A or AAAA)
    zone rpidvoproxy.proxydavao.com/IN: not loaded due to errors.
    _default/rpidvoproxy.proxydavao.com/IN: bad zone
    zone localhost/IN: loaded serial 0
    zone 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa/IN: loaded serial 0
    zone 172.11.1.in-addr.arpa/IN: loaded serial 0
    zone 0.in-addr.arpa/IN: loaded serial 0
    [FAILED]
    [root@rpidvoproxy rpidavao]#

      • this is my host..
        nano /etc/hosts

        27.0.0.1 localhost.localdomain localhost
        ::1 rpidvoproxy.proxydavao.com rpidvoproxy localhost6.localdomain6 localhost6
        172.11.1.56 rpidvoproxy.proxydavao.com

        • hello krizna, after of my some modification at /etc/named.rfc1912.zones.

          afterwards, I come up a little miss of error.

          pls. give some advice..

          [root@rpidvoproxy rpidavao]# service named start
          Starting named:
          Error in named configuration:
          /etc/named.rfc1912.zones:15: ‘}’ expected near ‘”‘
          [FAILED]
          [root@rpidvoproxy rpidavao]#

          • Yes, I know about the braces, like open and close braces..
            but the error way of pointing is in my “named.rfc1912.zones”

            please tell me where brace ang missing up?

            need your help…

            zone “proxydavao.com” IN {

            type master;

            “file “forward.zone”;

            allow-update { none; };

            };

            zone “localhost” IN {

            type master;

            file “named.localhost”;

            allow-update { none; };

            };

            zone
            “1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa”
            IN {

            type master;

            file “named.loopback”;

            allow-update { none; };

            };

            zone “1.11.172.in-addr.arpa”
            IN {

            type master;

            file “reverse.zone”;

            allow-update { none; };

            };

            zone “0.in-addr.arpa” IN {

            type master;

            file “named.empty”;

            allow-update { none; };

            };

          • thanks for that little miss-up… I thought I almost got to the top… but after removing that quotation.

            then, service named start. I got this back error…

            [root@rpidvoproxy rpidavao]# service named start
            Starting named:
            Error in named configuration:
            zone proxydavao.com/IN: NS ‘rpidvoproxy.proxydavao.com’ has no address records (A or AAAA)
            zone proxydavao.com/IN: not loaded due to errors.
            _default/proxydavao.com/IN: bad zone
            zone localhost/IN: loaded serial 0
            zone 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa/IN: loaded serial 0
            zone 1.11.172.in-addr.arpa/IN: loaded serial 0
            zone 0.in-addr.arpa/IN: loaded serial 0
            [FAILED]
            [root@rpidvoproxy rpidavao]#

          • hellow krizna… finally it run perfectly…
            thanks for the help..
            your amazing and great mod…

          • still same with your’s

            $TTL 1D
            @ IN SOA rpidvoproxy.proxydavao.com. root.rpidvoproxy.proxydavao.com. (
            0 ; serial
            1D ; refresh
            1H ; retry
            1W ; expire
            3H ) ; minimum
            IN NS rpidvoproxy.proxydavao.com.
            dns1 IN A 172.11.1.56

  9. when I run nslookup 192.168.1.* ( * being the last 3 digits in my server’s internal IP)
    I get the following error
    ** server can’t find *.1.168.192.in.addr.arpa.: NXDOMAIN
    Help?

    • Check your “reverse.zone” file .. you should have an entry for your server IP . Eg -> if your server ip = 192.168.1.2 and hostname = dns1.krizna.com . Entry should be like below .. refer STEP 9

      2 IN PTR dns1.krizna.com.
      restart named service and try again

  10. when I run nslookup 192.168.1.* ( * being the last 3 digits in my server’s internal IP)
    I get the following error
    ** server can’t find *.1.168.192.in.addr.arpa.: NXDOMAIN
    Help?

    • Check your “reverse.zone” file .. you should have an entry for your server IP . Eg -> if your server ip = 192.168.1.2 and hostname = dns1.krizna.com . Entry should be like below .. refer STEP 9

      2 IN PTR dns1.krizna.com.
      restart named service and try again

  11. I don’ normally comment on blogs, but i wanted to say thank you. I am not new to linux but I am new to DNS. This is the only tutorial that I found out of all of them that worked. Thanks a lot

  12. I don’ normally comment on blogs, but i wanted to say thank you. I am not new to linux but I am new to DNS. This is the only tutorial that I found out of all of them that worked. Thanks a lot

  13. Hi Krizna,
    I am too much impressed with your site, have learned some topic with clear concept.
    I would like to know that which colorful editor your are using to display commands or files output.
    Please tell me

  14. Hi Krizna,
    I am too much impressed with your site, have learned some topic with clear concept.
    I would like to know that which colorful editor your are using to display commands or files output.
    Please tell me

Leave a Reply

Your email address will not be published.


*