How to Configure DNS Name Server on RHEL7 / CentOS7



How to Configure DNS Name Server on RHEL7 / CentOS7

This article is a quick step by step procedure to show you How to Configure DNS Name Server on RHEL7 / CentOS7 using bind.

If you are interested in learning, Request you to go through the below recommended tutorial.

What is DNS (Domain Name System) and Why do we use it?

DNS provides the resolution of hostnames to IP address and Vice versa.

When some one tries to access any websites or any servername, example www.learnitguide.net, request will go to the particular server by resolving the name www.learnitguide.net to the particular server ipaddress 192.168.2.10 as configured in DNS name server. This is called Forward zone name resolution.

Same can be done in reverse way as IP Address 192.168.2.10 will resolve to the server name www.learnitguide.net, this is called Reverse zone name resolution.

Lab Server Setup:

DescriptionServer InfoClient Info
Operating SystemRHEL7 - 64 BitRHEL7 - 64 Bit
Host Namelinux1.learnitguide.netlinux2.learnitguide.net
IP Address192.168.2.10192.168.2.20
PackageBind9Not required
Service NameNamedNot required

How to Configure DNS Name Server on RHEL7 / CentOS7


Server end configuration:

Step 1: Installing DNS Packages bind

Install the appropriate DNS packages bind9 using yum to avoid dependencies issue. if yum is not configured, please refer the link http://www.learnitguide.net/2015/07/how-to-configure-local-yum-repo-server.html
[root@linux1 ~]# yum -y install bind*

Step 2: Edit the main configuration file.

Open the /etc/named.conf and append the below configuration.
zone "learnitguide.net" IN {
type master;
file "learnitguide.net.forward";
};
zone "2.168.192.in-addr.arpa" IN {
type master;
file "learnitguide.net.reverse";
};
This entries tells the DNS service which domains we are hosting here. The first zone statement for forward zone and the second zone statement for reverse zone.

According to the file names, we have to create two zone files under /var/named/ which is given in detail in Step 3.

Change the below values in the same configuration file /etc/named.conf and save the changes, else your client will not able to listen or query.
listen-on port 53 { 127.0.0.1; };
allow-query     { localhost; };

to
listen-on port 53 { any; };
allow-query     { any; };

Verify the configuration file for any errors using the command named-checkconf
[root@linux1 ~]# named-checkconf

Step 3: Create Forward and Reverse zone files

Now have to set up the two zone files as declared in the main configuration file /etc/named.conf to where its pointing to.

Go to the default zone files directory /var/named and create/copy the forward and reverse zone files.
[root@linux1 ~]# cd /var/named/
[root@linux1 named]# cp -rf named.localhost learnitguide.net.forward
[root@linux1 named]# cp -rf named.loopback learnitguide.net.reverse

Change the ownership of the files as "root:named".
[root@linux1 named]# chown root:named learnitguide.net.*

Edit the learnitguide.net.forward file for forward zone and add the client servers name, here we add only one node linux2 for testing.
[root@linux1 named]# vi learnitguide.net.forward
$TTL 1D
@       IN SOA  @ root.learnitguide.net. (
0       ; serial
1D      ; refresh
1H      ; retry
1W      ; expire
3H )    ; minimum
NS      @
A       192.168.2.10
linux1  A       192.168.2.10
linux2  A       192.168.2.20

Edit the learnitguide.net.forward file for forward zone and add the client servers ip address last digit number, here we add only one node "20" for testing.
[root@linux1 named]# vi learnitguide.net.reverse
$TTL 1D
@       IN SOA  @ root.learnitguide.net. (
0       ; serial
1D      ; refresh
1H      ; retry
1W      ; expire
3H )    ; minimum
NS      @
A       192.168.2.10
10      PTR     linux1
20      PTR     linux2

Step 4: Start DNS service and check the status for any errors
[root@linux1 named]# systemctl start named
[root@linux1 named]# systemctl status named
named.service - Berkeley Internet Name Domain (DNS)
Loaded: loaded (/usr/lib/systemd/system/named.service; disabled)
Active: active (running) since Mon 2015-11-02 11:34:46 EST; 3s ago
Process: 3059 ExecStart=/usr/sbin/named -u named $OPTIONS (code=exited, status=0/SUCCESS)
Process: 3058 ExecStartPre=/usr/sbin/named-checkconf -z /etc/named.conf (code=exited, status=0/SUCCESS)
Main PID: 3062 (named)
CGroup: /system.slice/named.service
└─3062 /usr/sbin/named -u named
Nov 02 11:34:46 linux1.learnitguide.net named[3062]: zone 0.in-addr.arpa/IN: loaded ...0
Nov 02 11:34:46 linux1.learnitguide.net named[3062]: zone 1.0.0.127.in-addr.arpa/IN:...0
Nov 02 11:34:46 linux1.learnitguide.net named[3062]: zone 1.0.0.0.0.0.0.0.0.0.0.0.0....0
Nov 02 11:34:46 linux1.learnitguide.net named[3062]: zone localhost/IN: loaded serial 0
Nov 02 11:34:46 linux1.learnitguide.net named[3062]: zone learnitguide.net/IN: loade...0
Nov 02 11:34:46 linux1.learnitguide.net named[3062]: zone 2.168.192.in-addr.arpa/IN:...0
Nov 02 11:34:46 linux1.learnitguide.net named[3062]: zone localhost.localdomain/IN: ...0
Nov 02 11:34:46 linux1.learnitguide.net named[3062]: all zones loaded
Nov 02 11:34:46 linux1.learnitguide.net named[3062]: running
Nov 02 11:34:46 linux1.learnitguide.net systemd[1]: Started Berkeley Internet Name D....
Hint: Some lines were ellipsized, use -l to show in full.
[root@linux1 named]#

Step 5: Verification of the name server resolution.

Use nslookup command to verify the resolution of each servers added in zone files.
[root@linux1 named]# nslookup linux1.learnitguide.net
Server: 127.0.0.1
Address: 127.0.0.1#53
Name: linux1.learnitguide.net
Address: 192.168.2.10
[root@linux1 named]# nslookup linux2.learnitguide.net
Server: 127.0.0.1
Address: 127.0.0.1#53
Name: linux2.learnitguide.net
Address: 192.168.2.20

That's it for server end configuration. Lets do it on client end.

Client end configuration:

Step 1: Edit the resolution file /etc/resolv.conf and add the domain, name server details as below
domain learnitguide.net
nameserver 192.168.2.10

Save and exit the file.

Step 2: Verification of the name server resolution.
[root@linux2 yum.repos.d]# nslookup linux1
Server: 192.168.2.10
Address: 192.168.2.10#53
Name: linux1.learnitguide.net
Address: 192.168.2.10
[root@linux2 yum.repos.d]# nslookup linux2
Server: 192.168.2.10
Address: 192.168.2.10#53
Name: linux2.learnitguide.net
Address: 192.168.2.20

That's all, we are able to resolve the server names from client successfully. Same way we have to add all our infrastructure servers in the zone files.

Keep practicing and have fun. Leave your comments if any.

Support Us: Share with your friends and groups.

Stay connected with us on social networking sites, Thank you.

Post a Comment

1 Comments

  1. […] nodes for name resolution in /etc/hosts file or configure the nodes in DNS. Refer this link to configure the DNS Server on RHEL7 / CentOS7.3. Yum repo enabled, refer this link to Configure YUM Repo Server on Linux.4. Internet […]

    ReplyDelete