Monday, 19 July 2021

How To Configure DNS (BIND) Server on CentOS 7



DNS (Domain Name System)/BIND (Berkeley Internet Name Domain) is most widely used DNS Server. DNS is a client server protocol that provides Domain name resolution to its associate IP address and IP address to Domain name. Its available in CentOS7 base repository.
This article describes How To Configure DNS (BIND) Server on CentOS7.
 
Step 1. Package Installation: Run the following command to install bind package:
 
[root@master-dns ~]# yum install bind bind-utils
Loaded plugins: fastestmirror
………………………..
Installed:
  bind.x86_64 32:9.11.4-26.P2.el7_9.5                                             bind-utils.x86_64 32:9.11.4-26.P2.el7_9.5
 
Dependency Installed:
  audit-libs-python.x86_64 0:2.8.5-4.el7      bind-libs.x86_64 32:9.11.4-26.P2.el7_9.5        ………………………..
 
Complete!
[root@master-dns ~]#
 
Step 2. DNS Server Configuration: Run the following command and replace the below parameter under “options” directive to run the service on local network and allow client queries:
 
[root@master-dns ~]# vi /etc/named.conf
//
// named.conf
……………………….
options {
        listen-on port 53 { 127.0.0.1; 192.168.1.103; };
………………………..
        allow-query     { localhost; 192.168.1.0/24; };
………………………..
[root@master-dns ~]#
 
Step 3. Zones Configuration: Run the following command and add/append the below lines outside of the “options” directive for DNS zones configuration:
 
Add the below parameters to include zone configuration file in bind configuration. Allow-update should be none as this is the primary DNS server:
 
[root@master-dns ~]# vi /etc/named.conf
……………………….
zone "linuxcnf.com" IN {
        type master;
        file "/etc/named/linuxcnf.forward";
        allow-update { none; };
};
 
zone "1.168.192.in-addr.arpa" IN {
        type master;
        file "/etc/named/linuxcnf.reverse";
        allow-update { none; };
};
………………………..
[root@master-dns ~]#
 
b)     Run the following command and add the below configuration to create DNS forward zone:
 
[root@master-dns ~]# vi /etc/named/linuxcnf.forward
@   IN  SOA     master-dns.linuxcnf.com. root.linuxcnf.com. (
                                                5001    ;Serial
                                                5H      ;Refresh
                                                30M     ;Retry
                                                1W      ;Expire
                                                3H      ;Minimum TTL
                                                )
 
@      IN  NS      master-dns.linuxcnf.com.
master-dns IN  A       192.168.1.103
[root@master-dns ~]#
 
c)      Run the following command and add the below configuration to create DNS reverse zone:
 
[root@master-dns ~]# vi /etc/named/linuxcnf.reverse
$TTL 1h
@       IN      SOA     1.168.192.in-addr.arpa    root.linuxcnf.com. (
                        5001            ; Serial
                        5H              ; Refresh
                        30M             ; Retry
                        1W              ; Expire
                        3H              ; Minimum TTL
                        )
 
@       IN      NS              master-dns
master-dns      IN      A       192.168.1.103
103     IN      PTR             master-dns
[root@master-dns ~]#
 
Step 4. Starting DNS Service: Run the below command to start DNS service and enable for auto start:
 
[root@master-dns ~]# systemctl enable --now named
Created symlink from /etc/systemd/system/multi-user.target.wants/named.service to /usr/lib/systemd/system/named.service.
[root@master-dns ~]#
  
[root@master-dns ~]# systemctl status named
named.service - Berkeley Internet Name Domain (DNS)
   Loaded: loaded (/usr/lib/systemd/system/named.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2021-07-18 22:09:21 IST; 8s ago
  Process: 1486 ExecStart=/usr/sbin/named -u named -c ${NAMEDCONF} $OPTIONS (code=exited, status=0/SUCCESS)
  Process: 1484 ExecStartPre=/bin/bash -c if [ ! "$DISABLE_ZONE_CHECKING" == "yes" ]; then /usr/sbin/named-checkconf -z "$NAMEDCONF"; else echo "Checking of zone files is disabled"; fi (code=exited, status=0/SUCCESS)
 Main PID: 1489 (named)
   CGroup: /system.slice/named.service
           └─1489 /usr/sbin/named -u named -c /etc/named.conf
 
………………………
Jul 18 22:09:22 master-dns.linuxcnf.com named[1489]: resolver priming query complete
[root@master-dns ~]#
  
Step 4. Firewall Configuration: Run the following command to allow DNS service in firewall:
  
[root@master-dns ~]# firewall-cmd --permanent --add-service=dns
success
[root@master-dns ~]#
 
[root@master-dns ~]# firewall-cmd --reload
success
[root@master-dns ~]#
 
Step 5. Validate Configuration: Add the DNS server IP address in /etc/resolv.conf in client machine as shown below and run dig command as given below:
 
[root@node1 ~]# vi /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.1.103
[root@node1 ~]#
 
[root@node1 ~]# dig master-dns.linuxcnf.com
 
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.5 <<>> master-dns.linuxcnf.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 5376
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
 
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;master-dns.linuxcnf.com.       IN      A
 
;; ANSWER SECTION:
master-dns.linuxcnf.com. 10800  IN      A       192.168.1.103
 
;; AUTHORITY SECTION:
linuxcnf.com.           10800   IN      NS      master-dns.linuxcnf.com.
 
;; Query time: 1 msec
;; SERVER: 192.168.1.103#53(192.168.1.103)
;; WHEN: Sun Jul 18 22:24:48 IST 2021
 
;; MSG SIZE  rcvd: 82
 
[root@node1 ~]#
 
Done!!! DNS configuration is done on CentOS7.

1 comment:

  1. Canada is an exceptionally progressed country innovatively, which is near the United States of America. Canada offers types of assistance at similarly exceptionally less expensive rates than United States of America. https://onohosting.com/

    ReplyDelete