Skip to content
apeirsPublic

About

A local DNS resolver that sends every lookup through the Nym mixnet (DoH, no clearnet fallback)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

dnsmix

A local DNS resolver that sends every lookup through the Nym mixnet. It listens for plain DNS on loopback (UDP and TCP), so anything that resolves names can use it: the system resolver, a browser, curl, a container. Each query leaves as DNS-over-HTTPS (RFC 8484) through Nym's nym-socks5-client to public resolvers (Quad9, Mullvad, Cloudflare, AdGuard, or your own). One Go binary, no dependencies outside the standard library, MIT.

dnsmix nym setup                   # starts nym-socks5-client on a random active exit gateway
dnsmix serve                       # DNS on 127.0.0.1:5380 -> mixnet -> DoH resolvers
dnsmix dig nym.com                 # ask it, like dig would
dnsmix lookup nym.com AAAA         # one lookup straight through the mixnet, no server
dnsmix whoami                      # the IP the resolvers see (a Nym exit gateway)
dnsmix probe --all                 # which resolvers answer through the mixnet, and how fast

Why

Every connection starts with a DNS lookup, and the lookup says where you are going before you get there. By default the lookups go in plain text to your ISP's resolver. Encrypted DNS (DoH/DoT) hides them from the network but hands them, with your IP, to the resolver operator instead: a list of every site, app backend, update server and wallet API this IP talks to, minute by minute.

Routing the app's own traffic through Nym doesn't fix that. Tools that take a SOCKS5 proxy often still resolve names locally first (curl --socks5, many libraries and anything that does getaddrinfo before it connects), and programs that don't take a proxy at all still look up every name through the system resolver.

dnsmix serve gives the machine (or one program) a resolver whose upstream traffic goes through the mixnet. The resolver operator sees a Nym exit gateway's IP and a stream of questions that it can't tie to you, and each resolver only sees its share of them.

Use

export DNSMIX_NYM_SOCKS5=/path/to/nym-socks5-client    # official Nym release binary
go install github.com/apeirs/dnsmix/cmd/dnsmix@latest
dnsmix nym setup             # SOCKS5 on 127.0.0.1:1093 (--port to change; then set DNSMIX_PROXY)
dnsmix serve &
dnsmix dig example.com       # -> 127.0.0.1:5380

Point something at it:

  • One program or a test: most DNS libraries take a server and port (dnspython: nameservers=["127.0.0.1"], port=5380; dig @127.0.0.1 -p 5380).
  • systemd-resolved (whole machine): a drop-in /etc/systemd/resolved.conf.d/dnsmix.conf with [Resolve], DNS=127.0.0.1:5380, Domains=~. and DNSOverTLS=no, then systemctl restart systemd-resolved. Per-link DNS servers from DHCP can still win for their own domains; resolvectl status shows what is used.
  • Plain /etc/resolv.conf needs port 53: run dnsmix serve --listen 127.0.0.2:53 with setcap cap_net_bind_service=+ep $(which dnsmix) and put nameserver 127.0.0.2 and options timeout:15 attempts:2 in resolv.conf (a cold mixnet lookup can take longer than glibc's 5 s default).
  • Containers: --dns with an address the container can reach, and dnsmix serve --listen <bridge IP>:53 --allow <container subnet>.
  • Firefox uses its own DoH (straight to its default provider, outside the mixnet) unless told not to. dnsmix answers Firefox's canary domain use-application-dns.net with NXDOMAIN, which turns the automatic rollout off; if you switched DoH on yourself, set it back to off (network.trr.mode = 5).

I tested the first and the resolv.conf setup (glibc's resolver, in a network namespace, see below). The systemd-resolved and container recipes follow the documented options but were not run here.

What it does with a query

  1. Local-only names never leave. .local, .lan, .home.arpa, .internal, .onion, .i2p, localhost, reverse lookups of private, loopback, link-local and CGNAT ranges, and single-label names (printer, nas, a search-domain typo) are answered on the spot: NXDOMAIN with an Extended DNS Error "Prohibited, not sent", or 127.0.0.1 / ::1 for localhost. Sending them would describe your network and can't return anything useful. .onion must never reach DNS (RFC 7686). Validating stubs can still ask a TLD for DS/DNSKEY/NS/SOA.
  2. Cache. Answers are cached for their TTL (negative answers for the SOA minimum, RFC 2308), and served with the TTLs counted down. A hit costs nothing and tells no resolver anything. Identical queries in flight share one trip through the mixnet, so a stub that retries after 2 s doesn't send a second copy.
  3. A new query is built from scratch. Only the question, the CD bit and the DO bit come from the client. Whatever else it put in its message (EDNS Client Subnet, cookies, NSID, its ID) is not forwarded. The new query has ID 0 (RFC 8484) and EDNS padding to a multiple of 128 bytes (RFC 8467), and goes out as an HTTP/2 GET with only an Accept header: no User-Agent, no cookies.
  4. One resolver per site. With --strategy spread (the default) a keyed hash of the site (www.example.org and cdn.example.org count as one) picks the resolver, so each of the four default operators sees about a quarter of your sites, and a site always goes to the same one. The key is random, kept in ~/.local/state/dnsmix/spread.key, so the split survives restarts and nobody else can predict it. --strategy first uses the first resolver for everything.
  5. Through the mixnet. The resolver is dialed at a pinned IP address (no DNS lookup is needed to find the resolvers: not locally, not at the exit) as a SOCKS5 stream through nym-socks5-client: entry gateway, mix layers, exit gateway, then TLS end to end with the resolver, verified for its hostname. The HTTP/2 connection is kept open (and warmed every 50 s), so later queries skip the stream and TLS setup.
  6. The answer is checked before it is cached or passed on: well-formed to the last byte, a response, ID 0, not truncated, and for the same question. Name compression may only point backwards. The resolver's own OPT record (its padding, any ECS echo) is dropped and the client gets dnsmix's own, with its question echoed in its own letter case (for 0x20-randomising clients). Over UDP, an answer bigger than the client's buffer is sent truncated (TC) so it retries over TCP.
  7. Failure. A resolver that errors, times out, redirects, answers with the wrong content type or a broken or mismatched message is skipped for the next one and goes to the back of the line for 30 s. SERVFAIL and REFUSED also try the next resolver. If every resolver fails, an expired cache entry may be served for up to a day with a TTL of 30 s and EDE "Stale Answer" (RFC 8767), otherwise SERVFAIL with EDE "Network Error".
  8. No clearnet fallback. If the Nym client is not running, nothing is sent anywhere: SERVFAIL with "mixnet client not running; not falling back to clearnet". When the client is back, the same server works again without a restart.

The server listens on loopback and answers loopback clients only. Listening anywhere else needs --allow CIDR,..., so it can't become an open resolver by accident. Packets from other addresses are dropped without an answer, and so are DNS responses sent to it (no reflection). Zone transfers, other classes than IN/CH and other opcodes than QUERY are refused.

Logs show the record type, resolver, result and timing, never the name, unless you pass --log-names. Errors never carry the request URL (it contains the query). Every 15 minutes, and on exit, a summary line: stats: 107 queries: 71 through the mixnet, 28 from cache, 6 answered locally, 1 stale, 1 failed; 57 cached.

Resolvers

name URL pinned
quad9 (default) https://dns.quad9.net/dns-query 9.9.9.9, 149.112.112.112 malware blocking, sends no ECS
mullvad (default) https://dns.mullvad.net/dns-query 194.242.2.2 no filtering, sends no ECS
cloudflare (default) https://cloudflare-dns.com/dns-query 1.1.1.1, 1.0.0.1 sends ECS of the exit's /24 to some authorities
adguard (default) https://unfiltered.adguard-dns.com/dns-query 94.140.14.140, .141 sends a substitute ECS subnet
quad9-unfiltered https://dns10.quad9.net/dns-query 9.9.9.10, 149.112.112.10
dnssb https://doh.dns.sb/dns-query 185.222.222.222, 45.11.45.11
google https://dns.google/dns-query 8.8.8.8, 8.8.4.4 sends ECS of the exit's /24

All 13 addresses answered through the mixnet on 2026-11-08 (dnsmix probe --all). Your own: --upstream my=https://doh.example.net/[email protected] (pinned) or without @... (the exit gateway then resolves the hostname; your machine still never does). https only, no credentials in the URL.

The ECS column comes from dnsmix whoami, which asks Akamai's whoami.ds.akahelp.net through each resolver. None of them ever had your subnet to send, only the exit gateway's.

Limits (read these)

  • It hides who asks, not what is asked. The resolvers see the names. The spread strategy limits how many each one sees; it doesn't make a name secret. Pick resolvers you are willing to show your lookups to.
  • The exit gateway sees which resolver you connect to and the size and timing of the TLS traffic, not the questions. Nym's reply SURBs (on by default in nym setup) keep your mixnet address from the exit.
  • One exit, one session. All your queries leave from the same exit IP while the client runs, so a resolver can link the queries it gets to each other (not to you). dnsmix nym setup --force picks a new identity and exit.
  • Timing and volume. Lookups happen when you open things. A resolver can see bursts at the exit IP that belong together. The mixnet adds delay and cover traffic between you and the exit, but the resolver end is ordinary HTTPS.
  • Latency. A cold lookup takes 1-5 s (new SOCKS5 stream, TLS, mixnet round trips), a warm one 0.3-1 s, a cached one nothing. In the live run below, the median first lookup was 0.63 s. Stub resolvers with short timeouts retry; the retries share the trip in flight.
  • Only what uses it. Programs with their own DoH (browsers), hardcoded resolvers (some IoT, Android apps) or their own name resolution through a VPN bypass it. dnsmix doesn't firewall anything.
  • IP connections are not covered. After the lookup, the program connects to the address itself; that connection is only private if it goes through the mixnet too (SOCKS5 to nym-socks5-client, or NymVPN).
  • DNSSEC is validated by the resolvers (the AD bit comes back, and with DO the RRSIGs do too, so a validating stub in front of dnsmix can check them itself). dnsmix doesn't validate.
  • Not a public-suffix list. Grouping names into sites is a heuristic (two labels, three under a two-letter country code's co/com/...). A wrong guess changes which resolver sees a name, never whether it goes through the mixnet.
  • Port 5353 is mDNS. That's why the default is 5380: on the test machine a desktop app already held 5353.

How I checked it

Tests (offline, fake mixnet)

go test ./... runs 41 tests (27 top level and 14 failure cases) against a fake nym-socks5-client that records every CONNECT, fake DoH resolvers over HTTP/2 and TLS with a throwaway CA, and a fake clock:

  • everything goes through the SOCKS5 proxy, to pinned IPs (or by name to the exit when unpinned), never resolved locally; the HTTP client can't reach any host that isn't a configured resolver, and doesn't follow redirects;
  • the upstream query is rebuilt: ID 0, padded to 128 bytes, DO/CD kept, the client's ECS and cookie never sent, no User-Agent; the answer has the client's ID, its letter case, no upstream OPT;
  • local-only names (17 kinds) open no connection at all;
  • cache: TTLs count down, negative answers use the SOA minimum, DO and non-DO apart, SERVFAIL not cached, 20 concurrent identical queries make one upstream request;
  • failover on HTTP 500/429, redirects, wrong content type, garbage, wrong ID, not a response, TC, other question, other type, trailing bytes, a hang, SERVFAIL, REFUSED; a failed resolver goes last for 30 s;
  • no fallback: with the proxy down and a resolver reachable directly on loopback, the answer is SERVFAIL + EDE 23 and the direct resolver gets nothing;
  • serve-stale inside its window only; FORMERR, NOTIMP, REFUSED (AXFR, class HS), BADVERS (EDNS 1); responses and runts get no answer;
  • UDP truncation (no EDNS: 512 bytes; EDNS 4096: fits), TCP with two pipelined queries;
  • loopback-only clients and listen addresses, --allow;
  • no query name, and no piece of the base64 query, in logs or errors on success, failover or total failure.

The wire parser has its own tests: pointer loops, forward pointers, names over 255 bytes, lying counts, rdlength past the end, two OPT records, cut SOA rdata.

Every guard was then broken on purpose, one at a time in a copy of the tree (45 mutations: a clearnet fallback in the dialer and in the resolver dial, direct dial instead of SOCKS5, redirects followed, any host dialed, User-Agent sent, padding off, upstream OPT kept, each answer check removed, each local zone list emptied, singleflight off, cache key without DO, serve-stale unbounded, open listen allowed, names always logged ...). A test failed for every one of them (examples/mutate.py, results in examples/mutations.txt).

Live, on the Nym mainnet mixnet (2026-11-08, logs in examples/)

dnsmix nym setup picked exit gateway node 2716 (IT) at random from 97. The resolvers see that node, not me:

$ dnsmix whoami
cloudflare-dns.com sees this DoH query coming from 57.131.24.48 (2.71s over the mixnet)
= Nym node 2716 (IT, exit gateway: true) in the nym-api node list
quad9        reaches Akamai from 2a01:9580:4409:93:9999::201, sends no client subnet
mullvad      reaches Akamai from 2a03:1b20:4:f011::8888, sends no client subnet
cloudflare   reaches Akamai from 2400:cb00:978:1024::ac47:ec62, and tells it the client subnet is 57.131.16.0/24/24
adguard      reaches Akamai from 154.47.26.225, and tells it the client subnet is 217.217.85.0/24/24

dnsmix probe --all: 13 of 13 resolver addresses answered, 2.5-6.3 s cold, 0.4-0.9 s warm (one 2.4 s).

An unmodified client (dnspython) against dnsmix serve, 25 popular domains, A and AAAA: median first lookup 0.63 s, worst 4.72 s, repeats from cache 0.5 ms. A 17-record TXT answer came back truncated over UDP and dnspython retried over TCP. nlnetlabs.nl with DO came back with AD set and its RRSIGs. A client-sent ECS option (198.51.100.0/24) did not reach Akamai. Local names were answered at once and the log says "nothing sent".

In a network namespace with no route out (examples/netns-check.sh): unshare -rnm gives a namespace with only a loopback interface, its own /etc/resolv.conf (nameserver 127.0.0.1) and nsswitch.conf (hosts: files dns, so glibc can't ask systemd-resolved over its Unix socket). The only way out is a Unix socket to the Nym client on the host. curl https://1.1.1.1 fails there with "Could not connect". Inside it, getent ahosts nym.com, Python's socket.getaddrinfo and curl --socks5 (which resolves the name itself through glibc, then connects over the mixnet) all worked through dnsmix serve --listen 127.0.0.1:53. A DNS leak or a clearnet fallback could not have worked in there.

With the Nym client stopped, the running server answered a new name with SERVFAIL + "mixnet client not running; not falling back to clearnet" and an expired name from its stale cache; after dnsmix nym start both resolved again through the mixnet, with no restart. ss showed the server's only connections were to 127.0.0.1:1093 (the Nym client).

Two things the live run taught the code: the first default port, 5353, was already taken by a desktop app's mDNS responder (now 5380, and the bind error says why); and a mixnet stream can drop mid-connection ("unexpected EOF"), which the failover handled by moving that query to the next resolver.

Layout

cmd/dnsmix     CLI: serve, lookup, dig, probe, whoami, ip, upstreams, nym
server         UDP + TCP listener, loopback guard, logging
resolver       local zones, cache, singleflight, spreading, failover, DoH over the mixnet
dnswire        strict DNS message parser/builder (EDNS, padding, EDE, truncation)
mixnet         SOCKS5 to nym-socks5-client, no fallback
nym            set up and run the official nym-socks5-client

License

MIT

About

A local DNS resolver that sends every lookup through the Nym mixnet (DoH, no clearnet fallback)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages