This guide will help you in setting up a DNS server for resolving IP address to domain names and vice-versa. We will be using “named (bind)” as its the DNS version for Linux. First we need to install named Packages.
# yum -y install bind*
“*” is to say install all bind packages required
The make sure you have assigned a Static IP
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 HWADDR=00:0C:29:65:32:B2 ONBOOT=yes BOOTPROTO=static IPADDR=172.16.70.5 NETMASK=255.255.255.0 GATEWAY=172.16.70.1
Now assign a Fully Qualified Domain Name (FQDN)
# vi /etc/sysconfig/network
NETWORKING=yes HOSTNAME=dns-server.hm.local
Add host entry in hosts file
# vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 172.16.70.5 dns-server.hm.local
Assign dns server IP as the nameserver
# vi /etc/resolv.conf
search hm.local nameserver 172.16.70.5
Now we need to configure DNS config files
Edit named.conf as given below
# vi /etc/named.conf
listen-on port 53 { 172.16.70.5; }; # listen-on-v6 port 53 { ::1; }; [Disable ipv6 by putting "#"] allow-query { any; };
* allow query from all clients in the network
Now edit named.rfc1912.zones file and add forward and reverse zone file entries
# vi /etc/named.rfc1912.zones
zone "hm.local" IN { ----> Your domain name type master; file "forward.zone"; -----> Forward zone file name allow-update { none; }; }; zone "70.16.172.in-addr.arpa" IN { --------> Put in your IP Address subnet type master; file "reverse.zone"; ---------> Reverse zone file name allow-update { none; }; };
Now create new forward and reverse zone files. Create a copy of the sample zone file installed with the package.
# cp /var/named/named.localhost /var/named/forward.zone # cp /var/named/named.localhost /var/named/reverse.zone
Change group permissions of the files so that they are owned by “named”
# chgrp named /var/named/forward.zone # chgrp named /var/named/reverse.zone
Now edit forward zone file and replace IP and hostname
# vi /var/named/forward.zone
$TTL 1D @ IN SOA dns-server.hm.local. root.dns-server.hm.local. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum IN NS dns-server.hm.local. dns-server IN A 172.16.70.5 testhost1 IN A 172.16.70.6 testhost2 IN A 172.16.70.7
Now edit reverse zone file and replace IP and hostname
# vi /var/named/reverse.zone
$TTL 1D @ IN SOA dns-server.hm.local. root.dns-server.hm.local. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum IN NS dns-server.hm.local. 5 IN PTR dns-server.hm.local. 6 IN PTR testhost1.hm.local. 7 IN PTR testhost2.hm.local.
All config done and now its time to start DNS service.
# service named restart
* Might take a while to startup 1st time
Output:
[root@dns-server ~]# service named start Generating /etc/rndc.key: [ OK ] Starting named: [ OK ]
Now to verify that all is working do a nslookup with IP and domain name, either should resolve vice-versa.
Output:
[root@dns-server ~]# nslookup dns-server.hm.local Server: 172.16.70.5 Address: 172.16.70.5#53 Name: dns-server.hm.local Address: 172.16.70.5 [root@dns-server ~]# nslookup 172.16.70.5 Server: 172.16.70.5 Address: 172.16.70.5#53 5.70.16.172.in-addr.arpa name = dns-server.hm.local.
If you encounter any errors during the process, let us know via Contact Us and will get it resolved promptly.