Red Hat Training
A Red Hat training course is available for RHEL 8
Chapter 26. Recording DNS queries by using dnstap in RHEL
As a network administrator, you can record Domain Name System (DNS) details to analyze DNS traffic patterns, monitor DNS server performance, and troubleshoot DNS issues. If you want an advanced way to monitor and log details of incoming name queries, use the dnstap interface that records sent messages from the named service. You can capture and record DNS queries to collect information about websites or IP addresses.
Prerequisites
-
Upgrade
BINDpackages to versionbind-9.11.26-2or later.
If you already have a BIND version installed and running, adding a new version of BIND will overwrite the existing version.
Procedure
Enable
dnstapand the target file by editing the/etc/named.conffile in theoptionsblock:options { # … dnstap { all; }; # Configure filter dnstap-output file "/var/named/data/dnstap.bin"; # … }; # end of optionsTo specify which types of DNS traffic you want to log, add
dnstapfilters to thednstapblock in the/etc/named.conffile. 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 contains multiple definitions delimited by a;in thednstap {}block with the following syntax:dnstap { ( all | auth | client | forwarder | resolver | update ) [ ( query | response ) ]; … };
-
To apply your changes, restart the
namedservice:# systemctl restart named.serviceConfigure a periodic rollout for active logs
In the following example, the
cronscheduler runs the content of the user-edited script once a day. Therolloption with the value3specifies thatdnstapcan create up to three backup log files. The value3overrides theversionparameter of thednstap-outputvariable, and limits the number of backup log files to three. Additionally, the binary log file is moved to another directory and renamed, and 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 sufficient.Example: sudoedit /etc/cron.daily/dnstap #!/bin/sh rndc dnstap -roll 3 mv /var/named/data/dnstap.bin.1 /var/log/named/dnstap/dnstap-$(date -I).bin # use dnstap-read to analyze saved logs sudo chmod a+x /etc/cron.daily/dnstap
Handle and analyze logs in a human-readable format by using the
dnstap-readutility:In the following example, the
dnstap-readutility prints the output in theYAMLfile format.Example: dnstap-read -y [file-name]