Skip to content

resolved: add DNSServerPolicy= option for server selection control - #40311

Draft
ageorgop wants to merge 1 commit into
systemd:mainfrom
ageorgop:dns-server-policy
Draft

ageorgop wants to merge 1 commit into
systemd:mainfrom
ageorgop:dns-server-policy

Conversation

@ageorgop

@ageorgop ageorgop commented Jan 9, 2026

Copy link
Copy Markdown

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 them
  • sequential: Traditional resolv.conf behavior - always try servers in configured order for each new query

Configuration

Global (/etc/systemd/resolved.conf):

[Resolve]
DNSServerPolicy=sequential

Per-link (.network files):

[Network]
DNSServerPolicy=sequential

Per-link settings override the global setting.

Key Behavioral Notes

  1. 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.

  2. 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.

  3. Feature probing still active: Sequential mode controls server ORDERING only. Per-server feature level probing (TLS → EDNS0 → UDP fallback) remains active regardless of policy.

  4. 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 status output:

Global
         Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
  resolv.conf mode: stub
DNS Server Policy: adaptive

Link 3 (wlp110s0)
    Current Scopes: DNS
         Protocols: +DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
DNS Server Policy: sequential

Implementation

  • New DnsServerPolicy enum in src/shared/resolve-util.h
  • Per-transaction server iteration via sequential_next_server field ensures independent transactions don't interfere
  • Server pointer is ref'd to prevent use-after-free if server list changes
  • D-Bus properties exposed for both Link and Manager interfaces
  • Documentation in resolved.conf.xml and systemd.network.xml

Testing

  • 16 unit tests in test-dns-server-policy.c
  • Integration test in TEST-75-RESOLVED.sh verifying resolvectl status output
  • Tests cover: string tables, policy inheritance, transaction-level cycling, NXDOMAIN behavior, latency trade-off documentation

Test plan

  • Unit tests pass (test-dns-server-policy)
  • Integration test verifies resolvectl status shows policy
  • Manual testing confirms policy behavior
  • Documentation updated with behavioral warnings

@SuperSweatyYeti

Copy link
Copy Markdown

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?

@ageorgop

Copy link
Copy Markdown
Author

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.

@yuwata

yuwata commented Feb 3, 2026

Copy link
Copy Markdown
Member

(Tentatively dropping the 'please-review' tag, as it is in draft. Please push the 'Ready for review' button when it is ready.)

@yuwata yuwata removed the please-review PR is ready for (re-)review by a maintainer label Feb 3, 2026
@ageorgop
ageorgop force-pushed the dns-server-policy branch from f52be50 to b2d3eae Compare March 5, 2026 00:29
Comment thread test/units/TEST-75-RESOLVED.sh Fixed
Comment on lines +1500 to +1507
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

This function is never invoked. Check usage (or ignored if invoked indirectly).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleanup() is invoked indirectly via 'trap cleanup RETURN' below, which shellcheck cannot detect — suppress the false positive.
thus the shellcheck disable=SC2317,SC2329

@ageorgop
ageorgop force-pushed the dns-server-policy branch 3 times, most recently from 290b058 to 80df6dc Compare March 5, 2026 04:18
@ageorgop
ageorgop force-pushed the dns-server-policy branch from 80df6dc to 42d2693 Compare March 21, 2026 18:34
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.
@ageorgop
ageorgop force-pushed the dns-server-policy branch from 42d2693 to 64ca460 Compare March 21, 2026 18:36
@rpigott

rpigott commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

This kind of behavior has been rejected multiple times before. See Lennart's comment here:

Again, defining multiple DNS servers is not a way to merge zones, it's a way to deal with unreliable servers, the assumption is always that all DNS servers configured provide the same dataset.

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.

@github-actions

github-actions Bot commented Apr 3, 2026 •

Copy link
Copy Markdown

Claude review of PR #40311 (64ca460)

Nits

  • Remove speculative future-policy comments — src/shared/resolve-util.h:76-79 — Comments about hypothetical round-robin/weighted/fastest policies add noise to the enum definition; these belong in an issue tracker
  • Fix copy-pasted comment wording — src/systemd/sd-network.h:168 — "Possible levels of support" is copy-paste from DNS-over-TLS/DNSSEC; should be "Possible values" for a policy setting

Workflow run

@SuperSweatyYeti

SuperSweatyYeti commented Apr 3, 2026 •

Copy link
Copy Markdown

This kind of behavior has been rejected multiple times before. See Lennart's comment here:

Again, defining multiple DNS servers is not a way to merge zones, it's a way to deal with unreliable servers, the assumption is always that all DNS servers configured provide the same dataset.

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.

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:

  • Manually config /etc/resolv.conf
  • Use some other DHCP tool that edits /etc/resolv.conf directly

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.

Comment thread src/shared/resolve-util.h
Comment on lines +76 to +79
/* 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 */

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/systemd/sd-network.h
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

optinally, begin every transaction with first DNS server in list instead of last working one

6 participants