6

Every time I (re)start dnsmasq it replaces /etc/resolv.conf with nameserver 127.0.0.1 ....

However that maschine has not to use the local DNS service. (Please don't ask why, the whole environment is like it is...)

How do I actually prevent dnsmasq from touching /etc/resolv.conf?

Neither removing resolvconf nor chattr +i /etc/resolv.conf is an option.

4 Answers 4

7

dnsmasq itself is not altering resolv.conf If you have your configuration file and start it manually via dnsmasq -d -C <yourconfig> you see that.

This behaviour comes from systemd unit on debian and probably on ubuntu systems and perhaps on other distributions.

Stop dnsmasq via sudo systemctl stop dnsmasq (because otherwise changed /etc/resolv.conf won't be restored) edit /etc/systemd/system/multi-user.target.wants/dnsmasq.service and comment out both lines

#ExecStartPost=/etc/init.d/dnsmasq systemd-start-resolvconf #ExecStop=/etc/init.d/dnsmasq systemd-stop-resolvconf 

exec sudo systemctl daemon-reload

after that you can start dnsmasq and your /etc/resolv.conf file won't be changed by dnsmasq

3

You can have dnsmasq use a different resolv.conf file, so when /etc/resolv.conf points to 127.0.0.1, dnsmasq will actually just use the other resolv.conf file and leave /etc/resolv.conf alone.

Add the following line to your dnsmasq.conf file:

resolv-file=/etc/dnsmasq.d/dnsmasq-resolv.conf 

And then create the file /etc/dnsmasq.d/dnsmasq-resolv.conf to look something like this:

nameserver 208.67.222.222 nameserver 208.67.220.220 
3
  • Unfortunately this doesn't help. Commented Feb 24, 2017 at 22:34
  • So, it looks like I missed something. I'm guessing it's related to your DNS configuration, and that you have a "real" DNS server listening on 127.0.0.1, other than dnsmasq, which is why /etc/resolv.conf cannot point to 127.0.0.1 (as you said you don't want the local machine using the local DNS)? Would the no-resolv option for dnsmasq help? Have I completely missed the crux of your question? Commented Feb 24, 2017 at 23:07
  • The maschine runs no dns server other than dnsmasq. No, no-resolv doesn't help. Commented Feb 25, 2017 at 9:47
2
  1. systemctl disable resolvconf.service
  2. systemctl stop resolvconf.service
  3. rm -f /etc/resolv.conf
  4. echo 'nameserver 8.8.8.8' > /etc/resolv.conf # or any other IP you want to use as DNS server
  5. systemctl restart dnsmasq.service # just for testing
  6. cat /etc/resolv.conf # just to verify

The machine won't be able to get the DNS server address(es) via DHCP, but it solves the problem.

1

I had the same issue. On debian bullseye, when resolvconf is installed (which is the case by default, if I am not mistaken) then dnsmasq will have this behavior. You should edit the /etc/default/dsnmasq file and uncomment this line:

# If the resolvconf package is installed, dnsmasq will tell resolvconf # to use dnsmasq under 127.0.0.1 as the system's default resolver. # Uncommenting this line inhibits this behaviour. #DNSMASQ_EXCEPT="lo" 

into

# If the resolvconf package is installed, dnsmasq will tell resolvconf # to use dnsmasq under 127.0.0.1 as the system's default resolver. # Uncommenting this line inhibits this behaviour. DNSMASQ_EXCEPT="lo" 

It worked for me.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.