DNS Configuration
Configure DNS (BIND) Server on RHEL-6/7

Assumptions :

Server Name: instructor.linux.com
IP ADDRESS: 192.168.0.254

Installing BIND package :

BIND stands for Berkeley Internet Name Domain is the software which provides ability to perform name to IP conversion.

# yum install bind bind-utils -y

Configuring BIND :

Configuration file of bind is /etc/named.conf, open up /etc/named.conf file.

# vim /etc/named.conf
line no    : listen-on port 53 { 127.0.0.1; 192.168.0.254; };

# Add your network in the following line, I’ve added 192.168.0.0/24, this will allow the clients from mentioned network can query the DNS for name to IP translation.

line no : allow-query { localhost; 192.168.0.0/24; };

Creating Zones :

The following is the forward zone entry in named.conf file, written for linux.com domain. Edit /etc/named.conf.

# vim /etc/named.conf
zone “.”      IN {
type hint;
file “named.ca”;
};

zone "linux.com" IN {
type master;
file "linux.com.forward.zone";
};

NOTE :
linux.com – Domain name
master – Primary DNS
linux.com.forward.zone – Forward lookup file

The following is the reverse zone entry in the named.conf file.

zone "0.168.192.in-addr.arpa" IN {
type master;
file "linux.com.reverse.zone";
};

save & exit
:wq

Check configuration file /etc/named.conf

# named-checkconf /etc/named.conf

NOTE :
0.168.192.in-addr.arpa – Reverse lookup name
master – Primary DNS
linux.com.reverse.zone – Reverse lookup file

Creating zone files:

Once zones are created in named.conf, it’s the time to create a zone files for a created zone. Default location of zone file is /var/named, if you have not mentioned full path. Create a zone file called "linux.com.forward.zone" for forward zone under /var/named.

There are some special keywords for Zone Files
A – A record
NS – Name Server
MX – Mail for Exchange
CN – Canonical Name
SOA – Start of Authority

# cd /var/named
# cp -a named.empty    linux.com.forward.zone
# vim linux.com.forward.zone
$TTL 3H

@ IN SOA instructor.linux.com. root@linux.com. (
O            ; Serial
1D          ;Refresh
1H          ;Retry
1W         ;Expire
3H )       ;Minimum

# Name Server Information
@     IN     NS     instructor.example.com.
@     IN     A        192.168.0.254

# IP address of Name Server
instructor     IN        A     192.168.0.254

# Mail exchanger
linux.com.     IN     MX 10     mail.linux.com.

# A - Record HostName To Ip Address
node1     IN     A     192.168.0.100
@            IN     A      192.168.0.100
mail       IN     A      192.168.0.150
@            IN     A       192.168.0.150

save & exit
:wq

Create a zone file called "linux.com.reverse.zone" for reverse zone under /var/named directory, create reverse pointer to the above forward zone entries.

PTR – Pointer SOA – Start of Authority

# cd /var/named
# cp -a named.empty    linux.com.reverse.zone
# vim linux.com.reverse.zone
$TTL 3H

@ IN SOA instructor.linux.com. root@linux.com. (
O            ; serial
1D          ;refresh
1H          ;retry
1W         ;expire
3H )       ;minimum

# Name Server Information
@      IN        NS            instructor.linux.com.

# Reverse lookup for Name Server
@      IN        PTR            linux.com.
254   IN        PTR            instructor.linux.com.

# PTR Record IP address to HostName
100      IN      PTR          node1.linux.com.
150      IN      PTR          mail.linux.com.

save & exit
:wq

Check zone files

# named-checkzone      linux.com       /var/named/linux.com.forward.zone
# named-checkzone      0.168.192.in-addr.arpa       /var/named/linux.com.reverse.zone

Once zone files are created, restart bind service (for RHEL 7)
# systemctl      restart      named.service

Once zone files are created, restart bind service (for RHEL 6)
#   service   named   restart

Enable it on system start up (for RHEL 7)
# systemctl      enable      named.service

Enable it on system start up (for RHEL 6)
# chkconfig    named    on

Verifying zones:

vim /etc/resolve.conf
search linux.com
nameserver 192.168.0.254

save & exit
:wq

Use the following command to verify the forward lookup, where the DNS server gives 192.168.0.254 as a ip for instructor.linux.com

# dig instructor.linux.com

Confirm the reverse lookup, where DNS server gives instructor.linux.com as a name for 192.168.0.254 It is now confirmed that both forward and reverse lookups are working fine.

# dig -x 192.168.0.254

# nslookup instructor.linux.com
# nslookup 192.168.0.254        [use these command also]