DNSDB Blocklist (DNSBL) Tutorial
With rbldnsd and BIND 9.9 on Debian 8.x
A DNS Black List (DNSBL) can be used to convey information about IP addresses or hostnames over DNS. Mail Servers and Anti-Spam software can be configured to leverage a DNSBL to make delivery or scoring decisions.
This tutorial demonstrates how to:
- Configure a Caching Nameserver using BIND 9.9.x
- Configure rbldnsd to serve the DNSBL zone v1.bl.dns-nod.net
- Configure BIND to forward queries for the zone v1.bl.dns-nod.net to rbldnsd
- Configure rbldnsd to load the Farsight NOD DNSBL dataset
Requirements
Section titled “Requirements”- Debian 8.x
- root or sudo privileges
- Provisioned for NOD DNSBL by Farsight Security
- A username provided by Farsight Security
- Firewall: Outbound TCP port 49222 to rsync.dns-nod.net:
- 104.244.13.85
- 216.66.15.100
- 104.244.14.85
- 216.156.194.100
- A 4096 bit SSH key pair
- The IP address(es) of the host that will be connecting to Farsight Security
Prerequisites
Section titled “Prerequisites”- Start with a clean install of Debian 8.x. For testing purposes a virtual machine with 1 CPU and 1GB of memory would be adequate.
- A NOD DNSBL username provided by Farsight Security
Setup Instructions
Section titled “Setup Instructions”NOD user account and associated SSH key
Section titled “NOD user account and associated SSH key”During the provisioning process of NOD DNSBL you will be asked to provided Farsight Security with a public SSH key and an IP address. You can complete these steps prior to the provisioning process to be prepared to provide a public SSH key to Farsight Security.
Create a user account named nod
Section titled “Create a user account named nod”$ sudo adduser nod --disabled-password --gecos GECOSCreate an SSH key pair
Section titled “Create an SSH key pair”Become the nod user to create an SSH key pair associated with the nod user account that will ultimately used with SSH and rsync
$ sudo su - nodCreate an SSH key
Section titled “Create an SSH key”Create an SSH key to be used to connect to Farsight Security resources. Do not create a password for the SSH key.
ssh-keygen -t rsa -b 4096 -C farsight_security -f /home/nod/.ssh/farsight_securityProvide the public ssh key
Section titled “Provide the public ssh key”During the provisioning process with Farsight Security you will be asked to provide the public ssh key. Example:
$ cat /home/nod/.ssh/farsight_security.pubLog out of the nod user
Section titled “Log out of the nod user”$ logoutInstall and configure BIND 9
Section titled “Install and configure BIND 9”This tutorial uses BIND as a recursive caching server and a forwarding server.
Install BIND 9
Section titled “Install BIND 9”$ sudo apt-get update$ sudo apt-get install bind9 bind9utils bind9-docConfigure BIND to be a recursive caching DNS Server
Section titled “Configure BIND to be a recursive caching DNS Server”$ sudo vim /etc/bind/named.conf.optionsAdd a ACL to allow recursive queries. Choose a CIDR range that makes sense for your organization.
acl localnetwork { 192.168.0.0/16; localhost; localnets;};Add the following within options directive
recursion yes;allow-query { localnetwork; };named.conf.options should look like:
acl allowrecursion { 192.168.0.0/16; localhost; localnets;};
options { directory "/var/cache/bind";
recursion yes; allow-query { localnetwork; };
dnssec-validation auto;
auth-nxdomain no; # conform to RFC1035 listen-on-v6 { any; };};Configure BIND to forward queries
Section titled “Configure BIND to forward queries”Configure BIND to forward queries for the zone v1.bl.dns-nod.net to rbldnsd running on port 5053.
$ sudo vim /etc/bind/named.conf.localadd:
zone "v1.bl.dns-nod.net" IN { type forward; forward first; forwarders { ::1 port 5053; };};Check the syntax of the BIND configuration files
Section titled “Check the syntax of the BIND configuration files”Check the syntax of the BIND configuration files. The shell prompt will return immediately without any output if there are no errors.
sudo named-checkconfRestart BIND
Section titled “Restart BIND”sudo systemctl restart bind9Verify BIND is listening on localhost
Section titled “Verify BIND is listening on localhost”Verify BIND is listening on localhost and is working as a caching server
$ dig @localhost indiana.edu
; <> DiG 9.9.5-9+deb8u6-Debian <> @localhost indiana.edu; (2 servers found);; global options: +cmd;; Got answer:;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 30876;; flags: qr rd ra ad; QUERY: 1, ANSWER: 2, AUTHORITY: 3, ADDITIONAL: 6
;; OPT PSEUDOSECTION:; EDNS: version: 0, flags:; udp: 4096;; QUESTION SECTION:;indiana.edu. IN A
;; ANSWER SECTION:indiana.edu. 3534 IN A 129.79.78.193indiana.edu. 3534 IN A 129.79.78.192
;; AUTHORITY SECTION:indiana.edu. 3534 IN NS dns1.illinois.edu.indiana.edu. 3534 IN NS dns1.iu.edu.indiana.edu. 3534 IN NS dns2.iu.edu.
;; ADDITIONAL SECTION:dns1.iu.edu. 172734 IN A 134.68.220.8dns1.illinois.edu. 172734 IN A 130.126.2.100dns1.illinois.edu. 172734 IN AAAA 2620:0:e00:b::53dns2.iu.edu. 172734 IN A 129.79.1.8dns2.iu.edu. 172734 IN AAAA 2001:18e8:2:8::10
;; Query time: 4 msec;; SERVER: ::1#53(::1);; WHEN: Mon Jun 20 14:12:04 EDT 2016;; MSG SIZE rcvd: 245Note: ;; Server: ... should be the localhost ip address
Install rsync
Section titled “Install rsync”Configure rsync to download the NOD rbldns data files
Section titled “Configure rsync to download the NOD rbldns data files”Become the nod user to setup rsync
Section titled “Become the nod user to setup rsync”$ sudo apt-get install rsync$ sudo su - nodCreate an SSH configuration file
Section titled “Create an SSH configuration file”Create a SSH configuration file to be used with the rsync process
$ vim /home/nod/.ssh/configCopy and paste the following, be sure to replace username with the username given to you by Farsight Security.
Host rsync.dns-nod.netUserIdentityFile ~/.ssh/farsight_securityHostKeyAlias rsync.dns-nod.netPort 49222Create directories
Section titled “Create directories”Create a directories to store the NOD DNSBL files and binaries
$ mkdir -p data/nod/v1$ ls -l /home/nod/total 8drwxr-xr-x 2 nod nod 4096 Jun 21 13:34 bindrwxr-xr-x 3 nod nod 4096 Jun 21 13:33 dataCreate a bin directory in /home/nod
Section titled “Create a bin directory in /home/nod”$ mkdir /home/nod/bin/bash script
Section titled “bash script”Create a bash script in /home/nod/bin to rsync the NOD DNSBL data from Farsight Security. This script uses /usr/bin/flock to ensure there are not multiple rsync commands running concurrently.
$ vim /home/nod/bin/nod-rsync.shCopy and paste the following
#!/bin/bash
set -e
/usr/bin/flock -n /home/nod/bin -c "/usr/bin/rsync -tq -e ssh --timeout=10 -az \ rsync.dns-nod.net:nod/v1/nod.rbldnsd /home/nod/data/nod/v1"Populate the SSH known_hosts file
Section titled “Populate the SSH known_hosts file”Populate the SSH known_hosts file with fingerprints for rsync.dns-nod.net
ssh-keyscan -H -t rsa,dsa -p 49222 rsync.dns-nod.net >> /home/nod/.ssh/known_hostsTest the rsync shell script
Section titled “Test the rsync shell script”$ /bin/bash /home/nod/bin/nod-rsync.shVerify nod.rbldnsd was fetched correctly
Section titled “Verify nod.rbldnsd was fetched correctly”$ head -n 9 /home/nod/data/nod/v1/nod.rbldnsd# Newly-Observed Domains List# (c) 2016 Farsight Security Inc. https://www.farsightsecurity.com# All rights reserved.# Sales inquiries to sales@domaintools.com# Technical support requests to enterprisesupport@domaintools.com# Published by nod2 running version 1.26.0 at 2016-06-30T12:51:55.294865+00:00$SOA 86400 a.ns.dns-nod.net nod-admin.fsi.io. 1467291115 600 300 86400 300$TIMESTAMP 2016:06:30:12:51:55# $NS 86400 a.ns.dns-nod.net b.ns.dns-nod.netLog out of the nod user again
Section titled “Log out of the nod user again”logoutCreate a cron job to run the rsync script every minute
Section titled “Create a cron job to run the rsync script every minute”$ sudo vim /etc/cron.d/nod-rsyncCopy and paste the following
#!/bin/sh# /etc/cron.d/nod-rsync: Farsight NOD rsync script
* * * * * nod /bin/bash /home/nod/bin/nod-rsync.shUpdate the permissions of the file
$ sudo chmod 755 /etc/cron.d/nod-rsyncInstall and configure rbldnsd
Section titled “Install and configure rbldnsd”Install rbldnsd
Section titled “Install rbldnsd”$ sudo apt-get install rbldnsdConfigure rbldnsd
Section titled “Configure rbldnsd”$ sudo vim /etc/default/rbldnsdCopy and paste the following to the bottom of the file:
RBLDNSD="rbldnsd -r/home/nod/data/nod/v1/ -b::1/5053 v1.bl.dns-nod.net:dnset:nod.rbldnsd"Start rbldnsd
Section titled “Start rbldnsd”sudo /etc/init.d/rbldnsd startTest rbldnsd
Section titled “Test rbldnsd”Test rbldnsd to verify it is serving Farsight NOD DNSBL data correctly.
$ dig @localhost -p 5053 8.test.dns-nod.net.v1.bl.dns-nod.net; <> DiG 9.9.5-9+deb8u6-Debian <> @localhost -p 5053 8.test.dns-nod.net.v1.bl.dns-nod.net; (2 servers found);; global options: +cmd;; Got answer:;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 23971;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0;; WARNING: recursion requested but not available
;; QUESTION SECTION:;8.test.dns-nod.net.v1.bl.dns-nod.net. IN A
;; ANSWER SECTION:8.test.dns-nod.net.v1.bl.dns-nod.net. 300 IN A 127.0.0.8
;; Query time: 3 msec;; SERVER: ::1#5053(::1);; WHEN: Thu Jun 30 18:12:36 EDT 2016;; MSG SIZE rcvd: 70Test BIND
Section titled “Test BIND”Test BIND to verify it is forwarding the v1.bl.dns-nod.net zone correctly.
$ dig @localhost 8.test.dns-nod.net.v1.bl.dns-nod.net; <> DiG 9.9.5-9+deb8u6-Debian <> @localhost 8.test.dns-nod.net.v1.bl.dns-nod.net; (2 servers found);; global options: +cmd;; Got answer:;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 39141;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 13, ADDITIONAL: 16
;; OPT PSEUDOSECTION:; EDNS: version: 0, flags:; udp: 4096;; QUESTION SECTION:;8.test.dns-nod.net.v1.bl.dns-nod.net. IN A
;; ANSWER SECTION:8.test.dns-nod.net.v1.bl.dns-nod.net. 300 IN A 127.0.0.8
;; AUTHORITY SECTION:......Troubleshooting
Section titled “Troubleshooting”You should see messages like this in /var/log/syslog if rsync and rbldnsd are configured correctly
Jul 1 09:27:01 deb-nod CRON[794]: (nod) CMD (/bin/bash /home/nod/bin/nod-rsync.sh)Jul 1 09:27:54 deb-nod rbldnsd[464]: dnset:nod.rbldnsd: 20160701 132700: e/w=320407/320399Jul 1 09:27:55 deb-nod rbldnsd[464]: zones reloaded, time 0.49e/0.47u sec, mem arena=13612 free=139 mmap=10016 Kb