Check Whether Tor Traffic Leaks DNS Through systemd-resolved
Stock Tor Browser does not ask systemd-resolved anything. It hands the hostname to Tor over SOCKS, and the exit relay does the lookup. The leaks people find almost always come from something else on the machine, or from a browser you pointed at a system Tor by hand. So the useful job is testing, then making the leak impossible rather than merely unlikely.
Where the leak actually comes from
A DNS leak means a hostname you meant to reach via Tor goes to your ISP's resolver (or whoever resolved is configured to use) instead. Common causes:
- A normal Firefox set to use a SOCKS proxy on port 9050 with "Proxy DNS when using SOCKS v5" switched off.
- A SOCKS4 proxy setting, which has no way to carry a hostname, so the client resolves locally first.
- A command-line tool that resolves the name itself, then connects to the IP through the proxy.
- Helper processes (updaters, link previews, captive portal checks) that never knew about the proxy.
Tor Browser is built to avoid the first three. The fourth is why a machine-level check matters.
Step 1: watch DNS while you browse
Start with a capture. Leave this running in one terminal, then use the browser in another:
sudo tcpdump -ni any 'port 53 or port 853'
Packets on lo to 127.0.0.53 are apps talking to the resolved stub. Packets on your real interface to a resolver are the upstream queries. Either kind appearing while you load a site in Tor Browser is worth investigating.
You can also see what resolved itself is being asked:
resolvectl monitor
That prints each query as resolved handles it. Quiet during Tor Browser use is what you want.
Quick detour: why a firewall rule on port 53 is not enough
On a typical systemd distro, glibc does not send UDP to 127.0.0.53 at all. If nss-resolve is in /etc/nsswitch.conf, the lookup goes over a Unix socket to systemd-resolved (varlink or D-Bus), and resolved then sends the real query out as its own user. That surprised me.
So a firewall rule such as "this user may not send port 53" never sees the lookup. The packet leaves under the systemd-resolve uid, not yours. Whether your distro uses the stub path or the NSS path varies, so check rather than assume: grep hosts /etc/nsswitch.conf.
Step 2: run the browser as a user that cannot reach resolved
The reliable fix is to remove the browser's ability to talk to any resolver and give it only Tor. Create a dedicated user and run a system Tor:
sudo useradd -m -s /bin/bash torbrowser
sudo apt install tor # or your distro's equivalent
systemctl status tor # SOCKS on 127.0.0.1:9050 by default
Now an nftables backstop. It lets that user reach only the Tor SOCKS port on loopback and drops everything else, including the stub on 127.0.0.53 and all IPv6:
table inet torjail {
chain out {
type filter hook output priority 0; policy accept;
meta skuid "torbrowser" oifname "lo" tcp dport 9050 accept
meta skuid "torbrowser" drop
}
}
Save that as a file and load it with sudo nft -f torjail.nft. Order matters: the accept comes before the blanket drop.
Close the Unix socket route too
The rule above does not stop the NSS path, because that goes over a Unix socket, not the network. Hide the socket from the browser's process. With a transient unit, InaccessiblePaths= does it:
sudo systemd-run --uid=torbrowser --pty --collect \
-p InaccessiblePaths=/run/systemd/resolve \
-p Environment=DISPLAY=$DISPLAY \
/path/to/tor-browser/Browser/start-tor-browser
You will likely need to sort out display access for that user (for example with xhost on X11, or a Wayland socket permission), and I have not covered every desktop setup here. What matters is the property rather than the exact launcher: no route to resolved, and no route to the network except Tor.
With the socket hidden, glibc cannot reach resolved, and its fallback to 127.0.0.1:53 hits the nftables drop. A lookup now fails loudly rather than leaking quietly.
Step 3: point Tor Browser at the system Tor
Tor Browser normally starts its own tor on port 9150. To use the system one instead, set these environment variables before launching:
TOR_SKIP_LAUNCH=1 TOR_SOCKS_HOST=127.0.0.1 TOR_SOCKS_PORT=9050 \
TOR_NO_DISPLAY_NETWORK_SETTINGS=1 ./start-tor-browser
These variables are used by the Tor Browser launcher; check your version's behaviour, as they have changed over the years. If it ignores them, it will try to start its own tor and the firewall will stop it, which is at least a safe failure.
Step 4: prove the jail works
Test as the jailed user. Every one of these should fail or time out:
sudo -u torbrowser dig example.com @127.0.0.53sudo -u torbrowser dig example.com @1.1.1.1sudo -u torbrowser curl https://example.com
And this should work, because the name goes to Tor and the exit does the lookup (socks5h is the "send the hostname, do not resolve it" form):
sudo -u torbrowser curl --socks5-hostname 127.0.0.1:9050 https://check.torproject.org/api/ip
Run the tcpdump from step 1 again during all of this. Nothing should appear on your real interface except Tor's own traffic to its guard relay, which is encrypted and carries no hostnames you asked for.
What this does not cover
This stops DNS leaks from the browser's user. It does nothing about your other applications under your normal account, and it does not make Tor safer against traffic correlation or browser fingerprinting. Treat it as one layer: if a bug or a stray helper tries to resolve a name, it fails instead of telling your ISP what you were reading.