systemd-resolved does not query dns server for local domain
Since upgrading to 17.04 I can no longer resolve addresses in my local network (silvesternet.local). I get the following response:
$ systemd-resolve edgerouter
edgerouter: resolve call failed: No appropriate name servers or networks for name found
In the journal there are only reports of timeouts for transaction related to this lookup.
I used Wireshark to sniff the network traffic, and it seems that it does not even try to lookup the name. There is no dns traffic whatsoever. Looking up another external domain works just fine.
Many issues around the same topic mention changing nsswitch.conf, but that does not seem to solve anything. My current settings are:
hosts: files mdns4_minimal dns [NOTFOUND=return] resolve [!UNAVAIL=return] mdns4
Solution 1:
I believe this is by design.
Ubuntu 17.04 has switched to systemd-resolved for name resolution and it uses only LLMNR (multicast name lookup) for single-label names resolution. See this link for details: https://www.freedesktop.org/software/systemd/man/systemd-resolved.service.html
For the reasoning behind this decision check out poettering's reply in this bug report: https://github.com/systemd/systemd/issues/2514
UPD: This issue can be worked around by using a domain for local network. If network interface is configured (either manually or by DHCP) to use a search domain then systemd-resolved will add this domain to single-label names and then look them up via unicast DNS.
Obviously the local DNS server should be reconfigured to recognise these domain. In case of dnsmasq that reads local host-to-IP pairs from /etc/hosts it can be accomplished by adding following instructions to dnsmasq.conf:
domain=mydomain.net
local=/mydomain.net/
expand-hosts
UPD2: Or you could just revert to dnsmasq as described here https://askubuntu.com/a/911432/692094
Solution 2:
I got the same problem on Ubuntu 18.04, which also use systemd-resolved for DNS. Its default configuration does not resolve single-label hostnames or .local domain hostnames by DNS, but by LLMNR or mDNS respectively.
To make local single-label hostnames or .local domain hostnames resolved by DNS, I enabled the 3rd of the "Four modes of handling /etc/resolv.conf" described in the man page for systemd-resolved.service:
sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
A similar answer was given here. And again, for the reasoning behind the default, see poettering's reply in this bug report.