How to Set Up a Primary DNS Server with BIND on CentOS 9
CentOS 9 centos, dnsPrerequisites
- running server with CentOS 9
- root or sudo privileges
- An available domain name to configure
Step 1: Installing BIND
As always start with updating the system:
sudo yum update -y
Once updated and reboot, install BIND and its utilties
sudo yum install bind bind-utils -y
Edit the main BIND configuration file named named.conf
:
vi /etc/named.conf
Inside the configuration file, set the options for your DNS server. Below is a basic configuration snippet:
options {
listen-on port 53 { any; };
//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";
secroots-file "/var/named/data/named.secroots";
recursing-file "/var/named/data/named.recursing";
allow-query { any; };
recursion no;
dnssec-validation yes;
managed-keys-directory "/var/named/dynamic";
geoip-directory "/usr/share/GeoIP";
pid-file "/run/named/named.pid";
session-keyfile "/run/named/session.key";
include "/etc/crypto-policies/back-ends/bind.config";
};
The above settings allow the server to listen on port 53 for any incoming DNS requests and respond to queries from any source.
Step 3: Defining the Zone Files
Create forward and reverse zone definitions within the named.conf
file. These will point to the actual files that contain the DNS records.
zone "paessens.local" IN {
type master;
file "/var/named/paessens.local.zone";
};
zone "122.168.192.in-addr.arpa" IN {
type master;
file "/var/named/192.168.122.rev";
};
Be sure to replace paessens.local
with your actual domain name and adjust the reverse zone file name to reflect your network’s IP address space.
Step 4: Creating Zone Files
Create the forward zone file:
vi /var/named/paessens.local.zone
Insert the DNS records for your domain:
$TTL 86400
@ IN SOA dns.paessens.local. admin.paessens.local. (
2023010401 ;Serial
3600 ;Refresh
1800 ;Retry
604800 ;Expire
86400 ;Minimum TTL
)
;Name Server Information
@ IN NS dns.paessens.local.
;IP address for hostname
dns IN A 192.168.122.2
;Additional A Records
@ IN A 192.168.122.1
host IN A 192.168.122.3
engine IN A 192.168.122.4
Similarly, create the reverse zone file:
vi /var/named/192.168.122.rev
And define reverse mappings:
$TTL 86400
@ IN SOA dns.paessens.local. admin.paessens.local. (
2023010401 ;Serial
3600 ;Refresh
1800 ;Retry
604800 ;Expire
86400 ;Minimum TTL
)
@ IN NS dns.paessens.local.
1 IN PTR paessnes.local.
2 IN PTR dns.paessens.local.
3 IN PTR host.paessens.local.
4 IN PTR engine.paessens.local.
Step 5: Starting and Enabling BIND
After configuring BIND and setting up the zone files, start the BIND service:
systemctl start named
Enable it to run on system boot:
systemctl enable named
References