Friday, 6 December 2013

How to configure DNS server in centOS 6.5

Hello ... Friends Today we are going to discus about DNS server. DNS ( Domain Name System )  is a server, which translates hostname or URLs into IP addresses. for examples if we typing www.techtecno2u.com in browser then our this DNS server translates this domain name into its associated IP address. as we are unable to remembers various IP addresses so we convert this IP address into our hostnameso that easy to remembers as www.techtecno2u.com to  69.xxx.xx.xx

here we are going to setup both master & slave DNS server
So let's start
prerequisite :  
1. Hostname
2. Static IP 
3. DNS entry in resolv.conf file ( /etc/resolv.conf )
To setup hostname we have two methods :
1. temporary (by using command as hostname new_hostname )
2. permanent (by editing /etc/sysconfig/network file )


as you can see null.nullportlinux.com is my Hostname

To satisfy our second conditions i recommend you to see my post on
DHCP server configurations

To set DNS entry in resolv.conf file edit "/etc/resolv.conf"



Note: if you are facing with a problem like nameserver changes again & again at each startup of OS then this issue is due to NetworkManager auto creates resolv.conf as is in above img. so due to this issue we are facing with a problem that our DNS Server not able to resolve the nameserver bcz our nameserver is change again & again. so How to avoid this issue ...

Disable this NetworkManager behavior run these commands
# /etc/init.d/NetworkManager stop
# /sbin/chkonfig NetworkManager off
and also in  /etc/sysconfig/network-script/ifcfg-eth1 adjust NM_CONTROLLED to NO

Let's now setup DNS Server
for DNS server setup we need bind package
here we can config Bind server as :

1. Master DNS server or we can say Primary bind DNS Server
2. Slave DNS server or we can say Secondry bind DNS Server

So let's we config Master DNS server first ....

here i am using :
OS             : CentOS 6.5
hostname   : null.nullportlinux.com
IP Address : 192.168.56.101

Step 1: First  we need to install bind package by yum installation # yum install bind* -y 



now  # chkconfig named on

Step 2: Next we need to configure Master DNS Server or primary DNS Server open up named.conf file in your vi editor or as you wish use can use nano or other editor too
# vi /etc/named.conf

make change in named.conf file as :



listen-on port 53 { 192.168.56.101; };  ## Master DNS IP Replace it with your IP address ##
listen-on-v6 port 53 { ::1; };  ##comment this line ##
allow-query  {  any; };         ## IP Range ##


Step:3 add forward zone & reverse zone at the end of the config file as


forward zone :

zone "nullportlinux.com" IN {       ##your domain ##   
              type master;
              file "forward.zone";   ## forward zone file ##
              allow-update { none; };
};

Reverse Zone :

zone "101.56.168.192.in-addr.arpa" IN {    ## edit as reverse of your IP ##
            type master;
            file "reverse.zone";  ## reverse zone file ##
            allow-update  { none; };
};

Save & close the named.conf file

or 

we can edit in /etc/named.rfc1912.zones file too

forward zone :

zone "nullportlinux.com" IN {       ##your domain ##   
              type master;
              file "forward.zone";   ## forward zone file ##
              allow-update { none; };
};

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

Reverse Zone :

zone "101.56.168.192.in-addr.arpa" IN {    ## edit as reverse of your IP ##
            type master;
            file "reverse.zone";  ## reverse zone file ##
            allow-update  { none; };
};

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

as from above we can see that our forward.zone is similar to file named.localhost
and reverse.zone is similar to file named.looback

So now Let's create these file according to our upper observation 

Step 4: Create zone file 
A ] Creating forward.zone

to create "forward.zone" file in the "/var/named" directory just cp named.localhost file & edit it as our requirements by command  # cp /var/named/named.localhost /var/named/forward.zone

& edit it as
as you know null.nullportlinux.com is our hostname



B ] Creating reverse.zone

to create "reverse.zone" file in the "/var/named" directory just cp named.localhost file & edit it as our requirements by command  # cp /var/named/named.loopback /var/named/reverse.zone

& edit it as


Step 5: next we need to set group permissions for the files as

# chgrp named /var/named/forward.zone
# chgrp named /var/named/reverse.zone




Now start the named service
# service named start# chkconfig --levels 235 named on or chkconfig named on 

Note: if there are any issue here too then check your firewall Rules in iptable open file /etc/sysconfig/iptables edit these lines & save iptables

iptables -I INPUT  -p tcp  -m start --state NEW --dport 53 -j ACCEPT
iptables -I INPUT  -p udp -m start --state NEW --dport 53 -j ACCEPT

Step 6: Reboot your Machine & test for proper working by dig command


ok you can see our server is running on 192.168.56.101 

Step 7: you can check it by running nslookup commands as


thnx friends njoy 

3 comments:

Post a Comment