]>
Commit | Line | Data |
---|---|---|
1 | <?xml version='1.0'?> | |
2 | <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" | |
3 | "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> | |
4 | <!-- SPDX-License-Identifier: LGPL-2.1+ --> | |
5 | ||
6 | <refentry id="systemd-resolved.service" conditional='ENABLE_RESOLVE'> | |
7 | ||
8 | <refentryinfo> | |
9 | <title>systemd-resolved.service</title> | |
10 | <productname>systemd</productname> | |
11 | </refentryinfo> | |
12 | ||
13 | <refmeta> | |
14 | <refentrytitle>systemd-resolved.service</refentrytitle> | |
15 | <manvolnum>8</manvolnum> | |
16 | </refmeta> | |
17 | ||
18 | <refnamediv> | |
19 | <refname>systemd-resolved.service</refname> | |
20 | <refname>systemd-resolved</refname> | |
21 | <refpurpose>Network Name Resolution manager</refpurpose> | |
22 | </refnamediv> | |
23 | ||
24 | <refsynopsisdiv> | |
25 | <para><filename>systemd-resolved.service</filename></para> | |
26 | <para><filename>/usr/lib/systemd/systemd-resolved</filename></para> | |
27 | </refsynopsisdiv> | |
28 | ||
29 | <refsect1> | |
30 | <title>Description</title> | |
31 | ||
32 | <para><command>systemd-resolved</command> is a system service that provides network name resolution to | |
33 | local applications. It implements a caching and validating DNS/DNSSEC stub resolver, as well as an LLMNR | |
34 | and MulticastDNS resolver and responder. Local applications may submit network name resolution requests | |
35 | via three interfaces:</para> | |
36 | ||
37 | <itemizedlist> | |
38 | <listitem><para>The native, fully-featured API <command>systemd-resolved</command> exposes on the bus, | |
39 | see | |
40 | <citerefentry><refentrytitle>org.freedesktop.resolve1</refentrytitle><manvolnum>5</manvolnum></citerefentry> | |
41 | for details. Usage of this API is generally recommended to clients as it is asynchronous and fully | |
42 | featured (for example, properly returns DNSSEC validation status and interface scope for addresses as | |
43 | necessary for supporting link-local networking).</para></listitem> | |
44 | ||
45 | <listitem><para>The glibc | |
46 | <citerefentry project='man-pages'><refentrytitle>getaddrinfo</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
47 | API as defined by <ulink url="https://tools.ietf.org/html/rfc3493">RFC3493</ulink> and its related | |
48 | resolver functions, including | |
49 | <citerefentry project='man-pages'><refentrytitle>gethostbyname</refentrytitle><manvolnum>3</manvolnum></citerefentry>. | |
50 | This API is widely supported, including beyond the Linux platform. In its current form it does not | |
51 | expose DNSSEC validation status information however, and is synchronous only. This API is backed by the | |
52 | glibc Name Service Switch | |
53 | (<citerefentry project='man-pages'><refentrytitle>nss</refentrytitle><manvolnum>5</manvolnum></citerefentry>). | |
54 | Usage of the glibc NSS module | |
55 | <citerefentry><refentrytitle>nss-resolve</refentrytitle><manvolnum>8</manvolnum></citerefentry> is | |
56 | required in order to allow glibc's NSS resolver functions to resolve hostnames via | |
57 | <command>systemd-resolved</command>.</para></listitem> | |
58 | ||
59 | <listitem><para>Additionally, <command>systemd-resolved</command> provides a local DNS stub listener on | |
60 | IP address 127.0.0.53 on the local loopback interface. Programs issuing DNS requests directly, | |
61 | bypassing any local API may be directed to this stub, in order to connect them to | |
62 | <command>systemd-resolved</command>. Note however that it is strongly recommended that local programs | |
63 | use the glibc NSS or bus APIs instead (as described above), as various network resolution concepts | |
64 | (such as link-local addressing, or LLMNR Unicode domains) cannot be mapped to the unicast DNS | |
65 | protocol.</para></listitem> | |
66 | </itemizedlist> | |
67 | ||
68 | <para>The DNS servers contacted are determined from the global settings in | |
69 | <filename>/etc/systemd/resolved.conf</filename>, the per-link static settings in | |
70 | <filename>/etc/systemd/network/*.network</filename> files (in case | |
71 | <citerefentry><refentrytitle>systemd-networkd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry> | |
72 | is used), the per-link dynamic settings received over DHCP, information provided via | |
73 | <citerefentry><refentrytitle>resolvectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>, and any | |
74 | DNS server information made available by other system services. See | |
75 | <citerefentry><refentrytitle>resolved.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry> and | |
76 | <citerefentry><refentrytitle>systemd.network</refentrytitle><manvolnum>5</manvolnum></citerefentry> for | |
77 | details about systemd's own configuration files for DNS servers. To improve compatibility, | |
78 | <filename>/etc/resolv.conf</filename> is read in order to discover configured system DNS servers, but | |
79 | only if it is not a symlink to <filename>/run/systemd/resolve/stub-resolv.conf</filename>, | |
80 | <filename>/usr/lib/systemd/resolv.conf</filename> or | |
81 | <filename>/run/systemd/resolve/resolv.conf</filename> (see below).</para> | |
82 | ||
83 | </refsect1> | |
84 | ||
85 | <refsect1> | |
86 | <title>Synthetic Records</title> | |
87 | ||
88 | <para><command>systemd-resolved</command> synthesizes DNS resource records (RRs) for the following | |
89 | cases:</para> | |
90 | ||
91 | <itemizedlist> | |
92 | <listitem><para>The local, configured hostname is resolved to all locally configured IP addresses | |
93 | ordered by their scope, or — if none are configured — the IPv4 address 127.0.0.2 (which is on the local | |
94 | loopback) and the IPv6 address ::1 (which is the local host).</para></listitem> | |
95 | ||
96 | <listitem><para>The hostnames <literal>localhost</literal> and <literal>localhost.localdomain</literal> | |
97 | (as well as any hostname ending in <literal>.localhost</literal> or | |
98 | <literal>.localhost.localdomain</literal>) are resolved to the IP addresses 127.0.0.1 and ::1. | |
99 | </para></listitem> | |
100 | ||
101 | <listitem><para>The hostname <literal>_gateway</literal> is resolved to all current default routing | |
102 | gateway addresses, ordered by their metric. This assigns a stable hostname to the current gateway, | |
103 | useful for referencing it independently of the current network configuration state.</para></listitem> | |
104 | ||
105 | <listitem><para>The mappings defined in <filename>/etc/hosts</filename> are resolved to their | |
106 | configured addresses and back, but they will not affect lookups for non-address types (like MX). | |
107 | Support for <filename>/etc/hosts</filename> may be disabled with <varname>ReadEtcHosts=no</varname>, | |
108 | see <citerefentry><refentrytitle>resolved.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>. | |
109 | </para></listitem> | |
110 | </itemizedlist> | |
111 | </refsect1> | |
112 | ||
113 | <refsect1> | |
114 | <title>Protocols and Routing</title> | |
115 | ||
116 | <para>Lookup requests are routed to the available DNS servers, LLMNR, and MulticastDNS interfaces | |
117 | according to the following rules:</para> | |
118 | ||
119 | <itemizedlist> | |
120 | <listitem><para>Names for which synthetic records are generated (as listed in the previous section) are | |
121 | never routed to the network and a reply is sent immediately. In particular this means that lookups for | |
122 | <literal>localhost</literal> are never routed to the network.</para></listitem> | |
123 | ||
124 | <listitem><para>Single-label names are routed to all local interfaces capable of IP multicasting, where | |
125 | LLMNR is not disabled, using the LLMNR protocol. Lookups for IPv4 addresses are only sent via LLMNR on | |
126 | IPv4, and lookups for IPv6 addresses are only sent via LLMNR on IPv6. Lookups for the locally | |
127 | configured hostname and the <literal>_gateway</literal> hostname are never routed to LLMNR. | |
128 | </para></listitem> | |
129 | ||
130 | <listitem><para>Multi-label names with the domain suffix <literal>.local</literal> are routed to all | |
131 | local interfaces capable of IP multicasting, where MulticastDNS is not disabled, using the MulticastDNS | |
132 | protocol. As with LLMNR, IPv4 address lookups are sent via IPv4 and IPv6 address lookups are sent via | |
133 | IPv6.</para></listitem> | |
134 | ||
135 | <listitem><para>Resolution of address records (A and AAAA) via unicast DNS (i.e. not LLMNR or | |
136 | MulticastDNS) for non-synthesized single-label names is only allowed for non-top-level domains. This | |
137 | means that such records can only be resolved when search domains are defined. For any interface which | |
138 | defines search domains, such look-ups are routed to that interface, suffixed with each of the search | |
139 | domains defined on that interface in turn. When global search domains are defined, such look-ups are | |
140 | routed to all interfaces, suffixed by each of the global search domains in turn. The details of which | |
141 | servers are queried and how the final reply is chosen are described below. Note that this means that | |
142 | address queries for single-label names are never sent out to remote DNS servers, and if no search | |
143 | domains are defined, resolution will fail.</para></listitem> | |
144 | ||
145 | <listitem><para>Other multi-label names are routed to all local interfaces that have a DNS server | |
146 | configured, plus the globally configured DNS servers if there are any. Note that by default, lookups for | |
147 | domains with the <literal>.local</literal> suffix are not routed to DNS servers, unless the domain is | |
148 | specified explicitly as routing or search domain for the DNS server and interface. This means that on | |
149 | networks where the <literal>.local</literal> domain is defined in a site-specific DNS server, explicit | |
150 | search or routing domains need to be configured to make lookups within this DNS domain work. Note that | |
151 | these days, it's generally recommended to avoid defining <literal>.local</literal> in a DNS server, as | |
152 | <ulink url="https://tools.ietf.org/html/rfc6762">RFC6762</ulink> reserves this domain for exclusive | |
153 | MulticastDNS use.</para></listitem> | |
154 | ||
155 | <listitem><para>Address lookups are routed similarly to multi-label names, with the exception that | |
156 | addresses from the link-local address range are never routed to unicast DNS and are only resolved using | |
157 | LLMNR and MulticastDNS (when enabled).</para></listitem> | |
158 | </itemizedlist> | |
159 | ||
160 | <para>If lookups are routed to multiple interfaces, the first successful response is returned (thus | |
161 | effectively merging the lookup zones on all matching interfaces). If the lookup failed on all interfaces, | |
162 | the last failing response is returned.</para> | |
163 | ||
164 | <para>Routing of lookups may be influenced by configuring per-interface domain names and other | |
165 | settings. See | |
166 | <citerefentry><refentrytitle>systemd.network</refentrytitle><manvolnum>5</manvolnum></citerefentry> and | |
167 | <citerefentry><refentrytitle>resolvectl</refentrytitle><manvolnum>1</manvolnum></citerefentry> for | |
168 | details. The following query routing logic applies for unicast DNS traffic:</para> | |
169 | ||
170 | <itemizedlist> | |
171 | <listitem><para>If a name to look up matches (that is: is equal to or has as suffix) any of the | |
172 | configured search or route-only domains of any link (see | |
173 | <citerefentry><refentrytitle>systemd.network</refentrytitle><manvolnum>5</manvolnum></citerefentry>), | |
174 | or the globally configured DNS settings (see the discussion of <varname>Domains=</varname> in | |
175 | <citerefentry><refentrytitle>resolved.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>), | |
176 | "best matching" search/route-only domain is determined: the matching one with the most labels. The | |
177 | query is then sent to all DNS servers of any links or the globally configured DNS servers associated | |
178 | with this "best matching" search/route-only domain. (Note that more than one link might have this same | |
179 | "best matching" search/route-only domain configured, in which case the query is sent to all of them in | |
180 | parallel).</para> | |
181 | ||
182 | <para>In case of single-label names, when search domains are defined, the same logic applies, except | |
183 | that the name is first suffixed by the search domain.</para></listitem> | |
184 | ||
185 | <listitem><para>If a query does not match any configured search/route-only domain (neither per-link nor | |
186 | global), it is sent to all DNS servers that are configured on links with the "DNS default route" option | |
187 | set, as well as the globally configured DNS server.</para></listitem> | |
188 | ||
189 | <listitem><para>If there is no link configured as "DNS default route" and no global DNS server | |
190 | configured, the compiled-in fallback DNS server is used.</para></listitem> | |
191 | ||
192 | <listitem><para>Otherwise the query is failed as no suitable DNS servers could be determined. | |
193 | </para></listitem> | |
194 | </itemizedlist> | |
195 | ||
196 | <para>The "DNS default route" option is a boolean setting configurable with <command>resolvectl</command> | |
197 | or in <filename>.network</filename> files. If not set, it is implicitly determined based on the | |
198 | configured DNS domains for a link: if there's any route-only domain (not matching <literal>~.</literal>) | |
199 | it defaults to false, otherwise to true.</para> | |
200 | ||
201 | <para>Effectively this means: in order to support single-label non-synthetized names, define appropriate | |
202 | search domains. In order to preferably route all DNS queries not explicitly matched by search/route-only | |
203 | domain configuration to a specific link, configure a <literal>~.</literal> route-only domain on it. This | |
204 | will ensure that other links will not be considered for these queries (unless they too carry such a | |
205 | route-only domain). In order to route all such DNS queries to a specific link only if no other link | |
206 | is preferable, set the "DNS default route" option for the link to true and do not configure a | |
207 | <literal>~.</literal> route-only domain on it. Finally, in order to ensure that a specific link never | |
208 | receives any DNS traffic not matching any of its configured search/route-only domains, set the "DNS | |
209 | default route" option for it to false.</para> | |
210 | ||
211 | <para>See the <ulink url="https://www.freedesktop.org/wiki/Software/systemd/resolved">resolved D-Bus API | |
212 | Documentation</ulink> for information about the APIs <filename>systemd-resolved</filename> provides. | |
213 | </para> | |
214 | </refsect1> | |
215 | ||
216 | <refsect1> | |
217 | <title><filename>/etc/resolv.conf</filename></title> | |
218 | ||
219 | <para>Four modes of handling <filename>/etc/resolv.conf</filename> (see | |
220 | <citerefentry project='man-pages'><refentrytitle>resolv.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>) are | |
221 | supported:</para> | |
222 | ||
223 | <itemizedlist> | |
224 | <listitem><para><command>systemd-resolved</command> maintains the | |
225 | <filename>/run/systemd/resolve/stub-resolv.conf</filename> file for compatibility with traditional | |
226 | Linux programs. This file may be symlinked from <filename>/etc/resolv.conf</filename>. This file lists | |
227 | the 127.0.0.53 DNS stub (see above) as the only DNS server. It also contains a list of search domains | |
228 | that are in use by systemd-resolved. The list of search domains is always kept up-to-date. Note that | |
229 | <filename>/run/systemd/resolve/stub-resolv.conf</filename> should not be used directly by applications, | |
230 | but only through a symlink from <filename>/etc/resolv.conf</filename>. This file may be symlinked from | |
231 | <filename>/etc/resolv.conf</filename> in order to connect all local clients that bypass local DNS APIs | |
232 | to <command>systemd-resolved</command> with correct search domains settings. This mode of operation is | |
233 | recommended.</para></listitem> | |
234 | ||
235 | <listitem><para>A static file <filename>/usr/lib/systemd/resolv.conf</filename> is provided that lists | |
236 | the 127.0.0.53 DNS stub (see above) as only DNS server. This file may be symlinked from | |
237 | <filename>/etc/resolv.conf</filename> in order to connect all local clients that bypass local DNS APIs | |
238 | to <command>systemd-resolved</command>. This file does not contain any search domains. | |
239 | </para></listitem> | |
240 | ||
241 | <listitem><para><command>systemd-resolved</command> maintains the | |
242 | <filename>/run/systemd/resolve/resolv.conf</filename> file for compatibility with traditional Linux | |
243 | programs. This file may be symlinked from <filename>/etc/resolv.conf</filename> and is always kept | |
244 | up-to-date, containing information about all known DNS servers. Note the file format's limitations: it | |
245 | does not know a concept of per-interface DNS servers and hence only contains system-wide DNS server | |
246 | definitions. Note that <filename>/run/systemd/resolve/resolv.conf</filename> should not be used | |
247 | directly by applications, but only through a symlink from <filename>/etc/resolv.conf</filename>. If | |
248 | this mode of operation is used local clients that bypass any local DNS API will also bypass | |
249 | <command>systemd-resolved</command> and will talk directly to the known DNS servers.</para></listitem> | |
250 | ||
251 | <listitem><para>Alternatively, <filename>/etc/resolv.conf</filename> may be managed by other packages, | |
252 | in which case <command>systemd-resolved</command> will read it for DNS configuration data. In this mode | |
253 | of operation <command>systemd-resolved</command> is consumer rather than provider of this configuration | |
254 | file. </para></listitem> | |
255 | </itemizedlist> | |
256 | ||
257 | <para>Note that the selected mode of operation for this file is detected fully automatically, depending | |
258 | on whether <filename>/etc/resolv.conf</filename> is a symlink to | |
259 | <filename>/run/systemd/resolve/resolv.conf</filename> or lists 127.0.0.53 as DNS server.</para> | |
260 | </refsect1> | |
261 | ||
262 | <refsect1> | |
263 | <title>Signals</title> | |
264 | ||
265 | <variablelist> | |
266 | <varlistentry> | |
267 | <term><constant>SIGUSR1</constant></term> | |
268 | ||
269 | <listitem><para>Upon reception of the <constant>SIGUSR1</constant> process signal | |
270 | <command>systemd-resolved</command> will dump the contents of all DNS resource record caches it | |
271 | maintains, as well as all feature level information it learnt about configured DNS servers into the | |
272 | system logs.</para></listitem> | |
273 | </varlistentry> | |
274 | ||
275 | <varlistentry> | |
276 | <term><constant>SIGUSR2</constant></term> | |
277 | ||
278 | <listitem><para>Upon reception of the <constant>SIGUSR2</constant> process signal | |
279 | <command>systemd-resolved</command> will flush all caches it maintains. Note that it should normally | |
280 | not be necessary to request this explicitly – except for debugging purposes – as | |
281 | <command>systemd-resolved</command> flushes the caches automatically anyway any time the host's | |
282 | network configuration changes. Sending this signal to <command>systemd-resolved</command> is | |
283 | equivalent to the <command>resolvectl flush-caches</command> command, however the latter is | |
284 | recommended since it operates in a synchronous way.</para></listitem> | |
285 | </varlistentry> | |
286 | ||
287 | <varlistentry> | |
288 | <term><constant>SIGRTMIN+1</constant></term> | |
289 | ||
290 | <listitem><para>Upon reception of the <constant>SIGRTMIN+1</constant> process signal | |
291 | <command>systemd-resolved</command> will forget everything it learnt about the configured DNS | |
292 | servers. Specifically any information about server feature support is flushed out, and the server | |
293 | feature probing logic is restarted on the next request, starting with the most fully featured | |
294 | level. Note that it should normally not be necessary to request this explicitly – except for | |
295 | debugging purposes – as <command>systemd-resolved</command> automatically forgets learnt information | |
296 | any time the DNS server configuration changes. Sending this signal to | |
297 | <command>systemd-resolved</command> is equivalent to the <command>resolvectl | |
298 | reset-server-features</command> command, however the latter is recommended since it operates in a | |
299 | synchronous way.</para></listitem> | |
300 | </varlistentry> | |
301 | </variablelist> | |
302 | ||
303 | </refsect1> | |
304 | ||
305 | <refsect1> | |
306 | <title>See Also</title> | |
307 | <para> | |
308 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
309 | <citerefentry><refentrytitle>resolved.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>, | |
310 | <citerefentry><refentrytitle>dnssec-trust-anchors.d</refentrytitle><manvolnum>5</manvolnum></citerefentry>, | |
311 | <citerefentry><refentrytitle>nss-resolve</refentrytitle><manvolnum>8</manvolnum></citerefentry>, | |
312 | <citerefentry><refentrytitle>resolvectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
313 | <citerefentry project='man-pages'><refentrytitle>resolv.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>, | |
314 | <citerefentry project='man-pages'><refentrytitle>hosts</refentrytitle><manvolnum>5</manvolnum></citerefentry>, | |
315 | <citerefentry><refentrytitle>systemd.network</refentrytitle><manvolnum>5</manvolnum></citerefentry>, | |
316 | <citerefentry><refentrytitle>systemd-networkd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry> | |
317 | </para> | |
318 | </refsect1> | |
319 | ||
320 | </refentry> |