How to properly disable systemd-resolved
On my Ubuntu Eoan laptop, I find that systemd-resolved sporadically inexplicably fails to respond to local DNS requests to 127.0.0.53 even when requests to my router's DNS server still work, so I want to keep things simple and cut off systemd-resolved.
(Specifically, after the WiFi disconnects and then reconnects, the local DNS server at 127.0.0.53 provided by systemd-resolved in /etc/resolv.conf stops responding to requests until I manually 'systemctl restart systemd-resolved'.)
I'm using a Wireless network with DHCP with wicd, normally controlling it with wicd-gtk. How can I configure my system properly so that under a WiFi connection with DHCP, I'll use the DNS server assigned by the DHCP? I've disabled the systemd-resolved service but that seemed insufficient. That just left behind a /etc/resolv.conf symlinked to a non-existent /run/systemd/resolve/stub-resolv.conf. Even if I remove that, a /etc/resolv.conf file gets created by NetworkManager pointing to the useless 127.0.0.53 when I reconnect to the WiFi. Even if I remove that file and stop NetworkManager and then reconnect to the WiFi, I get no /etc/resolv.conf, so DNS lookups have no server to use.
How can I configure wicd or my system's network settings properly to do the normal setting up of the DNS server in addition to the setting up of the local IP address, subnet and gateway under the WiFi DHCP? I normally use wicd-gtk to manually select a WiFi to connect to. Also, there's no problem with the WiFi, as other devices have no problems and previously with systemd-resolved running it sometimes worked and sometimes didn't work. Also, I'm trying to avoid using NetworkManager because I'm using xmonad without a system-tray so I can't easily use the NetworkManager system-tray GUI.
One thing that looks quite very suspicious to me in the system log after I connected to the WiFi is that systemd-resolved did not restart after dhclient got a DHCPACK. systemd-resolved got started just before that when presumably the network was still not ready. So, it seems that /etc/dhcp/dhclient-enter-hooks.d/resolved is not working as intended.
EDIT: It seems that by disabling systemd-resolved, I have run into a known bug: https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1745463
Solution 1:
The sporadic problem sounds like bugs 1396379 and 1805027 and 1804487. I found the solution to my sporadic 18.04 name resolution failures was to add the package libnss-resolve. This altered the /etc/nsswitch.conf hosts line to be:
hosts: files mdns4_minimal [NOTFOUND=return] resolve [!UNAVAIL=return] dns myhostname
No other changes were needed to the default install. Leave the /etc/resolv.conf link to the default stub-resolv.conf.
Solution 2:
To disable systemd-resolved:
sudo systemctl disable systemd-resolved.service
sudo systemctl stop systemd-resolved
Delete the symlink /etc/resolv.conf, so you can edit it.
sudo rm /etc/resolv.conf
Create a new resolv.conf file, and input the DNS Server that you would like to use.
If you use dhclient, it won't update /etc/resolv.conf with the values sent bythe server (or by supersede/prepend directives in your own client configuration!!!) unless you delete the following file:
sudo rm /etc/dhcp/dhclient-enter-hooks.d/resolved
I have tried this and can confirm it works in Ubuntu Focal. Note that this covers the case of using dhclient alone with ifupdown, not with Netplan, not with NetworkManager, nor wicd, not even resolvconf. All those configurations need different steps to work without systemd-resolved or when disabling other components of the systemd networking stack.
References:
this lifesaver blog entry
this lifesaver askubuntu answer