DNS packet syslogging using iptables NFLOG, written in C++. This program parses DNS reply packets and logs the details (any combination of A, AAAA, CNAME, MX, PTR, TXT records and FORMERR, SERVFAIL, NXDOMAIN, NOTIMPL, REFUSED errors) to syslog or console (stdout).
Prebuilt .deb/.rpm packages for popular distributions can be downloaded from the Releases page.
nflog_dns requires libfmt, libtins, libnetfilter_log and libspdlog libraries
- sudo apt-get install build-essential libtins-dev libnetfilter-log-dev libspdlog-dev
- make
- sudo dnf install gcc-c++ make libpcap-devel libtins-devel libnetfilter_log-devel spdlog-devel
- make
- sudo apt-get install doctest-dev
- sudo make test
- sudo dnf install doctest-devel
- sudo make test
- Compile nflog_dns as above
- sudo ./start.sh
- sudo ./nflog_dns
- Make some DNS queries and observe the extracted DNS replies
- sudo ./stop.sh
- Compile nflog_dns as above
- Optional: Edit the PREFIX in Makefile. By default installs to /usr/local
- sudo make install
- Install nflog_dns as above
- Edit options in /etc/default/nflog_dns to suit your needs
- sudo update-rc.d nflog_dns defaults
- sudo service nflog_dns start
- Install nflog_dns as above
- Edit options in /etc/default/nflog_dns to suit your needs
- sudo systemctl enable nflog_dns.service
- sudo systemctl start nflog_dns.service
- sudo apt-get install debhelper-compat lsb-release (plus compile dependencies from above)
- make deb
- sudo dnf install rpm-build rpmdevtools (plus compile dependencies from above)
- make rpm
% nflog_dns -h
Usage: nflog_dns [OPTION]...
Extract DNS replies from NFLOG group
-g, --group=NUM NFLOG group to bind (default: 123)
-s, --syslog log replies to syslog instead of stdout
-f, --facility=FACILITY facility for syslog logging (default: user)
-l, --level=LOGLEVEL log level for syslog logging (default: info)
-h, --help print this help and exit
-v, --version show version and exit
--log-a=BOOL A record logging (default: yes)
--log-aaaa=BOOL AAAA record logging (default: yes)
--log-cname=BOOL CNAME record logging (default: yes)
--log-mx=BOOL MX record logging (default: yes)
--log-ptr=BOOL PTR record logging (default: yes)
--log-txt=BOOL TXT record logging (default: yes)
--log-noerror=BOOL NOERROR replies logging (default: yes)
--log-formerr=BOOL FORMERR error logging (default: no)
--log-servfail=BOOL SERVFAIL error logging (default: no)
--log-nxdomain=BOOL NXDOMAIN error logging (default: no)
--log-notimpl=BOOL NOTIMPL error logging (default: no)
--log-refused=BOOL REFUSED error logging (default: no)
Add an iptables rule to send packets to NFLOG group 123:
IPv4:
sudo iptables -A INPUT -p udp --sport 53 -j NFLOG --nflog-group 123IPv6:
sudo ip6tables -A INPUT -p udp --sport 53 -j NFLOG --nflog-group 123Add an nftables rule to send packets to NFLOG group 123:
sudo nft add rule inet filter input udp sport 53 log group 123A bug in libtins ip6.arpa PTR reply parsing prevents logging IPv6 reverse DNS lookups.
- Run the create_release.sh script