• Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

How to Setup DNS (Bind) Server on CentOS/RHEL 7/6/5

Written by Rahul, Updated on April 2, 2013

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

This article will help you to step by step setup dns server on CentOS and RedHat systems.

Network Scenario:

  • DNS Server IP: 192.168.1.254
  • DNS Server Name: ns1.tecadmin.net, ns2.tecadmin.net
  • Domain Name: demotecadmin.net
  • Domain IP to point: 192.168.1.100

Step 1 – Install Bind Packages

Bind packages are available under default yum repositories. To install packages simple execute below command.

# yum install bind bind-chroot

Step 2 – Edit Main Configuration File

Default bind main configuration file is located under /etc directory. But using chroot environment this file is located at /var/named/chroot/etc directory. Now edit main configuration file and update content as below.

# vim /var/named/chroot/etc/named.conf

Content for the named.conf file

// /var/named/chroot/etc/named.conf
options {
        listen-on port 53 { 127.0.0.1; 192.168.1.0/24; 0.0.0.0/0; };
        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; 192.168.1.0/24; 0.0.0.0/0; };
        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";
};

zone "demotecadmin.net" IN {
        type master;
        file "/var/named/demotecadmin.net.db";
};

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

Step 3 – Create Zone File for Your Domain

After creating bind main configuration file, create a zone file for you domain as per configuration, for example demotecadmin.net.db in this article.

# vim /var/named/chroot/var/named/demotecadmin.net.db

Content for the zone file

; Zone file for demotecadmin.net
$TTL 14400
@      86400    IN      SOA     ns1.tecadmin.net. webmaster.tecadmin.net. (
                3013040200      ; serial, todays date+todays
                86400           ; refresh, seconds
                7200            ; retry, seconds
                3600000         ; expire, seconds
                86400          ; minimum, seconds
      )
demotecadmin.net. 86400 IN NS ns1.tecadmin.net.
demotecadmin.net. 86400 IN NS ns2.tecadmin.net.
demotecadmin.net. IN A 192.168.1.100
demotecadmin.net. IN MX 0 mail.demotecadmin.net.
mail 			  IN CNAME demotecadmin.net.
www 			  IN CNAME demotecadmin.net.

If you are having more domain, its required to create zone files for each domain individually.

Step 4 – Add More Domains

To add more domains in dns, create zone files individually for all domain as above. After that add any entry for all zones in named.conf like below. Change demotecadmin.net with your domain name.

zone "demotecadmin.net" IN {
        type master;
        file "/var/named/demotecadmin.net.db";
};

Step 5 – Start Bind Service

Start named (bind) service using following command.

# service named restart

Enable auto start on system boot.

# chkconfig named on
Step 6 – Test Your DNS Setup

Send query to your dns server directly using below command.
Syntax: nslookup <domainname> <dns server name/ip>

# nslookup demotecadmin.net 192.168.1.254 


Server:         192.168.1.254
Address:        192.168.1.254#53

Name:   demotecadmin.net
Address: 192.168.1.100

Above output is showing that dns server has successfully resolved domain demotecadmin.net.

Share it!
Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on Tumblr
Share on Whatsapp
Rahul
Rahul
Connect on Facebook Connect on Twitter

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

11 Comments

  1. Avatar UgoChukwu Reply
    January 15, 2016 at 12:13 pm

    Thanks for this tutorial. But I have few question.
    1. I have only but one IP address, will this work for me/ If yes, is/are how do I go about it?
    2. I want to enable subdomain wildcard on my site, How do I accomplish it with BIND?

  2. Avatar Govinda Ghimeray Reply
    May 27, 2015 at 3:13 pm

    hi great tutorial.
    but,
    how to setup dns for grobal access? Suppose i have abcd.com, so how can i make it xyz.abcd.com by configuring it on my own server which uses static NAT address inside NAT router?

  3. Avatar Luli Reply
    October 2, 2014 at 9:53 am

    Nice tutorial, but how does it apply in real world
    Example:
    Purchased a domain name and has access to Cpanel, there are some DNS and has ip for the website ?
    So my question is that , how l can redirect those DNS to my webserver which l own (centos) in my house , or how l can configure my DNS to host l website , because this tutorial does seem to be a help in my case !

    Thanks,

  4. Avatar Rerehja Reply
    April 11, 2014 at 4:44 pm

    I am confused as to why you have “vim /var/named/chroot/var/named/demotecadmin.net.db” for the zone file but in your named.conf you have “file “/var/named/demotecadmin.net.db”;”

    • Rahul Rahul Reply
      April 15, 2014 at 3:37 am

      Hi Rerehja,

      This is chroot environment for bind server. While running bind in chroot environment /var/named/chroot/ works as root (/) directory for bind service. It increase more security to to your dns server.

      • Avatar Rerehja Reply
        July 20, 2014 at 5:07 pm

        That is exactly why I am confused. If its supposed to be in /var/named/chroot why did you specify /var/named/demoteadmin.net/db instead of its actual location /var/named/chroot/var/named/demotecadmin.net.db

        I am sorry I am just confused, I am not understanding.

  5. Avatar Dragongang Reply
    March 1, 2014 at 8:46 am

    Many Many thanks bro….

  6. Avatar Odessa Reply
    January 9, 2014 at 12:31 pm

    Everything is very open with a very clear description of the challenges.
    It was definitely informative. Your website is very useful.

    Thanks for sharing!

  7. Avatar montre guess femme Reply
    November 1, 2013 at 7:14 am

    Grwat post. I was checking continuously this
    weblog and I’m impressed! Very useful info specifically the last
    section 🙂 I handle such information much. I was seeking this certain information for a long time.

    Thanks and best of luck.

  8. Rahul Rahul Reply
    August 27, 2013 at 2:27 pm

    Thanks Muditha,

  9. Avatar Muditha Reply
    July 22, 2013 at 11:50 am

    TX a lot for this comprehensive tutorial. I am absolute beginner for bind a website using ssh (also newbie to linux). Got the final sample output and waiting for propagating it trough the internet.
    I want to point out small mistake also. In zone file “)” is seems to be in wrong place.

    Thanks again.

Leave a Reply Cancel reply

Popular Posts

  • How to Install Python 3.9 on CentOS/RHEL 7 & Fedora 32/31 0
  • How To Install VNC Server on Ubuntu 20.04 1
  • How To Install NVM on macOS with Homebrew 0
  • (Solved) apt-add-repository command not found – Ubuntu & Debian 0
  • How to Install .NET Core on Debian 10 0
© 2013-2020 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy