Difference between revisions of "Systemd-resolved"

From ArchWiki
Jump to navigation Jump to search
(→‎DNSSEC: add instructions to disable DNSSEC)
(→‎Configuration: remove NetworkManager.conf examples, the man pages now list the correct values, so they can be looked up there)
 
(13 intermediate revisions by 7 users not shown)
Line 2: Line 2:
 
[[Category:Domain Name System]]
 
[[Category:Domain Name System]]
 
[[Category:Multicast DNS]]
 
[[Category:Multicast DNS]]
 +
[[es:Systemd-resolved]]
 +
[[ja:Systemd-resolved]]
 
{{Related articles start}}
 
{{Related articles start}}
 
{{Related|systemd-networkd}}
 
{{Related|systemd-networkd}}
Line 11: Line 13:
 
== Installation ==
 
== Installation ==
  
''systemd-resolved'' is a part of the {{Pkg|systemd}} package that is [[install]]ed by default.
+
''systemd-resolved'' is a part of the {{Pkg|systemd}} package that is installed by default.
  
 
== Configuration ==
 
== Configuration ==
Line 50: Line 52:
 
===== Manually =====
 
===== Manually =====
  
In local DNS stub mode, alternative DNS servers are provided in the {{man|5|resolved.conf}} file:
+
In local DNS stub mode, custom DNS server(s) can be set in the {{man|5|resolved.conf}} file:
  
 
{{hc|/etc/systemd/resolved.conf.d/dns_servers.conf|2=
 
{{hc|/etc/systemd/resolved.conf.d/dns_servers.conf|2=
 
[Resolve]
 
[Resolve]
DNS=91.239.100.100 89.233.43.71
+
DNS=192.168.35.1 fd7b:d0bd:7a6e::1
 +
Domains=~.
 
}}
 
}}
  
{{Note|[[Network manager]]s have their own DNS settings that override ''systemd-resolved'''s default.}}
+
{{Note|Without the {{ic|1=Domains=~.}} option in {{man|5|resolved.conf}}, ''systemd-resolved'' might use the per-link DNS servers, if any of them set {{ic|1=Domains=~.}} in the per-link configuration. This option will not affect queries of domain names that match the more specific search domains specified in per-link configuration, they will still be resolved using their respective per-link DNS servers.}}
  
 
===== Fallback =====
 
===== Fallback =====
Line 87: Line 90:
 
DNSSEC=true
 
DNSSEC=true
 
}}
 
}}
 +
 +
{{Tip|If your DNS server does not support DNSSEC and you experience problems with the default allow-downgrade mode (e.g. [https://github.com/systemd/systemd/issues/10579 systemd issue 10579]), you can explicitly disable systemd-resolved's DNSSEC support by setting {{ic|1=DNSSEC=false}}.}}
  
 
Test DNSSEC validation by querying a domain with a invalid signature:
 
Test DNSSEC validation by querying a domain with a invalid signature:
Line 102: Line 107:
 
-- Data is authenticated: yes
 
-- Data is authenticated: yes
 
}}
 
}}
 
Alternatively, if DNS resolution is not working, edit {{ic|/etc/systemd/resolved.conf}} to add a setting of {{ic|DNSSEC=off}} followed by a restart of systemd-resolved.
 
  
 
==== DNS over TLS ====
 
==== DNS over TLS ====
Line 109: Line 112:
 
{{Expansion|How to test if DNS over TLS is used?}}
 
{{Expansion|How to test if DNS over TLS is used?}}
  
{{Warning|As of version 239:
+
{{Warning|systemd-resolved only validates the DNS server certificate if it is issued for the server's IP address (a rare occurrence). DNS server certificates without an IP address are not checked making ''systemd-resolved'' vulnerable to man-in-the-middle attacks. See [https://github.com/systemd/systemd/issues/9397 systemd issue 9397].}}
* Only opportunistic mode is supported making ''systemd-resolved'' vulnerable to downgrade attacks. See [https://github.com/systemd/systemd/issues/10755 systemd issue 10755].
 
* DNS server certificates are not checked making ''systemd-resolved'' vulnerable to man-in-the-middle attacks. See [https://github.com/systemd/systemd/issues/9397 systemd issue 9397].
 
}}
 
  
 
DNS over TLS is disabled by default. To enable it change the {{ic|1=DNSOverTLS=}} setting in the {{ic|[Resolve]}} section in {{man|5|resolved.conf}}.
 
DNS over TLS is disabled by default. To enable it change the {{ic|1=DNSOverTLS=}} setting in the {{ic|[Resolve]}} section in {{man|5|resolved.conf}}.
Line 118: Line 118:
 
{{hc|/etc/systemd/resolved.conf.d/dns_over_tls.conf|2=
 
{{hc|/etc/systemd/resolved.conf.d/dns_over_tls.conf|2=
 
[Resolve]
 
[Resolve]
DNSOverTLS=opportunistic
+
DNSOverTLS=yes
 
}}
 
}}
  
{{Note|The used DNS server must support DNS over TLS otherwise ''systemd-resolved'' will disable DNS over TLS for the connection.}}
+
{{Note|The used DNS server must support DNS over TLS otherwise all DNS requests will fail.}}
  
 
=== mDNS ===
 
=== mDNS ===
Line 129: Line 129:
 
The resolver provides [[hostname]] resolution using a "''hostname''.local" naming scheme.
 
The resolver provides [[hostname]] resolution using a "''hostname''.local" naming scheme.
  
mDNS will only be activated for the connection if both the systemd-resolved's global setting ({{ic|1=MulticastDNS=}} in {{man|5|resolved.conf}}) and the [[Network manager|network manager's]] per-connection setting is enabled. By default ''systemd-resolved'' enables mDNS responder, but both [[systemd-networkd]] and [[NetworkManager]] do not enable it for connections:
+
mDNS will only be activated for the connection if both the systemd-resolved's global setting ({{ic|1=MulticastDNS=}} in {{man|5|resolved.conf}}) and the [[Network manager|network manager's]] per-connection setting is enabled. By default ''systemd-resolved'' enables mDNS responder, but both [[systemd-networkd]] and [[NetworkManager]][https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/301] do not enable it for connections:
  
 
* For [[systemd-networkd]] the setting is {{ic|1=MulticastDNS=}} in the {{ic|[Network]}} section. See {{man|5|systemd.network}}.
 
* For [[systemd-networkd]] the setting is {{ic|1=MulticastDNS=}} in the {{ic|[Network]}} section. See {{man|5|systemd.network}}.
* For [[NetworkManager]] the setting is {{ic|1=mdns=}} in the {{ic|[connection]}} section, see {{man|5|nm-settings}}. The values are {{ic|0}} - disabled, {{ic|1}} - resolver only, {{ic|2}} - resolver and responder. [https://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/libnm-core/nm-setting-connection.h#n102]
+
* For [[NetworkManager]] the setting is {{ic|1=mdns=}} in the {{ic|[connection]}} section. See {{man|5|nm-settings}}.
  
 
{{Note|If [[Avahi]] has been installed, consider [[disabling]] {{ic|avahi-daemon.service}} and {{ic|avahi-daemon.socket}} to prevent conflicts with ''systemd-resolved''.}}
 
{{Note|If [[Avahi]] has been installed, consider [[disabling]] {{ic|avahi-daemon.service}} and {{ic|avahi-daemon.socket}} to prevent conflicts with ''systemd-resolved''.}}
  
{{Tip|The default for all [[NetworkManager]] connections can be set by creating a configuration file in {{ic|/etc/NetworkManager/conf.d/}} and setting {{ic|1=connection.mdns=}} in the {{ic|[connection]}} section. For example the following will enable mDNS resolver for all connections:
+
{{Tip|The default for all [[NetworkManager]] connections can be set by creating a configuration file in {{ic|/etc/NetworkManager/conf.d/}} and setting {{ic|1=connection.mdns=}} in the {{ic|[connection]}} section. See {{man|5|NetworkManager.conf}}.}}
 
 
{{hc|/etc/NetworkManager/conf.d/mdns.conf|2=
 
[connection]
 
connection.mdns=1
 
}}
 
 
 
See {{man|5|NetworkManager.conf}}.
 
}}
 
  
 
If you plan to use mDNS and use a [[firewall]], make sure to open UDP port {{ic|5353}}.
 
If you plan to use mDNS and use a [[firewall]], make sure to open UDP port {{ic|5353}}.
Line 152: Line 144:
 
[[Wikipedia:Link-Local Multicast Name Resolution|Link-Local Multicast Name Resolution]] is a [[hostname]] resolution protocol created by Microsoft.
 
[[Wikipedia:Link-Local Multicast Name Resolution|Link-Local Multicast Name Resolution]] is a [[hostname]] resolution protocol created by Microsoft.
  
LLMNR will only be activated for the connection if both the systemd-resolved's global setting ({{ic|1=LLMNR=}} in {{man|5|resolved.conf}}) and the [[Network manager|network manager's]] per-connection setting is enabled. By default ''systemd-resolved'' enables LLMNR responder; [[systemd-networkd]] and [[NetworkManager]] enable it for connections.
+
LLMNR will only be activated for the connection if both the systemd-resolved's global setting ({{ic|1=LLMNR=}} in {{man|5|resolved.conf}}) and the [[Network manager|network manager's]] per-connection setting is enabled. By default ''systemd-resolved'' enables LLMNR responder; [[systemd-networkd]] and [[NetworkManager]][https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/301] enable it for connections.
  
 
* For [[systemd-networkd]] the setting is {{ic|1=LLMNR=}} in the {{ic|[Network]}} section. See {{man|5|systemd.network}}.
 
* For [[systemd-networkd]] the setting is {{ic|1=LLMNR=}} in the {{ic|[Network]}} section. See {{man|5|systemd.network}}.
* For [[NetworkManager]] the setting is {{ic|1=llmnr=}} in the {{ic|[connection]}} section, see {{man|5|nm-settings}}. The values are {{ic|0}} - disabled, {{ic|1}} - resolver only, {{ic|2}} - resolver and responder.
+
* For [[NetworkManager]] the setting is {{ic|1=llmnr=}} in the {{ic|[connection]}} section. See {{man|5|nm-settings}}.
  
{{Tip|The default for all [[NetworkManager]] connections can be set by creating a configuration file in {{ic|/etc/NetworkManager/conf.d/}} and setting {{ic|1=connection.llmnr=}} in the {{ic|[connection]}} section. For example the following will disable LLMNR for all connections:
+
{{Tip|The default for all [[NetworkManager]] connections can be set by creating a configuration file in {{ic|/etc/NetworkManager/conf.d/}} and setting {{ic|1=connection.llmnr=}} in the {{ic|[connection]}} section. See {{man|5|NetworkManager.conf}}.}}
 
 
{{hc|/etc/NetworkManager/conf.d/llmnr.conf|2=
 
[connection]
 
connection.llmnr=0
 
}}
 
 
 
See {{man|5|NetworkManager.conf}}.
 
}}
 
  
 
If you plan to use LLMNR and use a [[firewall]], make sure to open UDP and TCP ports {{ic|5355}}.
 
If you plan to use LLMNR and use a [[firewall]], make sure to open UDP and TCP ports {{ic|5355}}.

Latest revision as of 10:01, 19 February 2020

systemd-resolved is a systemd service that provides network name resolution to local applications via a D-Bus interface, the resolve NSS service (nss-resolve(8)), and a local DNS stub listener on 127.0.0.53. See systemd-resolved(8) for the usage.

Installation

systemd-resolved is a part of the systemd package that is installed by default.

Configuration

systemd-resolved provides resolver services for Domain Name System (DNS) (including DNSSEC and DNS over TLS), Multicast DNS (mDNS) and Link-Local Multicast Name Resolution (LLMNR).

The resolver can be configured by editing /etc/systemd/resolved.conf and/or drop-in .conf files in /etc/systemd/resolved.conf.d/. See resolved.conf(5).

To use systemd-resolved start and enable systemd-resolved.service.

Tip: To understand the context around the choices and switches, one can turn on detailed debug information for systemd-resolved as described in systemd#Diagnosing a service.

DNS

systemd-resolved has four different modes for handling the Domain name resolution (the four modes are described in systemd-resolved(8)). We will focus here on the two most relevant modes.

  1. Using the systemd DNS stub file - the systemd DNS stub file /run/systemd/resolve/stub-resolv.conf contains the local stub 127.0.0.53 as the only DNS server and a list of search domains. This is the recommended mode of operation. The service users are advised to redirect the /etc/resolv.conf file to the local stub DNS resolver file /run/systemd/resolve/stub-resolv.conf managed by systemd-resolved. This propagates the systemd managed configuration to all the clients. This can be done by replacing /etc/resolv.conf with a symbolic link to the systemd stub:
    # ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
  2. Preserving resolv.conf - this mode preserves /etc/resolv.conf and systemd-resolved is simply a client of this file. This mode is less disruptive as /etc/resolv.conf can continue to be managed by other packages.
Note: The mode of operation of systemd-resolved is detected automatically, depending on whether /etc/resolv.conf is a symlink to the local stub DNS resolver file or contains server names.

Setting DNS servers

Tip: In order to check the DNS actually used by systemd-resolved, the command to use is:
$ resolvectl status
Automatically

systemd-resolved will work out of the box with a network manager using /etc/resolv.conf. No particular configuration is required since systemd-resolved will be detected by following the /etc/resolv.conf symlink. This is going to be the case with systemd-networkd or NetworkManager.

However, if the DHCP and VPN clients use the resolvconf program to set name servers and search domains (see openresolv#Users for a list of software that use resolvconf), the additional package systemd-resolvconf is needed to provide the /usr/bin/resolvconf symlink.

Note: systemd-resolved has a limited resolvconf interface and may not work with all the clients, see resolvectl(1) for more information.
Manually

In local DNS stub mode, custom DNS server(s) can be set in the resolved.conf(5) file:

/etc/systemd/resolved.conf.d/dns_servers.conf
[Resolve]
DNS=192.168.35.1 fd7b:d0bd:7a6e::1
Domains=~.
Note: Without the Domains=~. option in resolved.conf(5), systemd-resolved might use the per-link DNS servers, if any of them set Domains=~. in the per-link configuration. This option will not affect queries of domain names that match the more specific search domains specified in per-link configuration, they will still be resolved using their respective per-link DNS servers.
Fallback

If systemd-resolved does not receive DNS server addresses from the network manager and no DNS servers are configured manually then systemd-resolved falls back to the fallback DNS addresses to ensure that DNS resolution always works.

Note: The fallback DNS are in this order: Cloudflare, Quad9 (without filtering and without DNSSEC) and Google; see the systemd PKGBUILD where the servers are defined.

The addresses can be changed by setting FallbackDNS= in resolved.conf(5). E.g.:

/etc/systemd/resolved.conf.d/fallback_dns.conf
[Resolve]
FallbackDNS=127.0.0.1 ::1

To disable the fallback DNS funtionality set the FallbackDNS option without specifying any addresses:

/etc/systemd/resolved.conf.d/fallback_dns.conf
[Resolve]
FallbackDNS=

DNSSEC

By default DNSSEC validation will only be enabled if the upstream DNS server supports it. If you want to always validate DNSSEC, thus breaking DNS resolution with name servers that do not support it, set DNSSEC=true:

/etc/systemd/resolved.conf.d/dnssec.conf
[Resolve]
DNSSEC=true
Tip: If your DNS server does not support DNSSEC and you experience problems with the default allow-downgrade mode (e.g. systemd issue 10579), you can explicitly disable systemd-resolved's DNSSEC support by setting DNSSEC=false.

Test DNSSEC validation by querying a domain with a invalid signature:

$ resolvectl query sigfail.verteiltesysteme.net
sigfail.verteiltesysteme.net: resolve call failed: DNSSEC validation failed: invalid

Now test a domain with valid signature:

$ resolvectl query sigok.verteiltesysteme.net
sigok.verteiltesysteme.net: 134.91.78.139

-- Information acquired via protocol DNS in 266.3ms.
-- Data is authenticated: yes

DNS over TLS

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: How to test if DNS over TLS is used? (Discuss in Talk:Systemd-resolved#)
Warning: systemd-resolved only validates the DNS server certificate if it is issued for the server's IP address (a rare occurrence). DNS server certificates without an IP address are not checked making systemd-resolved vulnerable to man-in-the-middle attacks. See systemd issue 9397.

DNS over TLS is disabled by default. To enable it change the DNSOverTLS= setting in the [Resolve] section in resolved.conf(5).

/etc/systemd/resolved.conf.d/dns_over_tls.conf
[Resolve]
DNSOverTLS=yes
Note: The used DNS server must support DNS over TLS otherwise all DNS requests will fail.

mDNS

systemd-resolved is capable of working as a multicast DNS resolver and responder.

The resolver provides hostname resolution using a "hostname.local" naming scheme.

mDNS will only be activated for the connection if both the systemd-resolved's global setting (MulticastDNS= in resolved.conf(5)) and the network manager's per-connection setting is enabled. By default systemd-resolved enables mDNS responder, but both systemd-networkd and NetworkManager[1] do not enable it for connections:

Note: If Avahi has been installed, consider disabling avahi-daemon.service and avahi-daemon.socket to prevent conflicts with systemd-resolved.
Tip: The default for all NetworkManager connections can be set by creating a configuration file in /etc/NetworkManager/conf.d/ and setting connection.mdns= in the [connection] section. See NetworkManager.conf(5).

If you plan to use mDNS and use a firewall, make sure to open UDP port 5353.

LLMNR

Link-Local Multicast Name Resolution is a hostname resolution protocol created by Microsoft.

LLMNR will only be activated for the connection if both the systemd-resolved's global setting (LLMNR= in resolved.conf(5)) and the network manager's per-connection setting is enabled. By default systemd-resolved enables LLMNR responder; systemd-networkd and NetworkManager[2] enable it for connections.

Tip: The default for all NetworkManager connections can be set by creating a configuration file in /etc/NetworkManager/conf.d/ and setting connection.llmnr= in the [connection] section. See NetworkManager.conf(5).

If you plan to use LLMNR and use a firewall, make sure to open UDP and TCP ports 5355.

Lookup

To query DNS records, mDNS or LLMNR hosts you can use the resolvectl utility.

For example, to query a DNS record:

$ resolvectl query archlinux.org
archlinux.org: 2a01:4f8:172:1d86::1
               138.201.81.199

-- Information acquired via protocol DNS in 48.4ms.
-- Data is authenticated: no

See resolvectl(1) for more examples.