Ubuntu 16.10+ uses systemd-resolved
as DNS resolver.
I prefer the setup 16.04 uses, dnsmasq
as the resolver.
How can I do that on 16.10+, especially on 17.04?
Ubuntu 16.10+ uses systemd-resolved
as DNS resolver.
I prefer the setup 16.04 uses, dnsmasq
as the resolver.
How can I do that on 16.10+, especially on 17.04?
dnsmasq
packages are still available in 16.10 and 17.04.Install
dnsmasq
and dependencies (or at least download their packages) before disablingsystemd-resolved
:Disable
systemd-resolved
and verifydnsmasq
is running:Season
dnsmasq
to taste. After applying your settings, restartdnsmasq
:After step 2 you might be without a working system resolver until step 3 is complete. You may need to restart the networking subsystem (or simply reboot) to get
dnsmasq
functioning with the default configs. In my testing, adding a known DNS server to/etc/dnsmasq.conf
and restartingdnsmasq
was enough to get it working in a liveCD environment.In addition to the answer of @quixotic:
Make sure you have in /etc/NetworkManager/NetworkManager.conf :
if you need to add it, restart NetworkManager like this:
and
/etc/resolv.conf
needs to be a symlink to/var/run/NetworkManager/resolv.conf
. could be done like thisFor (X)Ubuntu 18.04 (see my answer at stackexchange).
Here is copy of it (should I make a copy?)
Here is solution for (X)Ubuntu 18.04 Bionic.
Install dnsmasq
sudo apt install dnsmasq
Disable systemd-resolved listener on port 53 (do not touch /etc/systemd/resolved.conf, because it may be overwritten on upgrade):
and restart it
(alternatively disable it completely by
$ sudo systemctl disable systemd-resolved.service
)Delete /etc/resolv.conf and create again. This is important, because resolv.conf is a symbolic link to /run/systemd/resolve/stub-resolv.conf by default. If you will not delete symbolic link, the file will be overwritten by systemd on reboot (even though we disabled systemd-resolved!). Also NetworkManager (NM) checks if it is a symbolic link to detect systemd-resolved configuration.
Disable overwriting of /etc/resolv.conf by NM (there is also an option rc-manager, but it does not work, despite it is described in a manual):
and restart it:
Tell dnsmasq to use resolv.conf from NM:
and restart it:
Use dnsmasq for resolving:
According to the manual of systemd-resolved, systemd-resolved provides with name resolution services via three different interfaces:
It seems that the first two interfaces won't interfere in normal DNS resolution and for me the problem is likely to reside on the third.
In the manual of nss-resolve:
So what is needed is to make "dns" precedes "resolve" in "host:" line of /etc/nsswitch.conf. And then
getaddrinfo
should simply adhere to /etc/resolv.conf .This solution only prevents systemd-resolved from handling all the DNS resolution requests and is not restricted to a specific network manager. And it also makes sure LLMNR and mDNS service are operating normally.
( I am not fair familiar with how name resolution works under Linux and also unsure about what I understood from these manuals. Pleaes point out if I got something wrong. Thx :) )