2

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 time, 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 are 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.

  • Network Manager will not write out the namesservers adresses to dnsmasq. If your goal is only the use of DNS service from Dnsmasq, so you could keep systemd-resolved running and consistent for later upgrades. See askubuntu.com/questions/1032450/… – cmak.fr Mar 3 at 8:36
  • Thanks @cmak.fr, were you able to make it work? I.e., in step 4 of askubuntu.com/questions/1032450, both systemd-resolved and dnsmasq are listening on port 53, but my Ubuntu complains about it, and wouldn't let dnsmasq start. just as explained in superuser.com/questions/1336296. Thus, I want to completely disable systemd-resolved, and replace it with dnsmasq. – xpt Mar 3 at 13:43
  • yes it works, the link i provided is the feedback i made about my setup... both dnsmasq and systemd-resolved listen on port 53 but on different loopback addresses. Have a closer look to the dnsmasq configuration. – cmak.fr Mar 3 at 19:10
  • I still haven't heard any particular reason to do this. Both can run at the same time. Are you needing the DHCP part of dnsmasq, or the DNS part? If you follow my answer, you can disable the DNS part of systemd-resolved. – heynnema Mar 6 at 13:50
  • Oh, thanks for the reminder @heynnema, actually dnsmasq does a whole lot more than systemd-resolved; See gist.github.com/jult/4eba88bdd34a57cc79d6#gistcomment-1706666 and gist.github.com/jult/4eba88bdd34a57cc79d6#file-hostsupdater-sh to name but a few. Now, I was waiting for the notification from the site actually, because what I hope the answer be is to list the correct steps on how to replace systemd-resolved with dnsmasq, instead of correcting what I've been doing wrong. Don't get me wrong, I'm very grateful for your help, but I am hoping that it could benefit the other peoples as well. – xpt Mar 6 at 21:40
1

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

  • I explained why dnsmasq is preferable than systemd-resolved in above. Now, the problem is my Ubuntu complains about something is already listening on port 53, and wouldn't let dnsmasq start. just as explained in superuser.com/questions/1336296. Thus, I want to completely disable systemd-resolved, and replace it with dnsmasq. – xpt Mar 6 at 21:53
  • @xpt correct... when dnsmasq and systemd-resolved are run at the same time, they step on each others toes. My answers tell systemd-resolved to back off, and let dnsmasq do its thing. Real easy. Just try it. Follow this answer, or for a more complete answer, see my other detailed answer. – heynnema Mar 6 at 23:16
  • I marked the answer as the solution only out of politeness -- I followed it word for word and it did not work for me, but I thought it was my own problem so I accepted the answer. However, I've done another fresh installation of Ubuntu again (Ubuntu 18.04.2 LTS) again this time but again it doesn't work for me. I didn't change any setting in /etc/dnsmasq.conf. Maybe I should (dnsmasq doesn't work out of the box)? – xpt Jul 15 at 2:39
  • By "did not work" I meant I can see dnsmasq is listening on ':53' via netstat, but dig cnn.com or any DNS query times out. – xpt Jul 15 at 2:42
  • Edit your question and show me dpkg -l *dnsmasq* and ls -al /etc/resolv.conf and grep -i stub /etc/systemd/resolved.conf and cat /etc/NetworkManager/NetworkManager.conf – heynnema Jul 15 at 12:38
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.

  • Thanks for the feedback and welcome to askubuntu M-Jack, could you list the detailed steps on how you replaced systemd-resolved with dnsmasq please? Moreover, the /etc/netplan/*.yaml should not be working under 18.04, "This information belongs in NetworkManager GUI connection profile, or ... in NetworkManager speak... not netplan speak..." as put by heynnema, so it shall not work "out of the box", you need to confirm your details. For more info, refer to askubuntu.com/questions/1122836. – xpt Mar 12 at 13:23
  • Maybe there is a confusion here is about the Ubuntu type of OS : I am commenting on server edition, not the desktop one. Editing /etc/netplan/*.yaml is something that I do first thing after after the OS initial install, it works like a charm. After initial install, dnsmasq-base is installed. Then, if the server I am working on is supposed to be a local DNS / DHCP server, I install the two packages dnsmasq and dnsmasq-utils. I only had issue here with 16.04 upgraded systems to 18.04. That is why I reinstall all my servers with a fresh 18.04 – M-Jack Mar 12 at 13:45
  • Got you M-Jack, you're working on server edition, not the desktop one that I'm on. thx. – xpt Mar 12 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.