Menu

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

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 “http://hackthesec.co.in”, 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.0.200
  • DNS Server Name: ns1.hackthesec.co.in, ns2.hackthesec.co.in
  • Domain Name: hackthesec.co.in
  • Domain IP to point: 192.168.0.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.0.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.0.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 "hackthesec.co.in" IN {
        type master;
        file "/var/named/hackthesec.co.in.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 hackthesec.co.in.db in this article.
# vim /var/named/chroot/var/named/hackthesec.co.in.db
Content for the zone file
; Zone file for hackthesec.co.in
$TTL 14400
@      86400    IN      SOA     ns1.hackthesec.co.in. webmaster.hackthesec.co.in. (
                3013040200      ; serial, todays date+todays
                86400           ; refresh, seconds
                7200            ; retry, seconds
                3600000         ; expire, seconds
                86400          ; minimum, seconds
      )
hackthesec.co.in. 86400 IN NS ns1.hackthesec.co.in.
hackthesec.co.in. 86400 IN NS ns2.hackthesec.co.in.
hackthesec.co.in. IN A 192.168.0.100
hackthesec.co.in. IN MX 0 mail.hackthesec.co.in.
mail      IN CNAME hackthesec.co.in.
www      IN CNAME hackthesec.co.in.
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 hackthesec.co.in  with your domain name.
zone "hackthesec.co.in" IN {
        type master;
        file "/var/named/hackthesec.co.in.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 hackthesec.co.in 192.168.0.200 

Server:         192.168.0.200
Address:        192.168.0.200#53

Name:   hackthesec.co.in
Address: 192.168.0.100
Above output is showing that dns server has successfully resolved domain hackthesec.co.in

About Author:


I am a Linux Administrator and Security Expert with this site i can help lot's of people about linux knowladge and as per security expert i also intersted about hacking related news.TwitterFacebook

Next
Newer Post
Previous
Older Post

0 comments:

Post a Comment

 
Top