The Domain Name System (DNS) is a hierarchical distributed naming system for computers, services, or any resource connected to the internet or a private network. It associates various information with domain names assigned to each of the participating entities.
Most importantly, it translates domain names meaningful to humans into the numerical identifiers associated with networking equipment for the purpose of locating and addressing these devices worldwide.
This guide will help you to set up DNS server on CentOS 8 / RHEL 8.
THIS DOCUMENT IS ALSO AVAILABLE FOR
Assumptions
Contents
Host Name: ns1.itzgeek.local
IP Address: 192.168.0.10
Install DNS Server
BIND stands for Berkeley Internet Name Domain, a software that provides an ability to perform name to ip conversion.
yum -y install bind bind-utils
Configure DNS Server
BIND’s main configuration file is /etc/named.conf. We will use this file to configure the DNS server and define the DNS zone.
By default, BIND listens on the localhost. So, we will configure DNS servers to listen on all network interfaces or a particular interface.
Edit the /etc/named.conf file.
vi /etc/named.conf
Comment out the following line. This will enable BIND to listen to system network interfaces other than the localhost.
Listen on all IP address:
//listen-on port 53 { 127.0.0.1; }; //listen-on-v6 port 53 { ::1; };
Listen on particular IP address:
listen-on port 53 { 127.0.0.1; 192.168.0.10; };
Add your network in the following line. I’ve added 192.168.0.0/24 to allow clients from 192.168.0.0/24 network to query the DNS server for the name to ip translation.
allow-query { localhost;192.168.0.0/24; };
Create Zones
Edit /etc/named.conf file.
vi /etc/named.conf
Forward Zone
The following is the forward zone entry in named.conf file, written for the itzgeek.local domain.
zone "itzgeek.local" IN { // Domain Name type master; // Master DNS Server file "itzgeek.local.db"; // Zone File (/var/named/) allow-update { none; }; // Since master DNS, it is none };
itzgeek.local – Domain name
master – Primary DNS
itzgeek.local.db – Forward lookup file
allow-update – Since this is the master DNS, it should be none
Reverse Zone
The following is the reverse zone entry in the named.conf file.
zone "0.168.192.in-addr.arpa" IN { // Reverse Zone Name, should match with network in reverse order type master; // Master DNS Server file "192.168.0.db"; // Zone File (/var/named/) allow-update { none; }; // Since master DNS, it is none };
0.168.192.in-addr.arpa – Reverse lookup name
master – Primary DNS
192.168.0.db – Reverse lookup file
allow-update – Since this is the master DNS, it should be none
Create zone files
Now, it’s time to create a lookup file for a created zone. By default, zone lookup files are placed under /var/named directory. Create a zone file called itzgeek.local.db for the forward lookup under /var/named directory.
All domain names should end with a dot (.).
Forward Zone
There are some special keywords for Zone Files
Create a file.
vi /var/named/itzgeek.local.db
A – A record
NS – Name Server
MX – Mail for Exchange
CNAME – Canonical Name
$TTL 86400 @ IN SOA ns1.itzgeek.local. root.itzgeek.local. ( 3 ;Serial 3600 ;Refresh 1800 ;Retry 604800 ;Expire 86400 ;Minimum TTL ) ;Name Server Information @ IN NS ns1.itzgeek.local. ;IP address of Name Server ns1 IN A 192.168.0.10 ;Mail exchanger itzgeek.local. IN MX 10 mail.itzgeek.local. ;A - Record HostName To Ip Address www IN A 192.168.0.100 mail IN A 192.168.0.150 ;CNAME record ftp IN CNAME www.itgeek.local.
Whenever you update the zone files for the DNS record update, do not forget to increment the serial.
Reverse Zone
Create a zone file called 192.168.0.db for the reverse zone under /var/named directory, create a reverse pointer to the above forward zone entries.
vi /var/named/192.168.0.db
PTR – Pointer
SOA – Start of Authority
$TTL 86400 @ IN SOA ns1.itzgeek.local. root.itzgeek.local. ( 3 ;Serial 3600 ;Refresh 1800 ;Retry 604800 ;Expire 86400 ;Minimum TTL ) ;Name Server Information @ IN NS ns1.itzgeek.local. ;Reverse lookup for Name Server 10 IN PTR ns1.itzgeek.local. ;PTR Record IP address to HostName 100 IN PTR www.itzgeek.local. 150 IN PTR mail.itzgeek.local.
Whenever you update the zone files for the DNS record update, do not forget to increment the serial.
Validate DNS Server Configuration
Use named-checkconf command to validate the configuration file.
named-checkconf /etc/named.conf
If you don’t see any error, then you are good to go.
Validate the forward zone file you have created with the below command.
named-checkzone itzgeek.local /var/named/itzgeek.local.db
itzgeek.local – Domain Name
/var/named/itzgeek.local.db – Path to a zone file
Output:
zone itzgeek.local/IN: loaded serial 3 OK
The serial number mentioned in the output should match with the serial number in the zone files.
Perform the same for the reverse zone as well.
named-checkzone 0.168.192.in-addr.arpa /var/named/192.168.0.db
Output:
zone 0.168.192.in-addr.arpa/IN: loaded serial 3 OK
Start DNS Service
Once you validate DNS configurations, restart bind service.
systemctl restart named
Enable it on system startup.
systemctl enable named
DNS Record Update
Whenever you change a DNS record, do not forget to change the serial number in the zone file and reload the zone.
Change itzgeek.local & 0.168.192.in-addr.arpa with your zone names.
### Forward Zone ### rndc reload itzgeek.local ### Reverse Zone ### rndc reload 0.168.192.in-addr.arpa
Firewall
Add a firewall rule to allow DNS queries from client machines.
firewall-cmd --permanent --add-port=53/udp firewall-cmd --reload
Verify DNS Server
Visit any client machine and add a DNS server’s ip address in /etc/resolv.conf if Network Manager does not manage the network.
nameserver 192.168.0.10
If Network Manager manages the networking then place the following entry in /etc/sysconfig/network-scripts/ifcfg-eXX file.
DNS1=192.168.0.10
Restart network service.
service network restart OR systemctl restart NetworkManager
Use the following command to verify the forward lookup, where the DNS server gives 192.168.0.100 as ip for www.itzgeek.local.
dig www.itzgeek.local
Output:
; <<>> DiG 9.11.3-1ubuntu1.7-Ubuntu <<>> www.itzgeek.local
;; global options: +cmd
;; Got answer:
;; WARNING: .local is reserved for Multicast DNS
;; You are currently testing what happens when an mDNS query is leaked to DNS
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 42679
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2 ;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
; COOKIE: 99d94df91828bc8e957709ec5e13f9cd0c242970a9488a91 (good)
;; QUESTION SECTION:
;www.itzgeek.local. IN A ;; ANSWER SECTION:
www.itzgeek.local. 86400 IN A 192.168.0.100 ;; AUTHORITY SECTION:
itzgeek.local. 86400 IN NS ns1.itzgeek.local. ;; ADDITIONAL SECTION:
ns1.itzgeek.local. 86400 IN A 192.168.0.10 ;; Query time: 0 msec
;; SERVER: 192.168.0.10#53(192.168.0.10)
;; WHEN: Tue Jan 07 08:53:56 IST 2020
;; MSG SIZE rcvd: 124
Install bind-utils package to get nslookup or dig command.
Confirm the reverse lookup, where the DNS server gives www.itzgeek.local as a name for 192.168.0.100. It is now confirmed that both forward and reverse lookups are working fine.
dig -x 192.168.0.100
Output:
; <<>> DiG 9.11.3-1ubuntu1.7-Ubuntu <<>> -x 192.168.0.100 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 43305 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ; COOKIE: d36aa24edb88f8951b3fbf8c5e13fa2cbf0e3ed754a00eee (good) ;; QUESTION SECTION: ;100.0.168.192.in-addr.arpa. IN PTR ;; ANSWER SECTION: 100.0.168.192.in-addr.arpa. 86400 IN PTR www.itzgeek.local. ;; AUTHORITY SECTION: 0.168.192.in-addr.arpa. 86400 IN NS ns1.itzgeek.local. ;; ADDITIONAL SECTION: ns1.itzgeek.local. 86400 IN A 192.168.0.10 ;; Query time: 0 msec ;; SERVER: 192.168.0.10#53(192.168.0.10) ;; WHEN: Tue Jan 07 08:55:30 IST 2020 ;; MSG SIZE rcvd: 148
Conclusion
That’s All. You have successfully installed BIND on CentOS 8 / RHEL 8 as the master server. In our next article, we will see how to configure a slave DNS server on CentOS 8 / RHEL 8.