DNSMasq responds randomly

1

I have just installed DNSMasq on a local device (Raspberry Pi) to use as a DNS server but the service is not always working correctly when other computers in the network try to use it. This is what I added to the /etc/dnsmasq.conf file:

log-queries
no-resolv
server=8.8.8.8
server=8.8.4.4

This is the /etc/hosts file:

192.168.1.101   desktop.home
192.168.1.102   laptop.home

I'm not using DHCP, DHCP is done by my router. My router has the option to manually configur the DNS server and I put the Raspberry Pi IP address (192.168.1.100) in that field. I can confirm that both my desktop and laptop (Linux machines) are aware of the new DNS server (DNSMasq at 192.168.1.100).

Both my desktop and laptop are connected by cable. When I run nslookup laptop.home from my desktop, for example, I get 50% hit more or less - sometimes I get a successful result sometimes I don't. Same thing from the laptop.

What's even more strange is that when I connect the laptop to wifi the hits get low even more. I only get 10% hits or less on my laptop on wifi. Really strange.

The logs don't say anything. I don't even know where to start to debug this.

kapus

Posted 2018-07-31T15:12:24.237

Reputation: 13

1Check what IP for DNS you're actually getting via DHCP. If it's windows then you can use ipconfig in a command prompt to see. – djsmiley2k TMW – 2018-07-31T15:23:04.150

Yes, the laptop and desktop are using the Raspberry Pi for DNS. This is how I know that they are: nmcli device show enp0s25 | grep DNS and the response includes IP4.DNS[1]: 192.168.1.100. – kapus – 2018-07-31T15:29:57.890

Is there any other DNS servers listed? If so, that'd explain why it only works 'some' of the time – djsmiley2k TMW – 2018-07-31T15:40:09.530

Yes, it lists a secondary DNS server (OpenDNS), which is a DNS server my router let's me configure in case the first fails. It should only be used if the first fails, so I think the problem is not related to that - the problem is that DNSMasq is failing to catch those requests. – kapus – 2018-07-31T15:46:22.527

1@djsmiley2k I think you were right about the other DNS. I was using another DNS server (OpenDNS) on my router because I thought the router was going to use it as a failover, but actually I think that the router was doing a round robin between DNSMasq and OpenDNS. Things work now after I removed the other DNSServer from router config. If you put an answer, I will mark it as correct. Thanks! – kapus – 2018-08-01T00:40:01.557

Answers

1

It appears that your clients are doing round robin between two DNS servers, one being the local one and one being a remote one which won't have the local names added.

Ideally your clients would query the first (local server) and on a time out then query the second one, but what likely happens is both get queried in turn, and which ever responds faster is used.

As a fix, I'd set ONLY the raspi's DNS as the dns on the router, and rely on this working properly. If you're concerned maybe the raspi might crash or be offline for another reason - maybe you could setup a second one too - and use that as the secondary - If you do this however, make sure to turn off DHCP (server) on this raspi too!

djsmiley2k TMW

Posted 2018-07-31T15:12:24.237

Reputation: 5 937

Hi Thanks for accepting. I'm going to update my answer with what you added in the comment, about removing the opendns from your router, as it genunely seems to be doing what I thought it might be, which is infact bad ;) – djsmiley2k TMW – 2020-02-27T16:47:37.043