Install and configure DNS & Reverse DNS Server with BIND in CentOS

Hi, I'm going to show you how to install and configure Domain Name System in CentOS. that is not straight forward process and it's might be done with different type of configuration based on your needs. so let's have some agreements on Basics

Definition of DNS : The DNS (Domain Name System) is a distributed system, used for translate domain names to IP address and vice a versa (Reverse DNS to translate IP address to domain name).For example when we type domain name in browser url like “”, Our computer sends a request to DNS and get an ip address of domain.

What is Reverse DNS (rDNS) : Reverse DNS (rDNS) is a method of resolving an IP address into a domain name. exactly reverse scenario of DNS. you may ask what the use: One of the applications of reverse DNS is as a spam filter. for example spammer uses invalid IP address for sending mails that does not match used domain name. once the request reaches to destination server, server will run reverse DNS lookup against incoming message IP address to DNS system and check the validity of message by finding domain name match, if it doesn't find any match, server will block the message or mark it as spam.

ok, now we now what is what. let's assume below network scenario.

  • DNS Server IP:
  • DNS Server Name:,
  • Domain Name:

what we are going to do? : we have 1 stand-alone server with IP address and we are going to point our domain( to this server and then create DNS server with these NS records (, on the same server.

First step : let's point our domain to server IP address and NS records that we are going to create. for this action, depend on your domain control panel, you have to update your DNS to ( and and then create two child-host with these names. => pointing to server IP => pointing to server IP after this change, it will take a bit of time to propagate your changes to network.but for checking the status you can use or nslookup command in your terminal.

Second Step: we need to log-in to our server and install the requirement and make some configuration. I'm considering that we have CentOS 7 as server OS. so after log-in run below commands.

1. update yum packages

yum update

2. install bind (Bind packages are available under default yum repositories)

yum install bind

3. enabling network ports

after installation, if you have active firewall on your OS, we need to enable bind ports on the firewall. bind is using port number 53 on tcp/udp, so we need to enable these ports in our firewall.

run the below command in terminal for this activity.

[root@rhel7 ~]# firewall-cmd --zone=public --add-port=53/tcp --permanent
[root@rhel7 ~]# firewall-cmd --zone=public --add-port=53/udp --permanent
[root@rhel7 ~]# firewall-cmd --reload

note: if you have iptables, then you need to do this action based on iptables commands rule. for verifying that the port is open, run below command.

netstat -ant | grep -w 53
and you will get something like this.
[root@rhel7 ~]# netstat -ant | grep -w 53
tcp        0      0*               LISTEN     
tcp        0      0  *               LISTEN     
tcp6       0      0 ::1:53                  :::*                    LISTEN

as you can see, the port is open now.

4. change the configuration

after installing the bind, it will add one service to your OS, called "named" which is bind service. and this service has configuration file, stored under this path /etc/named.conf .

you can use vim or any other editor that you want to modify the configuration file, but please take a back-up before any changes. after modification you would have the below file, which I'll describe you the changes.

// 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.
// See the BIND Administrator's Reference Manual (ARM) for details about the
// configuration located in /usr/share/doc/bind-{version}/Bv9ARM.html

options {
    listen-on port 53 {;; };
    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     { any; };
    allow-transfer { none; };
     - If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
     - If you are building a RECURSIVE (caching) DNS server, you need to enable 
     - If your recursive DNS server has a public IP address, you MUST enable access 
       control to limit queries to your legitimate users. Failing to do so will
       cause your server to become part of large scale DNS amplification 
       attacks. Implementing BCP38 within your network would greatly
       reduce such attack surface 
    recursion no;

    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";

    pid-file "/run/named/";
    session-keyfile "/run/named/session.key";

logging {
        channel default_debug {
                file "data/";
                severity dynamic;

acl "trusted-servers"  {;  //ns1 and ns2

zone "." IN {
    type hint;
    file "";

zone "" IN {
    type master;
    file "/var/named/";
    allow-update { "trusted-servers"; };

zone "" IN {
        type master;
        file "/var/named/";
        allow-update { none; };

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

what is the change?

first add your server IP address here listen-on port 53 {;; }; , this will tell bind to listen on which IP.

change allow-query to any, this will allow every computer to query your DNS. allow-query { any; }; since we are configuring authoritative DNS server , make sure recursion is no , recursion no;

set dnssec setting as below, what is dnssec? click Here

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

now it's time to create zone file and load it, what is zone file? ( click Here ).

we are going to create one zone file for our domain name, and an other one for our reverse DNS and then load it in our config.

loading domain name zone:

zone "" IN {
    type master;
    file "/var/named/";
    allow-update { "trusted-servers"; };

load reverse DNS zone

zone "" IN {
        type master;
        file "/var/named/";
        allow-update { none; };

content of each zone file : note: lines starting with ; are comments.

$TTL 86400
@   IN  SOA (
        2017082701  ;Serial
        14400       ;Refresh
        3600        ;Retry
        1209600     ;Expire
        3600        ;Minimum TTL
; Specify our nameservers
                IN      NS    
                IN      NS    

; and mail exchange servers
;                IN      MX      10

; Define hostname    IN    A
ns1        IN    A
ns2        IN    A
@               IN      A     
www             IN      A content:

$TTL    604800      IN      SOA (
                          1        ; Serial
                          3h       ; Refresh after 3 hours
                          1h       ; Retry after 1 hour
                          1w       ; Expire after 1 week
                          1h )     ; Negative caching TTL of 1 day       IN      NS       IN      NS   IN      PTR

now we are almost done.

5. check the configuration and restarting bind

Before we attempt to start a bind name server with a new zone and configuration here are some tools to check if we have not done some typo or misconfiguration. To check a configuration files run a following command: named-checkconf With this named-checkconf command the rule is: no news are good news. If no output had been produced your config files looks OK. now let's check zone files with named-checkzone

named-checkzone /var/named/
zone loaded serial 2017082701
amed-checkzone /var/named/
zone loaded serial 1

now seems everything is fine and we just need to restart the bind service.

service named restart

6. verifying the DSN server

to verify that DNS server is working properly, run below command in your system terminal.





Above output is showing that DNS server has successfully resolved domain and we are finished, hope to be useful.


No Comments Yet