Primary DNS Server Installation and Configuration in CentOS 7

0
31

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 needed)

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
PREFIX = 26
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
Installed:
bind.x86_64 32:9.9.4-14.el7
Dependency Installed:
bind-libs.x86_64 32:9.9.4-14.el7

Complete!

5. DNS Server Configuration:

Caution: Please keep backup the configuration file before edit it.

# 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 { 127.0.0.1; 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.
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
OK

Check DNS Reverse Zone File:
# named-checkzone       rev-example.zone      /var/named/rev-example.zone
zone rev-example.zone/IN: loaded serial 0
OK

Enable and Start the Service:
Now the time to enable and start the named service using the below commands:
# systemctl    start    named.service
# systemctl     enable      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
success
# firewall-cmd    –zone=public    –add-port=53/udp     –permanent
success
# firewall-cmd    –reload
success

Finished !!!

LEAVE A REPLY

Please enter your comment!
Please enter your name here