Skip to content

fix: preserve systemd-resolved stub in DNS auto-detection#50

Merged
tito merged 1 commit intomainfrom
fix/dns-preserve-systemd-stub
Apr 14, 2026
Merged

fix: preserve systemd-resolved stub in DNS auto-detection#50
tito merged 1 commit intomainfrom
fix/dns-preserve-systemd-stub

Conversation

@tito
Copy link
Copy Markdown
Contributor

@tito tito commented Apr 14, 2026

Summary

  • Stop bypassing systemd-resolved in linuxMacDNSServers(): read /etc/resolv.conf verbatim instead of swapping the stub out for the raw upstreams in /run/systemd/resolve/resolv.conf.
  • Fall back to /run/systemd/resolve/stub-resolv.conf only when /etc/resolv.conf is absent (minimal images). The raw upstream file is never read.
  • Add sysdns_test.go covering the 127.0.0.53 regression, multi-nameserver order, IPv6 bracketing, malformed lines, and missing files.

Why

0.4.1 (#43) replaced 127.0.0.53 with the raw Mullvad upstream from /run/systemd/resolve/resolv.conf, so greyproxy tried plain UDP/53 to an upstream that systemd-resolved had been reaching over DoT. On hosts configured with DNSOverTLS=opportunistic (matclab's setup in #47) the direct UDP path is unreachable and every lookup times out. Letting queries flow through 127.0.0.53 keeps DoT, DNSSEC, and split-DNS intact.

The container concern the original code cited (127.x.x.x being container-local) doesn't apply: greyproxy runs on the host, and the sandboxed client connects to it via the host's loopback, so 127.0.0.53 is reachable.

Fixes #47

Test plan

  • go test ./cmd/greyproxy/ -run TestResolvConf -v
  • go build ./...
  • go vet ./cmd/greyproxy/

0.4.1 introduced auto-detection of the host's DNS servers in
linuxMacDNSServers(). When /etc/resolv.conf contained only the
systemd-resolved stub (127.0.0.53), the code fell back to
/run/systemd/resolve/resolv.conf to grab the raw upstream nameservers.

That bypasses systemd-resolved entirely: queries go straight to the
upstream over plain UDP/53, dropping DoT, DNSSEC, and split-DNS. On
hosts where resolved is configured with DoT-only upstreams (Mullvad
with DNSOverTLS=opportunistic is the reported case), the raw UDP path
is unreachable and every lookup times out.

Read /etc/resolv.conf verbatim instead. On the typical systemd-resolved
host that returns 127.0.0.53, and queries flow through resolved as the
user configured. As a safety net for minimal images that ship without
/etc/resolv.conf, fall back to /run/systemd/resolve/stub-resolv.conf,
which also points at the stub. The raw upstream file is never read.

Fixes #47
@tito tito merged commit 5c69e1d into main Apr 14, 2026
3 checks passed
@tito tito deleted the fix/dns-preserve-systemd-stub branch April 14, 2026 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: DNS not working on linux with greyproxy 0.4.1

1 participant