Repository navigation
Conversation
|
Is it possible to add some timeout options here as well? Like being able to define how many sec or msec before timeout and/or how many timeouts before trying the next server? |
i feel like that should be it's own change and not conflated with this feature. I have another branch where I'm working on a more complete set of options like rotate, timeouts etc that i'll push if by some miracle this gets accepted. |
|
(Tentatively dropping the 'please-review' tag, as it is in draft. Please push the 'Ready for review' button when it is ready.) |
f52be50 to
b2d3eae
Compare
| cleanup() { | ||
| rm -f /run/systemd/resolved.conf.d/90-dns-server-policy.conf | ||
| rm -f /run/systemd/network/10-dns0.network.d/dns-server-policy.conf | ||
| rmdir /run/systemd/network/10-dns0.network.d 2>/dev/null || true | ||
| networkctl reload | ||
| systemctl reload systemd-resolved.service | ||
| resolvectl revert dns0 | ||
| } |
Check warning
Code scanning / ShellCheck
SC2329
There was a problem hiding this comment.
cleanup() is invoked indirectly via 'trap cleanup RETURN' below, which shellcheck cannot detect — suppress the false positive.
thus the shellcheck disable=SC2317,SC2329
290b058 to
80df6dc
Compare
80df6dc to
42d2693
Compare
Add a new DNSServerPolicy= configuration option for systemd-resolved that controls how DNS servers are selected for queries. Two policies are available: - adaptive (default): The existing behavior that learns which servers respond well and prefers them, optimizing for latency. - sequential: Always tries servers in configured list order, like traditional resolv.conf behavior. Each new transaction starts with the first server, falling back to others only on failure. The setting can be configured globally in resolved.conf and per-link in systemd.network files, with per-link settings taking precedence. Delegate scopes also support their own policy via the Delegate.DNSServerPolicy config entry. The sequential policy uses a per-transaction iterator (sequential_next_server) to track position in the server list, ensuring independent iteration across concurrent transactions. Feature-level probing (TLS/EDNS0/UDP fallback) remains active regardless of policy — it is orthogonal to server ordering.
42d2693 to
64ca460
Compare
|
This kind of behavior has been rejected multiple times before. See Lennart's comment here:
And this assumption is a useful one used in resolved's caching. More importantly, it's usually a bad idea to "leak" internal queries to random other resolvers, and for that reason using internal corporate DNS alongside external dns providers as equivalents is not really a good idea. resolved already supports per-domain routing, per interface zones and custom delegate zones that are much more elegant and correct solutions to the "my corporate dns is shit" problem. We should be encouraging those features, and for that reason I really don't think this should be accepted into resolved. |
Claude review of PR #40311 (64ca460)Nits
|
I don't think anyone is arguing that using split-dns architecture is ideal. This is just the reality we are in today. I'm pretty sure people who are asking for this feature/option are perfectly happy with the default behavior STAYING the default behavior. It is EXTREMELY common for small to medium sized businesses to have a split-dns scenario where internal DNS servers point to internal resources, but network admins have configured DHCP to set some public DNS as a backup in case of failures so that internal DNS servers being down ( while yes may be bad ) don't cause every computer on the network to lose internet access, and then when the internal DNS servers come back up internal resources are accessible again because the PC's are still trying to query those internal DNS servers. Because of the lack of this resolved option, when I am administering linux servers in these types of environments I HAVE to disable 'systemd-resolved' completely and either:
That way I can get the behavior we are asking for here. For me and for many other system admins, that behavior takes priority over any other feature that resolved can provide. Anyways, thanks to the PR creator for their attempt here. I really hope it get's merged and I hope that the maintainers understand the need here. |
| /* Future policies could include: | ||
| * - round-robin: rotate through servers for load distribution | ||
| * - weighted: prefer servers based on configured weights | ||
| * - fastest: always use the server with lowest observed RTT */ |
There was a problem hiding this comment.
Claude: nit: Claude: These speculative comments about future policies (round-robin, weighted, fastest) add noise to the enum definition. The systemd codebase generally avoids speculative future-feature comments in type definitions — these belong in an issue tracker or design doc, not the code.
| int sd_network_link_get_dns_over_tls(int ifindex, char **ret); | ||
|
|
||
| /* Indicates which DNS server selection policy should be used for the link | ||
| * Possible levels of support: adaptive, sequential |
There was a problem hiding this comment.
Claude: nit: Claude: "Possible levels of support" is copy-pasted from the DNS-over-TLS and DNSSEC function comments above, where it makes sense (levels of support). For a policy setting, "Possible values: adaptive, sequential" would be more accurate.
Summary
This PR adds a new
DNSServerPolicy=configuration option for systemd-resolved that allows users to control DNS server selection behavior.Fixes: #5755
The Problem
systemd-resolved's default behavior is to remember which DNS servers respond well and prefer them for future queries ("adaptive"). While this works well for many scenarios, it causes issues in corporate split-DNS environments where the internal DNS server should always be tried first, even if it's slower or occasionally fails.
The Solution
Add a
DNSServerPolicy=option with two values:adaptive(default): Current behavior - remember which servers work well and prefer themsequential: Traditional resolv.conf behavior - always try servers in configured order for each new queryConfiguration
Global (
/etc/systemd/resolved.conf):Per-link (
.networkfiles):Per-link settings override the global setting.
Key Behavioral Notes
Fallback only on failure: Fallback to the next server only occurs on timeout, network error, SERVFAIL, or REFUSED. NXDOMAIN and NODATA are authoritative responses that do NOT trigger fallback. Sequential mode is not suitable for merging responses from servers authoritative for different zones.
Latency trade-off: In sequential mode, when the primary server is down, every query waits for the full timeout before trying the next server. Unlike adaptive mode, there is no cross-transaction learning.
Feature probing still active: Sequential mode controls server ORDERING only. Per-server feature level probing (TLS → EDNS0 → UDP fallback) remains active regardless of policy.
For split-DNS: Use per-link DNS routing (
Domains=) instead of sequential mode for scenarios where different servers are authoritative for different zones.Observability
DNS Server Policy is displayed in
resolvectl statusoutput:Implementation
DnsServerPolicyenum insrc/shared/resolve-util.hsequential_next_serverfield ensures independent transactions don't interfereresolved.conf.xmlandsystemd.network.xmlTesting
test-dns-server-policy.cTEST-75-RESOLVED.shverifyingresolvectl statusoutputTest plan
test-dns-server-policy)resolvectl statusshows policy