Following How to disable systemd-resolved and resolve DNS with dnsmasq?
However, I followed it as much as I could, but still wasn't able to properly replace systemd-resolved with dnsmasq --
If i put dns=dnsmasq
under [main]
in /etc/NetworkManager/NetworkManager.conf
, then the nameserver
in my /etc/resolv.conf
will be my ISP's, not my dnsmasq
. If removing it, then the nameserver
in my /etc/resolv.conf
will remain to be systemd-resolved
's, i.e., 127.0.0.53
So all in all, how to properly use dnsmasq as system DNS service?
- I've removed
resolvconf
, and now the question is, - how to replace systemd-resolved with dnsmasq?
PS.
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.1 LTS
Release: 18.04
Codename: bionic
UPDATE:
I've actually tried two times, with the latest attempt from a fresh Lubuntu 18.04.2 LTS installation, and both cases did not work. By "did not work" I meant I can see dnsmasq
is listening on ':53
' via netstat
, but dig cnn.com
and/or any DNS query times out.
Here is the updated info. Note that I've reverted my changes and am now back to using systemd-resolved. So results like grep -i stub /etc/systemd/resolved.conf
reflect my current stage (back to systemd-resolved
).
$ dpkg -l '*dnsmasq*'
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-===================-==============-==============-===========================================
ii dnsmasq 2.79-1 all Small caching DNS proxy and DHCP/TFTP serve
ii dnsmasq-base 2.79-1 amd64 Small caching DNS proxy and DHCP/TFTP serve
un dnsmasq-base-lua <none> <none> (no description available)
ii dnsmasq-utils 2.79-1 amd64 Utilities for manipulating DHCP leases
$ ls -al /etc/resolv.conf
lrwxrwxrwx 1 root root 35 2019-07-14 22:07 /etc/resolv.conf -> /var/run/NetworkManager/resolv.conf
$ grep -i stub /etc/systemd/resolved.conf
#DNSStubListener=yes
$ cat /etc/NetworkManager/NetworkManager.conf
[main]
plugins=ifupdown,keyfile
[ifupdown]
managed=false
[device]
wifi.scan-rand-mac-address=no
# I've removed `resolvconf`:
$ dpkg -l '*resolvconf*'
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-===================-==============-==============-===========================================
un resolvconf <none> <none> (no description available)
$ sudo ls /run/resolvconf/resolv.conf
ls: cannot access '/run/resolvconf/resolv.conf': No such file or directory
UPDATE2:
I now think I know what went wrong -- after the change (following all the steps in the answer), I checked the content of /etc/resolv.conf
, and found its content remains the same. I.e., still having nameserver 127.0.0.53
.
Now I recall that nameserver 127.0.0.53
is for systemd-resolved
, whereas for dnsmasq
, it should be nameserver 127.0.0.1
. That's why all DNS queries are timing out.
I.e., there is one step missing from the answer, which is to change nameserver
to 127.0.0.1
in /etc/resolv.conf
, which I don't know how.
I don't know why you're trying to replace systemd-resolved, but if you need to run them at the same time...
Regarding
dnsmasq
andsystemd-resolved
...Do a
ps auxc | grep -i dns
andps auxc | grep -i resolv
and look fordnsmasq
andsystemd-resolved
, and if both are running, you need to disable the DNS part ofsystemd-resolved
by editing/etc/systemd/resolved.conf
and...change:
to:
then restart systemd-resolve and dnsmasq, or reboot.
You need to reset the symlink that is /etc/resolv.conf
sudo mv /etc/resolv.conf /etc/resolv.conf.OLD
# save the old symlinksudo ln -s /run/resolvconf/resolv.conf /etc/resolv.conf
I had the same issue, but only on 16.04 systems updated to 18.04. I am also using dnsmasq as my LAN DNS and DHCP server. On a freshly installed 18.04, it is working out of the box, without having to modify
/etc/systemd/resolved.conf
(DNSStubListener).This and other differences are anoying especially when using configuration management tools like ansible (for instance the network definition that is defined under
/etc/network/interfaces
for 16.04 or under/etc/netplan/01-netcfg.yaml
for 18.04)So I finally decided to reinstall all my servers with a fresh 18.04 instead of an upgrade.
I use Ubuntu (freshly installed) 18.04.03 router for my home computers. The router gets the name server from the internet provider. I use
dnsmasq
for dns and dhcp in my home network. Begin fromModify
/etc/systemd/resolved.conf
:Check if /etc/resolv.conf linked. Then modify link /etc/resolv.conf to /run/systemd/resolve/resolv.conf instead of /run/systemd/resolve/stub-resolv.conf
Then
After all reboot and dns server should be right in
/etc/resolv.conf
.