3

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.

LifeBoy
  • 2,392
xpt
  • 1,197

3 Answers3

2

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 and systemd-resolved...

Do a ps auxc | grep -i dns and ps auxc | grep -i resolv and look for dnsmasq and systemd-resolved, and if both are running, you need to disable the DNS part of systemd-resolved by editing /etc/systemd/resolved.conf and...

change:

#DNSStubListener=yes

to:

DNSStubListener=no

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 symlink

sudo ln -s /run/resolvconf/resolv.conf /etc/resolv.conf

heynnema
  • 73,649
0

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.

M-Jack
  • 101
0

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 from

systemctl stop systemd-resolved

Modify /etc/systemd/resolved.conf:

...
#DNSStubListener=yes
DNSStubListener=no

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

rm /etc/resolv.conf
ln -s /etc/resolv.conf /run/systemd/resolve/resolv.conf

Then

systemctl start dnsmasq

After all reboot and dns server should be right in /etc/resolv.conf.