DNS blocking, seen from the terminal

· PM-mirror


On November 24, Quad9 stops answering DNS queries from France. A Paris court fined the Swiss non-profit for refusing to block a list of pirate sports-streaming domains, about twenty similar cases are still pending, and leaving the country was the only way out it could afford. Tech Stackups wrote the long version of this story: the law behind it, the rulings, why resolvers are a poor place to fight piracy and where the rest of Europe is heading. It's the place to start.

This post is the hands-on half. If a court can order a resolver to lie, it pays to know which resolver is answering, what a lie looks like when it comes back, and how to stop depending on somebody else's resolver at all. Everything below works on Linux, and most of it on macOS and Windows too.

Who answers when a name is typed #

When a browser opens example.com, the computer doesn't look for the address on its own. A small part of the operating system, the stub resolver, passes the question to a recursive resolver: the ISP's, the one in the router, or a public one like 9.9.9.9 or 1.1.1.1. The recursive resolver does the actual work. It asks a root server who runs .com, asks the .com servers who runs example.com, asks that domain's own servers for the address, keeps the answer in its cache for a while and hands it back.

That middle box is where blocking happens. The pirate site keeps its address and its own servers keep giving it out. The recursive resolver simply decides not to pass the answer along, which is why French courts go after Google, Cloudflare and Quad9: they sit in the middle.

Step 1: find out which resolver answers #

Start with what the machine is configured to use:

# Linux with a plain /etc/resolv.conf
cat /etc/resolv.conf

# Linux with systemd-resolved (Ubuntu and others)
resolvectl status

# macOS
scutil --dns | grep nameserver

# Windows, in PowerShell
Get-DnsClientServerAddress

Very often this only shows the router, something like 192.168.1.1, and the router forwards everything to whatever it was set up to use. To find out who really answers, ask for a name whose server replies with the address of whoever asked it:

dig +short whoami.akamai.net
dig +short TXT o-o.myaddr.l.google.com

Both print the IP address of the resolver that reached them. Run whois on that address to see which network it belongs to. It won't always be the expected brand: big public resolvers use anycast, and many of their nodes live inside partner networks. A query sent through Quad9, for example, can come back from an address registered to a university research network in Colorado that hosts one of Quad9's nodes.

For Quad9 there's a shortcut: open on.quad9.net and it answers yes or no.

That page also lists the usual reasons for a surprise "no", and they apply to any resolver:

Step 2: read a blocked answer #

The tool here is dig. On Debian and Ubuntu it lives in bind9-dnsutils (the old package name dnsutils still works), macOS already has it, and on Windows Resolve-DnsName in PowerShell covers the basics.

sudo apt install bind9-dnsutils

Quad9 keeps a test domain, isitblocked.org, that its filter always blocks. The examples below use +https, which makes dig send the query over DNS over HTTPS (it needs BIND 9.18 or newer). Plain dig @9.9.9.9 isitblocked.org gets the same status. This is Quad9's filtered service, with the output trimmed:

$ dig +https @dns.quad9.net isitblocked.org

;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 44678
;; flags: qr rd ad; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
; EDE: 17 (Filtered)

Four details give the block away.

status: NXDOMAIN means "this name doesn't exist". The domain does exist, so this is the lie itself.

AUTHORITY: 0 is the clearest sign. A real NXDOMAIN comes with a record from the zone that says so. Asked for a name nobody registered, the same resolver answers this:

$ dig +https @dns.quad9.net thisdomaindoesnotexist-pm.org

;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 31764
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1

;; AUTHORITY SECTION:
org. 3454 IN SOA v0n0.pir-ns.org. hostmaster.donuts.email. 1795037395 7200 900 1209600 3600

That SOA record comes from the .org zone itself, confirming the name doesn't exist. The blocked answer has nothing like it.

The ra flag is missing in the blocked answer, and dig warns that recursion wasn't available. The resolver never went out to look the name up.

EDE: 17 (Filtered) is an Extended DNS Error, defined in RFC 8914. It's a small note attached to the answer that says why it came back the way it did.

Now ask Quad9's unfiltered service, 9.9.9.10, the same question:

$ dig +https @dns10.quad9.net isitblocked.org +short
74.208.236.124

Without the filter, the same company hands over the real address.

The four codes that matter here #

RFC 8914 has four codes for "I won't give you this", and the difference between them is who wanted the block:

The RFC also says these codes are diagnostic only and must not change how software handles the answer. Browsers generally don't show them, which is why a blocked site just looks broken. dig shows them, so dig is the way to find out.

Not every resolver lies the same way #

When the block comes from a court, each resolver answers differently:

A bare NXDOMAIN or 127.0.0.1 says nothing about why. The quickest test is to ask several resolvers the same question and compare:

for r in 9.9.9.9 9.9.9.10 1.1.1.1 8.8.8.8; do
printf '%s ' "$r"
dig @"$r" isitblocked.org +noall +comments | grep -o 'status: [A-Z]*'
done

9.9.9.9 status: NXDOMAIN
9.9.9.10 status: NOERROR
1.1.1.1 status: NOERROR
8.8.8.8 status: NOERROR

If one resolver says the name doesn't exist and the others return an address, somebody along the way is filtering. Swap isitblocked.org for any site that fails to load and it becomes a small censorship test that runs anywhere.

Step 3: encrypt the trip #

Plain DNS travels over UDP port 53 in clear text. Anyone on the path, the ISP or the café Wi-Fi, can read every name looked up, and some networks catch traffic to port 53 and answer it themselves no matter which server was configured. Two protocols close that gap: DNS over TLS (DoT, port 853) and DNS over HTTPS (DoH, port 443, RFC 8484).

Encryption protects the trip only. The resolver at the other end still sees every name, so encryption decides who can watch along the way and the choice of resolver decides who gets trusted at the end of it.

On Linux with systemd-resolved, create /etc/systemd/resolved.conf.d/10-dot.conf:

[Resolve]
DNS=9.9.9.9#dns.quad9.net 149.112.112.112#dns.quad9.net
DNSOverTLS=yes

The part after # is the name on the server's TLS certificate, and systemd-resolved checks it. Swap both for the chosen provider (in France, after the 24th, that can't be Quad9). Then:

sudo systemctl restart systemd-resolved
resolvectl status

The Protocols line should now show +DNSOverTLS. With DNSOverTLS=yes, a server that doesn't speak TLS makes every lookup fail, which is the point: no silent fallback to clear text.

Elsewhere:

dig can test both protocols directly: dig +tls @dns.quad9.net example.com and dig +https @dns.quad9.net example.com.

Step 4: run your own resolver #

A recursive resolver at home walks from the root to the authoritative servers by itself, the same way the big public ones do. No public resolver sees the queries, and no court order aimed at one of them changes the answers. There are trade-offs, and they're worth knowing first:

Unbound is the usual choice. Debian 13 ships version 1.22:

sudo apt install unbound dns-root-data

Debian's package already turns DNSSEC validation on (that's /etc/unbound/unbound.conf.d/root-auto-trust-anchor-file.conf) and reads every .conf file in that folder. Add one more, /etc/unbound/unbound.conf.d/local-resolver.conf:

server:
interface: 127.0.0.1
interface: ::1
access-control: 127.0.0.0/8 allow
access-control: ::1/128 allow

hide-identity: yes  
hide-version: yes  

prefetch: yes

Line by line:

QNAME minimisation (sending each server only the part of the name it needs, so the root servers see .com and not the full name) and the DNSSEC hardening options are already on by default in current Unbound, so there's no need to write them.

Check the file, restart and test:

sudo unbound-checkconf
sudo systemctl restart unbound
dig @127.0.0.1 example.com

Then test DNSSEC. The first name is signed wrong on purpose and must fail, the second must resolve with ad (authenticated data) in the flags line:

dig @127.0.0.1 fail01.dnssec.works
dig @127.0.0.1 dnssec.works

SERVFAIL on the first and flags: qr rd ra ad on the second mean validation works.

Last, point the machine at it. On a Debian box without systemd-resolved, /etc/resolv.conf should contain nameserver 127.0.0.1 (if the resolvconf or openresolv package is installed, Unbound's own unbound-resolvconf service writes that line by itself). With systemd-resolved, use a drop-in like the one in step 3 with DNS=127.0.0.1 and without the TLS line.

For the whole house #

To serve the local network from a Raspberry Pi or a home server, add a second file, say lan.conf, in the same folder:

server:
interface: 0.0.0.0
interface: ::0
access-control: 192.168.1.0/24 allow
access-control: fd00::/8 allow

Change 192.168.1.0/24 to the local network's range, restart Unbound and set the router's DHCP to hand out the Pi's address as the DNS server. Keep port 53 closed to the internet: open resolvers get abused to flood other people with amplified traffic.

Before November 24, in France #

Quad9 hasn't said how the cutoff will behave on the wire, whether queries will be refused or just go unanswered. Either way, as Cloudflare put it in its post about the withdrawal, people won't see an error message: "Their Internet will simply stop working." Places where Quad9 tends to hide:

On Linux machines, this finds the Quad9 addresses and hostnames in /etc:

sudo grep -rnE '9\.9\.9\.(9|10|11)|149\.112\.112\.|2620:fe:|quad9' /etc 2>/dev/null

Afterwards, run the two commands from step 1 again. They're the quickest way to see who answers now.