Home / Server / Linux / CentOS / Primary DNS Sever Installation and Configuration in RHEL/CentOS 7

Primary DNS Sever Installation and Configuration in RHEL/CentOS 7

Today i will show you how to install and configure DNS Server step by step. I will install and configure Primary DNS Server in Linux 7 operating system.

DNS stands for Domain Name System which translates hostname or url into IP address.  For more details visit wikipedia.

For DNS Server installation and configuration needed to complete below steps:

1. RHEL 7 OS Installation
2. Yum Server Configuration
3. IP Configuration
4. Bind Package Installation
5. DNS Configuration and Check
6. Firewall Configuration
7. Reverse DNS Lookup
8. Disable IPv6 (if neededd)

In this post i will show the steps 4, 5 and 6 number. If you need you can visit my other post for details.

My Primary DNS Server Details Information:

Domain Name: www.example.com
DNS Server IP: 122.X.X.102
Fully Qualified Domain Name (FQDN): ns1.example.com

Network File:
IPADDR = 122.X.X.102
GATEWAY = 122.X.X.65
DNS = 122.X.X.102

Resolv.conf File:
search example.com
nameserver   122.X.X.102

Host File:
122.X.X.102     ns1.example.com       ns1

4. DNS/BIND Server Installation:

To install dns server we need two packages bind and bind-utils.

# yum install bind bind-utils -y
RHEL_7_Disc/productid | 1.6 kB 00:00
Verifying : 32:bind-9.9.4-14.el7.x86_64 1/2
Verifying : 32:bind-libs-9.9.4-14.el7.x86_64 2/2

bind.x86_64 32:9.9.4-14.el7

Dependency Installed:
bind-libs.x86_64 32:9.9.4-14.el7


5. DNS Server Configuration:

Caution: Please keep backup the configuration file before edition.

# cp  /etc/named.conf     /etc/named.conf.bak

Now we will edit the conf file using vim command. named.conf is the main configuration file of dns server.

# vim /etc/named.conf
options {
listen-on port 53 {; 122.X.X.102; };
#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 { any; };

zone "ns1.example.com" IN {
 type master;
 file "/var/named/fwd-example.zone";
 allow-update { none; };

zone "X.X.122.in-addr.arpa" IN {
 type master;
 file "/var/named/rev-example.zone";
 allow-update { none; };

include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";

:wq!  (Save and Quit)

In this configuration file, i only changed and added the green color text. 122.X.X.102 is the ip address of primary dns server. I disable ipv6 resolving “# listen-on-v6 port 53“.

Here i added two extra zone file information. You can add zone information in “/etc/named.rfc1912.zones” file. I added in named.conf file. These are the same things.

In the field ( zone “ns1.example.com” IN ) added FQDN of my primary dns server. And in the field ( zone “X.X.122.in-addr.arpa” IN ) added reverse zone name of my dns server. It is the important key point for right configuration of primary dns server.

Create DNS Forward Zone File:

# vim /var/named/fwd-example.zone
$TTL      1D
@   IN   SOA   ns1.example.com.    admin.example.com. (
3 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
IN           NS       ns1.example.com.
IN           A         122.X.X.102
ns1        IN         A          122.X.X.102

:wq! (Save and Quit)

Create DNS Reverse Zone File:

# vim /var/named/rev-example.zone
$TTL     1D
@      IN     SOA     ns1.example.com.      admin.example.com. (
3 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
IN          NS          ns1.example.com.
IN          A            122.X.X.102
102       IN           PTR          ns1.example.com.
:wq!  (Save and Quit)

Change the Group Ownership:

#chgrp   named      /var/named/fwd-example.zone
#chgrp   named      /var/named/rev-example.zone

Check the Group Ownership:

# ls    -l     /var/named/fwd-example.zone
-rw-r----- 1    root    named    243    Jan 14   10:17     /var/named/fwd-example.zone
# ls -l /var/named/rev-example.zone
-rw-r----- 1    root    named    211    Jan 14   10:17    /var/named/rev-example.zone

Check DNS (Bind) Configuration:

# named-checkconf     /etc/named.conf

Every changes done in bind configuration, i recommend to check the dns configuration file using the above  command. If there are no error found in config file, the above command will show nothing.

Check DNS Forword Zone File:

# named-checkzone      fwd-example.zone      /var/named/fwd-example.zone
zone fwd-example.zone/IN: loaded serial 0

Check DNS Reverse Zone File:

# named-checkzone       rev-example.zone      /var/named/rev-example.zone
zone rev-example.zone/IN: loaded serial 0

Enable and Start the Service:

Now the time to enable and start the named service using the below commands:

# systemctl    enable    named.service
# systemctl     start      named.service

6. Port Add on Firewall:

Now open firewall to allow DNS queries from external sources.

# firewall-cmd    --zone=public    --add-port=53/tcp      --permanent
# firewall-cmd    --zone=public    --add-port=53/udp     --permanent
# firewall-cmd    --reload

Finished !!!

About Shyamal

Avatar of Shyamal
Shyamal is our resident tutorial master. He has years of experience with WordPress Platform and is a professional blogger with a special interest in Social Media, Internet Marketing and Web Design. Actually, he is also working on a IT Company as a System Administrator in the fields of Linux and Windows Server, System Administration and Networking.

Check Also

disable ipv6

How to Disable IPv6 on CentOS/RHEL 7

Post describes procedure to disable IPv6 on CentOS/RHEL 7. There are 2 ways to do …

Leave a Reply

Your email address will not be published. Required fields are marked *

Advertisment ad adsense adlogger