Configuring Quad9 on pfSense

Configuring Quad9 on pfSense

Quad9 is a DNS platform that adds a layer of security. It does this via standard DNS queries/responses. Basically, if a machine on your network queries a known bad hostname, the Quad9 DNS server responds by stating that domain does not exist (NX DOMAIN or non-existent domain). If you would like a bit more info on Quad9 including some speed benchmarks against other DNS services, I would suggest an earlier article, Quad9 – First Thoughts & Benchmarks.

This post is all about configuring, testing, and troubleshooting Quad9 on pfSense, although many of the same rules apply to nearly any firewall on the market. The DNS resolver on most pfSense distributions is unbound so this documentation was written as such.

pfSense Configuration

First things first, after logging into your firewall, go to System -> General Setup so you can change your primary and secondary DNS servers to those of Quad9. While you are there, make sure the “DNS Server Override” and “Disable DNS Forwarder” options are not checked (as shown below). Don’t forget to click ‘Save’ at the bottom.

IPv4
Primary DNS: 9.9.9.9

Secondary DNS: 149.112.112.112
IPv6
Primary DNS: 2620:fe::fe
Secondary DNS: 2620:fe::9
The secondary DNS for IPv6 is not permanent. I’ll try to update it when the change occurs, but keep an eye on the Quad 9 FAQ for the most up-to-date info. 

Warning! Do not get cute and add in a tertiary DNS *or* think you know better by adding in OpenDNS or Google as a secondary DNS for improved redundancy. If you do this, you will get unexpected results. The DNS servers are *not* queried in order as you might expect. Instead, the servers are either asked simultaneously (dnsmasq) or they flip flop who is the “primary” DNS frequently. In my testing, the Google DNS was just a titch faster so it stayed primary more often than not. In a handful of tests, the 1st query was sent and it didn’t come back fast enough so Google DNS was queried second. Surprisingly, Google DNS still answered first in some instances despite its later start. As a result, the IP address resolved as it normally would and the second/later response of NX Domain was discarded. At any rate, any DNS configuration other than what I have stated above breaks the blocking features of Quad9, which is the main reason for using it IMO.

Change pfSense DNS servers to Quad9

Next, go to the Services -> DNS Resolver and put a checkmark in the “DNS Query Forwarding” if it isn’t there already. You can leave the DNSSEC box checked too. Click ‘Save’ and then click ‘Apply Changes’ at the top.

pfSense DNS resolver

Before moving on, I would strongly suggest following the “Log Configuration” section toward the bottom of this post. While it is not 100% necessary, it will make your life easier in the future and it is highly recommended!

Testing/Troubleshooting

Below are some various ways to test your configuration whether in Linux/FreeBSD, Windows, or from the browser using the isitblocked.org domain.

Linux command line – Not working

# dig +short isitblocked.org
74.208.236.124

Linux command line –Working

# dig +short isitblocked.org

Nothing is returned above.

Windows command line – Not working

C:\Users\User>nslookup isitblocked.org
Non-authoritative answer:
Name:    isitblocked.org
Addresses:  2607:f1c0:100f:f000::2d1
          74.208.236.124

Windows command line – Working

C:\Users\User>nslookup isitblocked.org
*** can't find isitblocked.org: Server failed

Browser

Assuming your configuration is correct, from a browser the isitblocked.org domain should appear as though it is down (below). If you see anything else or your browser gets re-directed to http://www.isitblocked.org/default, then something isn’t working right.

NX DOmain firefox

More Troubleshooting – Present & Future

Either your configuration isn’t working or you realized that at some point, you’re going to need to troubleshoot a domain getting blocked and you wanted to read ahead. 😉 One way to test your new DNS configuration is via the web GUI by going to Diagnostics -> DNS Lookup. Once again, type in isitblocked.org and see the response. If you see a “could not be resolved” as shown in yellow above, congrats! The only issue? That doesn’t necessarily mean everything is working. The DNS lookup via the web GUI performs a sequential lookup of DNS servers. Remember the red warning above? Nonetheless, this can still be a useful step in your troubleshooting endeavors.

pfSense DNS lookup via web gui

For those interested, this is what the “race” looks like during a packet capture despite 9.9.9.9 being “above” 8.8.8.8 in the DNS configuration screen and getting queried first.

IP MYEXTIP.53125 > 9.9.9.9.53 <-- FIRST QUERY (TO QUAD9)
IP MYEXTIP.54417 > 8.8.8.8.53 <-- SECOND QUERY (TO GOOGLE)
IP 8.8.8.8.53 > MYEXTIP.54417 <-- FIRST RESPONSE (FROM GOOGLE)
IP 9.9.9.9.53 > MYEXTIP.53125 <-- SECOND RESPONSE (FROM QUAD9)

Log Configuration – NX Domain

What’s the best way to troubleshoot? Get familiar with your logs. Better yet, configure them properly when you first set this up. Go to Services -> DNS Resolver -> Advanced Settings and switch the default log level of 1 to 2 (or higher). Don’t forget ‘Save’ and ‘Apply Changes’ once you are done.

pfSense log level on DNS resolver

Now, you can go to your system logs (Status -> System Logs -> System -> DNS Resolver) and see every DNS query/response. Keep in mind the logs will also show which domains are returning as NXDOMAIN. Because of how Quad9 responds for malicious domain queries, you can see first-hand if any devices on your network are trying to contact known bad guys on the internet!

pfSense DNS Resolver NXDOMAIN

Leave a Reply

Your email address will not be published.