Setup DNS server Bind chroot CentOS 6

I. Edit /etc/hosts
# vi /etc/hosts localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 ns1.bachem.local ns1

II. Install & Setting Bind chroot for DNS Server
-Install Bind
# yum -y install bind bind-chroot

-Setting iptables open DNS port
# system-config-firewall-tui


# iptables -A INPUT -p udp -m state --state NEW --dport 53 -j ACCEPT
# iptables -A INPUT -p tcp -m state --state NEW --dport 53 -j ACCEPT
# service iptables save
# service iptables restart

-Konfigurasi awal
# cp -R /usr/share/doc/bind-9.8.2/sample/var/named/* /var/named/chroot/var/named/
# cp -R /usr/share/doc/bind-9.8.2/sample/etc/* /var/named/chroot/etc/
# touch /var/named/chroot/var/named/data/cache_dump.db
# touch /var/named/chroot/var/named/data/named_stats.txt
# touch /var/named/chroot/var/named/data/named_mem_stats.txt
# touch /var/named/chroot/var/named/data/
# mkdir /var/named/chroot/var/named/dynamic
# touch /var/named/chroot/var/named/dynamic/managed-keys.bind
# chmod -R 777 /var/named/chroot/var/named/data
# chmod -R 777 /var/named/chroot/var/named/dynamic

-Set if you don’t use IPv6(if use, don’t set it)
# echo 'OPTIONS="-4"' >> /etc/sysconfig/named

-Setting RNDC
# rndc-confgen -a -c /etc/rndc.key
# chmod 755 /etc/rndc.key

-Konfigurasi /var/named/chroot/etc/named.conf
# touch /var/named/chroot/etc/named.conf
# vi /var/named/chroot/etc/named.conf

include "/etc/rndc.key";
options {
// Put files that named is allowed to write in the data/ directory:
directory "/var/named";
// "Working" directory
dump-file "data/cache_dump.db";
statistics-file "data/named_stats.txt";
memstatistics-file "data/named_mem_stats.txt";
pid-file "/var/run/named/";

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

/* Specify listenning interfaces. You can use list of addresses (';' is delimiter) or keywords "any"/"none" */
//listen-on port 53 { any; };
listen-on port 53 { localhost;; };

//listen-on-v6 port 53 { any; };
listen-on-v6 port 53 { ::1; };

//these are the ISP DNS or public DNS servers (optional)
forwarders {;;;;;

/* Access restrictions

There are two important options:
allow-query { argument; };
- allow queries for authoritative data

allow-query-cache { argument; };
- allow queries for non-authoritative data (mostly cached data)

You can use address, network address or keywords "any"/"localhost"/"none" as argument
allow-query { localhost;;; };
allow-query-cache { ::1; fe80::5c63:a8ff:fe2f:4526;; };

allow-query { localhost;; };
allow-query-cache { localhost;; };

// Enable/disable recursion - recursion yes/no;
recursion yes;
/* DNSSEC related options. See information about keys ("Trusted keys", bellow) */
/* Enable serving of DNSSEC related data - enable on both authoritative and recursive servers DNSSEC aware servers */
//dnssec-enable yes;
/* Enable DNSSEC validation on recursive servers */
//dnssec-validation yes;
/* Enable DLV by default, use built-in ISC DLV key. */
//dnssec-lookaside auto;

logging {
/* If you want to enable debugging, eg. using the 'rndc trace' command,
* named will try to write the '' file in the $directory (/var/named).
* By default, SELinux policy does not allow named to modify the /var/named directory,
* so put the default debug log file in data/ :
channel default_debug {
file "data/";
severity dynamic;

/* Views let a name server answer a DNS query differently depending on who is asking.

By default, if named.conf contains no "view" clauses, all zones are in the "default" view, which matches all clients.
Views are processed sequentially. The first match is used so the last view should match "any" - it's fallback and the most restricted view.

If named.conf contains any "view" clause, then all zones MUST be in a view.

view "internal" {
/* This view will contain zones you want to serve only to "internal" clients that connect via your directly attached LAN interfaces - "localnets".

match-clients { localhost;; };
recursion yes;
zone "." IN {
type hint;
file "/var/named/";

/* these are zones that contain definitions for all the localhost
* names and addresses, as recommended in RFC1912 - these names should
* not leak to the other nameservers:
include "/etc/named.rfc1912.zones";

// These are your "authoritative" internal zones, and would probably
// also be included in the "localhost_resolver" view above :

/* NOTE for dynamic DNS zones and secondary zones:


If you are using views and DDNS/secondary zones it is strongly recommended to read FAQ on ISC site (, section
"Configuration and Setup Questions", questions
"How do I share a dynamic zone between multiple views?" and
"How can I make a server a slave for both an internal and an external
view at the same time?"

zone "bachem.local" IN {
type master;
file "";
//allow-update { none; };
//we assume we have a slave dns server with the IP
allow-transfer {; };
notify yes;
also-notify {; };

zone "" IN {
type master;
file "";
//allow-update { none; };
//we assume we have a slave dns server with the IP
allow-transfer {; };
notify yes;
also-notify {; };

-Setting Forward Lookup Zone
# cd /var/named/chroot/var/named
# touch
# vi

$TTL 86400
@ IN SOA ns1.bachem.local. admin.bachem.local. (
2012113001 ; Serial
10800 ; Refresh after 3 hours
3600 ; Retry after 1 hour
604800 ; Expire after 1 week
86400 ) ; Minimum TTL of 1 day
@ IN NS ns1.bachem.local.
ns1 IN A
ayam IN CNAME ns1
cumi IN A
ns2 IN A
kucing IN CNAME ns2

-Setting Reverse Lookup Zone
# cd /var/named/chroot/var/named
# touch
# vi

$TTL 86400
@ IN SOA ns1.bachem.local. admin.bachem.local. (
3600 )
IN NS ns1.bachem.local.
5 IN PTR ns1.bachem.local.
11 IN PTR cumi.bachem.local.
6 IN PTR ns2.bachem.local.

-Edit /etc/resolv.conf
# vi /etc/resolv.conf

search bachem.local

-Restart Bind service & Setting run level
# service named restart
# chkconfig named on

Make sure it’s running:
# rndc status

-Testing DNS Query


3 thoughts on “Setup DNS server Bind chroot CentOS 6

  1. labradorg13

    hello, thanks for your great post. It help to me.
    but, I get an error after the service named restart command.

    [root@rpidvoproxy rpidavao]# service named restart
    Stopping named: [ OK ]
    Starting named:
    Error in named configuration:
    zone localhost.localdomain/IN: loaded serial 0
    zone localhost/IN: loaded serial 0
    zone loaded serial 0
    zone loaded serial 0
    zone loaded serial 0
    zone loading from master file failed: file not found
    zone not loaded due to errors.
    internal/ file not found
    zone loaded serial 2012113002
    [root@rpidvoproxy rpidavao]#

    give some advice that is this error.


      1. labradorg13

        hello bachem.

        thanks your time to reply.

        I repeat your instruction “-Konfigurasi awal” , then copy from your named.conf and paste into my named.conf and some editing information of hostname, ip’s, slave ip.

        After repeating those instrucition, then named restart…. wow! its running now, then dig 172.11.56.
        I thinks there is mistake of my named.conf….

        Again, thanks for your time.


Leave a Reply

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