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,245
xpt
  • 1,045
  • 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 https://askubuntu.com/questions/1032450/how-to-add-dnsmasq-and-keep-systemd-resolved-18-04 – cmak.fr Mar 03 '19 at 08:36
  • Thanks @cmak.fr, were you able to make it work? I.e., in step 4 of https://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 https://superuser.com/questions/1336296/. Thus, I want to completely disable systemd-resolved, and replace it with dnsmasq. – xpt Mar 03 '19 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 03 '19 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 06 '19 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 06 '19 at 21:40
  • So I edited the answer myself, but my pending editing was somehow rejected by someone, and I didn't know a thing until now. So, again, @heynnema, would you give another answer that details the correct steps on how to replace systemd-resolved with dnsmasq please? because from the comments of "the" answer, https://askubuntu.com/questions/898605/, at least two people found the answer incomplete. I need the DNS part of dnsmasq, not DHCP, BTW. – xpt Mar 06 '19 at 21:45
  • @xpt If you follow my answer, dnsmasq will provide DNS, and systemd-resolved will not... without having to disable anything. I mention this in my other answer to you earlier. Am I missing more? – heynnema Mar 06 '19 at 23:15
  • @xpt fyi: you normally don't edit somebody else's answer, you create your own comment or answer. – heynnema Mar 06 '19 at 23:20
  • Just edit the file /etc/resolv.conf and put nameserver 127.0.0.1 (dnsmasq) and make this file read-only - it will prevent any service from overriding its contents. As for resolved just disable the service entirely sudo systemctl disable systemd-resolved.service. – Michal Przybylowicz Jul 16 '19 at 12:41
  • Thanks @MichalPrzybylowicz, that's what I used to do, and I want to do it properly this time, not heavy-handedly patching up. :-) – xpt Jul 16 '19 at 12:47

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
  • 70,711
  • 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 06 '19 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 06 '19 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 '19 at 02: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 '19 at 02: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 '19 at 12:38
  • @xpt Since you have all 3 dnsmasq* software installed, you need to disable that functionality in systemd-resolve. Also, your symlink for /etc/resolv.conf is wrong. My answer is exactly what you need to do. – heynnema Jul 16 '19 at 04:39
  • I've removed resolvconf. See updated OP. I.e., I don't have /run/resolvconf/resolv.conf. Thanks a lot for your help. – xpt Jul 16 '19 at 11:47
  • Why did you remove resolvconf? Sigh. It still looks like you're trying to defeat the system. How do you expect that somebody can help when you've made all of these mods? Backup your data, and just reinstall a vanilla Ubuntu. It should work fine then. – heynnema Jul 16 '19 at 14:53
  • I'm "old-fashioned" -- I've been removing resolvconf ever since it was in my way and had been able to get away with it. Only start looking at the new NetworkManager approach recently, maybe I should have waited even more longer for its documentation to catch up. Anyway, OK, will find some time to do. Thanks again for all your help. – xpt Jul 16 '19 at 23:06
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
  • 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 https://askubuntu.com/questions/1122836/. – xpt Mar 12 '19 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 '19 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 '19 at 17:04
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.

  • thanks a lot for the clear steps. One question link -s /etc/resolv.conf to /run/systemd/resolve/resolv.conf instead of /run/systemd/resolve/stub-resolv.conf, can you give the actual linux command to use pls? because I'm a bit confused which to replace which. thx. – xpt Jan 05 '20 at 15:13