Understanding Precedence of DNS Servers: systemd-resolved.conf Work Configuration
In modern Linux systems, the systemd-resolved service plays a crucial role in handling DNS resolution for the system. This service reads its main configuration file, /etc/systemd/resolved.conf, and additional per-interface configuration files located at /etc/systemd/network/*.network.
systemd-resolved.conf: The Global Configuration File
The /etc/systemd/resolved.conf file sets global DNS configuration parameters, including DNS servers. It consists of several sections, while the focus here is on the [Resolve] section and its DNS= entry:
# /etc/systemd/resolved.conf
[Resolve]
DNS= ...
Where , , and so on, denote the IP addresses of the DNS servers, separated by spaces.
Per-Interface Configuration Files
Additionally, systemd-resolved reads per-interface configuration files from the /etc/systemd/network/ directory, where the DNS server settings can be set per interface or link using the DNS= or Domains= directives:
# /etc/systemd/network/.network
[Match]
Name=
[Network]
DNS= ...
In the example above, denotes the file name, stands for the interface name (such as "eth0" or "wlan0"), and the DNS servers are set through the DNS= directive.
Precedence Rules
When DNS server settings are defined in both /etc/systemd/resolved.conf and the per-interface files, the settings from the latter take precedence over the global settings. This behavior leads to the following order of precedence:
- Per-interface
DNS=configuration files (/etc/systemd/network/*.network) - Per-interface
Domains=configuration files (/etc/systemd/network/*.network) - Global
DNS=configuration (/etc/systemd/resolved.conf)
Understanding the precedence of DNS servers configuration in systemd-resolved allows for fine-grained control over network settings. It's essential to choose the most appropriate precedence rule depending on the system requirements and network setup. In most cases, applying the desired DNS settings at the per-interface level should suffice, while in certain advanced or complex scenarios, the global configuration can offer a more comprehensive solution.
References
- Lennart Poettering and Michael Olbrich. The systemd book. No Starch Press, 2018.
- Freedesktop.org - resolved.conf man page
- Reddit - systemd-resolved and dnsmasq