How do I set the search path for systemd-resolved?
Solution 1
The search path is updated from DHCP. In my router, this setting is called "Domain Name".
To update the search path I set the domain in my router, and then renewed the DHCP lease on my Ubuntu machine (service network-manager restart
or reboot).
systemd-resolve --status
whill then show this domain as "DNS Domain", and it will show up in /run/systemd/resolve/stub-resolv.conf
as a search
directive.
Note that the dig
command does not use the search list in /etc/resolv.conf
by default. Add the +search
option to enable this:
dig +search some-hostname
Solution 2
On my 18.04.3 system, man resolved.conf says to modify the Domains= line of the /etc/systemd/resolved.conf file. Excerpt below:
Domains=
A space-separated list of domains. These domains are used as search suffixes when resolving single-label host names
(domain names which contain no dot), in order to qualify them into fully-qualified domain names (FQDNs). Search
domains are strictly processed in the order they are specified, until the name with the suffix appended is found. For
compatibility reasons, if this setting is not specified, the search domains listed in /etc/resolv.conf are used
instead, if that file exists and any domains are configured in it. This setting defaults to the empty list.
Specified domain names may optionally be prefixed with "~". In this case they do not define a search path, but
preferably direct DNS queries for the indicated domains to the DNS servers configured with the system DNS= setting
(see above), in case additional, suitable per-link DNS servers are known. If no per-link DNS servers are known using
the "~" syntax has no effect. Use the construct "~." (which is composed of "~" to indicate a routing domain and "."
to indicate the DNS root domain that is the implied suffix of all DNS domains) to use the system DNS server defined
with DNS= preferably for all domains.
Having done that and restarted systemd-resolved, my /etc/resolv.conf now contains the search domains I wish (since I have configured a static address on this Ubuntu server - it is not going to pick up anything from DHCP)
Laurence Gonsalves
Updated on September 18, 2022Comments
-
Laurence Gonsalves over 1 year
The man page for
systemd-resolved.service
says:systemd-resolved
maintains the/run/systemd/resolve/stub-resolv.conf
file for compatibility with traditional Linux programs. This file may be symlinked from/etc/resolv.conf
. This file lists the 127.0.0.53 DNS stub (see above) as the only DNS server. It also contains a list of search domains that are in use bysystemd-resolved
. The list of search domains is always kept up-to-date.(Emphasis mine.) "The list of search domains is always kept up-to-date" seems to imply that the list is synced from somewhere else, but does not state where. Where does this list of search domains come from? In particular, how do I modify it?