Overview
The below snippet from my ~/.bash_aliases should illustrate my feelings towards systemd-resolved:
$ grep resolved ~/.bash_aliases
alias fuck-resolved='sudo systemctl restart systemd-resolved'
For the longest time, I’ve put up with the pain-in-my-ass that is systemd-resolved and the constant issues that it has given me (not to mention the time spent troubleshooting various issues). Today, I intend to resolve my issues once and for all.
There are a ton of “guides” already on the internet (a google search for “disable systemd-resolved” has 179,000 results at the time of writing this).
The blog post My War on Systemd-resolved is a good, quick read and gives some ideas on why the google search results differ ever-so-slightly from each other (but please don’t follow his proposed solution).
Like the above post, I intend to shut down systemd-resolved permanently, and document how (for Ubuntu 18.04 at least).
Disabling systemd-resolved
First up is disabling the systemd-resolved service.
Easy enough using systemctl:
$ sudo systemctl disable systemd-resolved
$ sudo systemctl stop systemd-resolved
Next, we’ll remove the existing “/etc/resolv.conf” file, which is currently a symbolic link to “/run/systemd/resolve/stub-resolv.conf”:
$ ls /etc/resolv.conf -al
lrwxrwxrwx 1 root root 39 Jun 16 2018 /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf
$ sudo rm /etc/resolv.conf
Reconfiguring DNS
There are now two paths you can take to configure your DNS, depending on whether you receive your DNS configuration via DHCP or not.
If you do, then we’ll configure NetworkManager to look after the “/etc/resolv.conf” file.
If you don’t, then simply configure this file statically yourself and you’re good to go.
Using NetworkManager
If you want to use the settings given out via DHCP, we need to reconfigure NetworkManager so that it starts to set this for us.
This is as simple as editing the file “/etc/NetworkManager/NetworkManager.conf” and setting (or adding, if not already present) the dns
and rc-manager
keys under the [main]
section, as below:
[main]
dns=default
rc-manager=resolvconf
Then we’ll restart NetworkManager so that it’ll create us a new “/etc/resolv.conf” file:
sudo systemctl restart network-manager
We can now verify that the new configuration has been picked up by checking the contents of “/etc/resolv.conf”:
$ cat /etc/resolv.conf
# Generated by NetworkManager
search example.com
nameserver 192.168.0.1
nameserver 192.168.0.2
Manual configuration
If you’re not receiving DNS settings over DHCP, or you want to have manual control over this, then you can skip the NetworkManager configuration and simply start manually configuring the “/etc/resolv.conf” file yourself.
Appendices
References
My War on Systemd-resolved
Disabling systemd-resolvd service on Ubuntu systems
AskUbuntu - How do I disable systemd-resolved and replace with something sane on Ubuntu 18?
How to correctly disable systemd-resolved on Ubuntu 18.04
Versions used
Desktop Machine: kubuntu-18.04.3