Chapter 1. Setting up and configuring a BIND DNS server
To manage Domain Name System (DNS) services, configure the BIND DNS server. BIND is fully compliant with the Internet Engineering Task Force (IETF) DNS standards and draft standards. BIND acts as a caching server for local networks and as a secondary server to ensure high availability for zones.
1.1. Configuring BIND as a caching DNS server Copy linkLink copied to clipboard!
To resolve and cache successful and failed lookup and answer requests to the same records from its cache, configure BIND as a caching DNS server. This can act as an authoritative DNS server for zones and improves the speed of DNS lookup.
Prerequisites
- You have administrative privileges.
- The IP address of the server is static.
Procedure
Install the
bindandbind-utilspackages:dnf install bind bind-utils
# dnf install bind bind-utilsCopy to Clipboard Copied! Toggle word wrap Toggle overflow If you want to run BIND in a change-root environment install the
bind-chrootpackage:dnf install bind-chroot
# dnf install bind-chrootCopy to Clipboard Copied! Toggle word wrap Toggle overflow Note that running BIND on a host with SELinux in
enforcingmode, which is default, is more secure.Edit the
/etc/named.conffile, and make the following changes in theoptionsstatement:Update the
listen-onandlisten-on-v6statements to specify on which IPv4 and IPv6 interfaces BIND should listen:listen-on port 53 { 127.0.0.1; 192.0.2.1; }; listen-on-v6 port 53 { ::1; 2001:db8:1::1; };listen-on port 53 { 127.0.0.1; 192.0.2.1; }; listen-on-v6 port 53 { ::1; 2001:db8:1::1; };Copy to Clipboard Copied! Toggle word wrap Toggle overflow Update the
allow-querystatement to configure from which IP addresses and ranges clients can query this DNS server:allow-query { localhost; 192.0.2.0/24; 2001:db8:1::/64; };allow-query { localhost; 192.0.2.0/24; 2001:db8:1::/64; };Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add an
allow-recursionstatement to define from which IP addresses and ranges BIND accepts recursive queries:allow-recursion { localhost; 192.0.2.0/24; 2001:db8:1::/64; };allow-recursion { localhost; 192.0.2.0/24; 2001:db8:1::/64; };Copy to Clipboard Copied! Toggle word wrap Toggle overflow WarningDo not allow recursion on public IP addresses of the server. Otherwise, the server can become part of large-scale DNS amplification attacks.
By default, BIND resolves queries by recursively querying from the root servers to an authoritative DNS server. However, you can configure BIND to forward queries to other DNS servers, such as the ones of your provider. In this case, add a
forwardersstatement with the list of IP addresses of the DNS servers that BIND should forward queries to:forwarders { 198.51.100.1; 203.0.113.5; };forwarders { 198.51.100.1; 203.0.113.5; };Copy to Clipboard Copied! Toggle word wrap Toggle overflow As a fall-back behavior, BIND resolves queries recursively if the forwarder servers do not respond. To disable this behavior, add a
forward only;statement.
Verify the syntax of the
/etc/named.conffile:named-checkconf
# named-checkconfCopy to Clipboard Copied! Toggle word wrap Toggle overflow If the command displays no output, the syntax is correct.
Update the
firewalldrules to allow incoming DNS traffic:firewall-cmd --permanent --add-service=dns firewall-cmd --reload
# firewall-cmd --permanent --add-service=dns # firewall-cmd --reloadCopy to Clipboard Copied! Toggle word wrap Toggle overflow Start and enable BIND:
systemctl enable --now named
# systemctl enable --now namedCopy to Clipboard Copied! Toggle word wrap Toggle overflow If you want to run BIND in a change-root environment, use the
systemctl enable --now named-chrootcommand to enable and start the service.
Verification
Use the newly set up DNS server to resolve a domain:
dig @localhost www.example.org
# dig @localhost www.example.orgCopy to Clipboard Copied! Toggle word wrap Toggle overflow ... __www.example.org.__ __86400__ IN A __198.51.100.34__ ;; Query time: __917 msec__ ...
... __www.example.org.__ __86400__ IN A __198.51.100.34__ ;; Query time: __917 msec__ ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow This example assumes that BIND runs on the same host and responds to queries on the
localhostinterface.After querying a record for the first time, BIND adds the entry to its cache.
Repeat the query from the last step:
dig @localhost www.example.org
# dig @localhost www.example.orgCopy to Clipboard Copied! Toggle word wrap Toggle overflow __www.example.org.__ __85332__ IN A __198.51.100.34__ ;; Query time: __1 msec__ ...
__www.example.org.__ __85332__ IN A __198.51.100.34__ ;; Query time: __1 msec__ ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow Because of the cached entry, further requests for the same record are faster until the entry expires.
For details, see the
named.conf(5)man page and the/usr/share/doc/bind/sample/etc/named.conffile on your system.
1.2. Configuring logging on a BIND DNS server Copy linkLink copied to clipboard!
To write different events with defined severity level to separate files, configure logging on a BIND DNS server. On the server, the BIND package configures the /etc/named.conf file to use the default_debug channel, which logs entries when debug level is non zero to the /var/named/data/named.run file.
Prerequisites
- You have already configured BIND as a caching name server.
-
You have started the
namedornamed-chrootservice.
Procedure
Edit the
/etc/named.conffile and addcategoryandchannelphrases to theloggingstatement, for example:Copy to Clipboard Copied! Toggle word wrap Toggle overflow In this example configuration
-
BIND logs messages related to zone transfers to
/var/named/log/transfer.log. - BIND creates up to 10 versions of the log file and rotates them if they reach a maximum size of 50 MB.
-
The
categoryphrase defines to which channels BIND sends messages of a category. -
The
channelphrase defines the destination of log messages including the number of versions, the maximum file size, and the severity level BIND should log to a channel. Additional settings, such as enabling logging the timestamp, category, and severity of an event are optional, but useful for debugging purposes.
-
BIND logs messages related to zone transfers to
Create the log directory if it does not exist and grant write permissions to the
nameduser on this directory:mkdir /var/named/log/ chown named:named /var/named/log/ chmod 700 /var/named/log/
# mkdir /var/named/log/ # chown named:named /var/named/log/ # chmod 700 /var/named/log/Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify the syntax of the
/etc/named.conffile:named-checkconf
# named-checkconfCopy to Clipboard Copied! Toggle word wrap Toggle overflow If the command displays no output, the syntax is correct.
Restart BIND:
systemctl restart named
# systemctl restart namedCopy to Clipboard Copied! Toggle word wrap Toggle overflow If you run BIND in a change-root environment, use the
systemctl restart named-chrootcommand to restart the service.
Verification
Display the content of the log file:
cat /var/named/log/transfer.log
# cat /var/named/log/transfer.logCopy to Clipboard Copied! Toggle word wrap Toggle overflow ... __06-Jul-2022 15:08:51.261 xfer-out: info: client @0x7fecbc0b0700 192.0.2.2#36121/key example-transfer-key (example.com): transfer of 'example.com/IN': AXFR started: TSIG example-transfer-key (serial 2022070603)__ __06-Jul-2022 15:08:51.261 xfer-out: info: client @0x7fecbc0b0700 192.0.2.2#36121/key example-transfer-key (example.com): transfer of 'example.com/IN': AXFR ended__
... __06-Jul-2022 15:08:51.261 xfer-out: info: client @0x7fecbc0b0700 192.0.2.2#36121/key example-transfer-key (example.com): transfer of 'example.com/IN': AXFR started: TSIG example-transfer-key (serial 2022070603)__ __06-Jul-2022 15:08:51.261 xfer-out: info: client @0x7fecbc0b0700 192.0.2.2#36121/key example-transfer-key (example.com): transfer of 'example.com/IN': AXFR ended__Copy to Clipboard Copied! Toggle word wrap Toggle overflow For details, see the
named.conf(5)man page on your system.
1.3. Writing BIND access control lists Copy linkLink copied to clipboard!
To prevent unauthorized access and attacks, such as denial of service (DoS), you can control access to certain features of BIND by using access control list (ACL) statements. ACL statements are lists of IP addresses and ranges.
BIND uses only the first matching entry in an ACL. For example, if you define an ACL { 192.0.2/24; !192.0.2.1; } and the host with IP address 192.0.2.1 connects, BIND grants access even if the second entry excludes this address.
Each ACL has a nickname that you can use in several statements, such as allow-query, which refers to the specified IP addresses and ranges. BIND has the following built-in ACL statements:
-
none: Matches no hosts. -
any: Matches all hosts. -
localhost: Matches the loopback addresses127.0.0.1and::1, and the IP addresses of all interfaces on the server that runs BIND. -
localnets: Matches the loopback addresses127.0.0.1and::1, and all subnets the server that runs BIND is directly connected to.
Prerequisites
- You have configured BIND as a caching name server.
-
The
namedornamed-chrootservice is running.
Procedure
Edit the
/etc/named.conffile and make the following changes:Add
aclstatements to the file. For example, to create an ACL namedinternal-networksfor127.0.0.1,192.0.2.0/24, and2001:db8:1::/64, enter:acl internal-networks { 127.0.0.1; 192.0.2.0/24; 2001:db8:1::/64; }; acl dmz-networks { 198.51.100.0/24; 2001:db8:2::/64; };acl internal-networks { 127.0.0.1; 192.0.2.0/24; 2001:db8:1::/64; }; acl dmz-networks { 198.51.100.0/24; 2001:db8:2::/64; };Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use the nickname for the ACL in statements that support them, for example:
allow-query { internal-networks; dmz-networks; }; allow-recursion { internal-networks; };allow-query { internal-networks; dmz-networks; }; allow-recursion { internal-networks; };Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verify the syntax of the
/etc/named.conffile:named-checkconf
# named-checkconfCopy to Clipboard Copied! Toggle word wrap Toggle overflow If the command displays no output, the syntax is correct.
Reload BIND:
systemctl reload named
# systemctl reload namedCopy to Clipboard Copied! Toggle word wrap Toggle overflow If you run BIND in a change-root environment, use the
systemctl reload named-chrootcommand to reload the service.
Verification
Execute an action that triggers a feature, which uses the configured ACL. For example, the ACL allows only recursive queries from the defined IP addresses. In this case, enter the following command on a host that is not within the definition of ACL to try to resolve an external domain:
dig +short @192.0.2.1 www.example.com
# dig +short @192.0.2.1 www.example.comCopy to Clipboard Copied! Toggle word wrap Toggle overflow If the command returns no output, access denied for BIND, and the ACL works.
Display output on a client, use the last command without the
+shortoption:dig @192.0.2.1 www.example.com
# dig @192.0.2.1 www.example.comCopy to Clipboard Copied! Toggle word wrap Toggle overflow ... ;; WARNING: recursion requested but not available ...
... ;; WARNING: recursion requested but not available ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow
1.4. Recording DNS queries by using dnstap Copy linkLink copied to clipboard!
To analyze Domain Name System (DNS) traffic patterns, monitor DNS server performance and troubleshoot related issues, record DNS details by using the dnstap interface. To monitor and log incoming name queries for collecting website and IP address details, dnstap records messages sent by the named service.
Prerequisites
- You have administrative privileges.
-
You have installed the
bindpackage.
If you already have a BIND version installed and running, adding a new version of BIND overwrites the existing version.
Procedure
Enable
dnstapand the target file in theoptionsblock of the/etc/named.conffile:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add
dnstapfilters to thednstapblock in the/etc/named.conffile to specify which types of DNS traffic you want to log. You can use the following filters:-
auth: Authoritative zone response or answer. -
client: Internal client query or answer. -
forwarder: Forwarded query or response from it. -
resolver: Iterative resolution query or response. -
update: Dynamic zone update requests. -
all: Any from the above options. queryorresponse: If you do not specify aqueryor aresponsekeyword,dnstaprecords both.NoteThe
dnstapfilter has several definitions delimited by a semicolon (;) in thednstap {}block with the following syntax:dnstap { ( all | auth | client | forwarder | resolver | update ) [ ( query | response ) ]; … };
-
Change the
dnstap-outputoption by adding additional parameters to customize the behavior of thednstaputility on the recorded packets:-
size(unlimited | <size>): Enable automatic rolling over of thednstapfile when its size reaches the specified limit. -
versions(unlimited | <integer>): Specify the number of automatically rolled files to keep. suffix(increment | timestamp ): Choose the naming convention for rolled out files. By default, the increment starts with.0. However, you can use the UNIX timestamp by setting thetimestampvalue.The following example requests
authresponses only,clientqueries, and both queries and responses of dynamicupdates:Example: dnstap {auth response; client query; update;};Example: dnstap {auth response; client query; update;};Copy to Clipboard Copied! Toggle word wrap Toggle overflow
-
To apply your changes, restart the
namedservice:systemctl restart named.service
# systemctl restart named.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow Configure a periodic rollout for active logs:
sudoedit /etc/cron.daily/dnstap
# sudoedit /etc/cron.daily/dnstapCopy to Clipboard Copied! Toggle word wrap Toggle overflow Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
The
cronscheduler runs the contents of the user-edited script only one time in a day. -
The
rolloption with the value3specifies thatdnstapcan create up to three backup log files. -
The value
3overrides theversionparameter of thednstap-outputvariable. This value limits the number of backup log files to three. Also, this option moves the binary log file to another directory and renames it. It never reaches the.2suffix, even if three backup log files already exist. - You can skip this step if automatic rolling of binary logs based on size limit is enough.
-
The
Use the
dnstap-readutility to read and print output logs in a human-readable format such as aYAMLfile:dnstap-read -p /var/named/data/dnstap.bin
# dnstap-read -p /var/named/data/dnstap.binCopy to Clipboard Copied! Toggle word wrap Toggle overflow