I recently installed my EPSON L3150 printer's drivers and about the same time I started having weird (and random) DNS name resolution errors in some applications (ssh, nextcloud-client), that I can only fix by restarting the NetworkManager service:
systemctl restart NetworkManager
For example:
$ ssh example.mydomain
ssh: Could not resolve hostname example.mydomain: Name or service not known
Another example is getent, which returns nothing and exits with code 2:
$ getent hosts example.mydomain
$ echo $?
2
But nslookup works fine:
$ nslookup example.mydomain
...
Name: example.mydomain
Address: 192.168.0.10
I narrowed it down to my nsswitch.conf file, which I blame my printer installer for changing it. I found a nsswitch.conf.bak lying besides a nsswitch.conf, created at the same time that I installed the printer drivers using dnf install epson/*.rpm.
The file had this change in the hosts line:
-hosts: files dns myhostname
+hosts: files myhostname mdns4_minimal [NOTFOUND=return] resolve [!UNAVAIL=return] dns
So the question is, why does the "new" configuration fail so randomly? How can I prevent it? I don't think just restoring the original file would be a solution since the new file seems to be auto-generated, it says so right at the top:
Generated by authselect on Sat Feb 12 18:53:06 2022
Uninstalling the driver would also not be a solution.
EDIT:
The culprit seems to be systemd-resolved. My network config is managed by NetworkManager and I setup two DNSs:
$ nmcli con show my-lan
...
ipv4.dns 192.168.0.1 8.8.8.8
It seems that whenever my computer wakes up from sleep, NetworkManager falls back to the second DNS:
$ systemd-resolve --status
...
Link 2 (enp39s0)
Current Scopes: DNS LLMNR/IPv4 LLMNR/IPv6
Protocols: +DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 8.8.8.8
DNS Servers: 192.168.0.1 8.8.8.8
DNS Domain: mydomain
Thus causing systemd-resolve example.mydomain to fail (because 8.8.8.8 can't resolve my domain):
query: resolve call failed: 'example.mydomain' not found
I guess it's a bug in NetworkManager?