2

I have dnsmasq running on a raspberry pi w/Raspbian. The pi has a wifi stick on wlan0 and is connected to the local network/internet on eth0. My goal is to have dnsmasq resolve all hosts to the pi's static IP only for wifi connections. This is my dnsmasq.conf

address=/#/192.168.42.1
interface=wlan0

Now however, when I ssh to the pi through eth0 and ping google.com it resolves to 192.168.42.1 also. Perhaps that's because of this (from the man page):

Dnsmasq automatically adds the loopback (local) interface to the list of interfaces to use when the --interface option is used

If so, how can I make it so that dnsmasq only listens to the wifi connections?

Workaround Solution

For my purposes it was ok for the logic to be: "If an ethernet cable is plugged in, turn off dnsmasq. If an ethernet cable is unplugged, turn it back on".

Therefore, I used ifplugd to manage the process. In the file /etc/ifplugd/ifplud.action I added service dnsmasq stop to the "up" case and service dnsmasq start to the "down" case. Full success!

2 Answers 2

1

try instead

except-interface=eth0

to avoid dnsmasq listening to eth0

0
1

You’re going about this the wrong way. dnsmasq isn’t at fault at all.

Most DNS resolvers on Linux use /etc/resolv.conf. What’s defined there is interface-independent. In fact, it has to be: You don’t know which interface and route to take unless you have the numeric IP address.

So basically what you want cannot be done.

Unless, of course, it isn’t actually meant for the dnsmasq host at all, but the WiFi clients or whatever. In that case, you need to remove the local DNS responder from resolv.conf and make it use upstream (your router, ISP, Google DNS, OpenDNS, ...) directly.

A typical resolv.conf could look like this when using Google DNS:

nameserver 8.8.8.8
nameserver 8.8.4.4
4
  • Thanks for your help. I'm not sure I understand what you mean by "Unless, of course, it isn’t actually meant for the dnsmasq host at all, but the WiFi clients or whatever." I am sure that what I want to do is possible because I've done it before. Unfortunately I no longer have access to that device though. The behavior appears to be related to dnsmasq because when it is running my /etc/resolv.conf is set to nameserver 127.0.0.1 by resolvconf and when it isn't running that line reads nameserver 192.168.1.254. Shouldn't dnsmasq know which interface the request comes from?
    – owise1
    Jun 9, 2015 at 21:24
  • Sure it knows where the request comes from. It’s just that it always comes from lo when using nameserver 127.0.0.1.
    – Daniel B
    Jun 10, 2015 at 5:52
  • 1
    What you want is to avoid whatever is setting your nameserver to 127.0.0.1 in resolvconf. It may be dnsmasq doing it by default unless you use the option not to.
    – qasdfdsaq
    Jun 11, 2015 at 16:32
  • See also this answer. You need to add DNSMASQ_EXCEPT=lo to the file /etc/default/dnsmasq. (IGNORE_RESOLVCONF=yes didn't work for me).
    – Splines
    Mar 12, 2022 at 0:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .