Primary DNS Server Installation and Configuration in 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 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:
DNS Server IP: 122.X.X.102
Fully Qualified Domain Name (FQDN):

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

Resolv.conf File:
nameserver   122.X.X.102

Host File:
122.X.X.102       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 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 {; 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 “” IN {
type master;
file “/var/named/”;
allow-update { none; };

zone “” IN {
type master;
file “/var/named/”;
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 “” IN ) added domain name of my primary dns server. And in the field ( zone “” 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/
$TTL      1D
@   IN   SOA (
3 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
IN           NS
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/
$TTL     1D
@      IN     SOA (
3 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
IN          NS
102       IN           PTR

:wq!  (Save and Quit)

Change the Group Ownership:
#chgrp   named      /var/named/
#chgrp   named      /var/named/

Check the Group Ownership:
# ls    -l     /var/named/
-rw-r—– 1    root    named    243    Jan 14   10:17     /var/named/

# ls -l /var/named/
-rw-r—– 1    root    named    211    Jan 14   10:17    /var/named/

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      /var/named/
zone loaded serial 0

Check DNS Reverse Zone File:
# named-checkzone      /var/named/
zone loaded serial 0

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
# firewall-cmd    –zone=public    –add-port=53/udp     –permanent
# firewall-cmd    –reload

Finished !!!