Troubleshooting dnsmasq

5,192

Solution 1

1. dnsmasq and Network Manager

As yourself from a few days in the future: your understanding is correct.

Note, however, that Network Manager launches an instance of dnsmasq as a child process (not a separate daemon) and keeps its own set of dnsmasq configuration settings.

2. Can I see how dnsmasq is handling a particular DNS lookup?

Sorry, I still don't know.

3. Can I instruct dnsmasq to use a particular DNS server for the local domain?

Yes, the --server option in dnsmasq (manpage here) allows you to specify upstream DNS servers for specific domains.

You can pass this option to Network Manager's invocation of dnsmasq. I did this by creating a file in the directory /etc/NetworkManager/dnsmasq.d/ with the contents:

server=//192.168.0.1

Normally, this line would be server=/domain/<ipaddr>; in this case the empty domain specification means "unqualified names only", such as localserver in your example (as opposed to localserver.domain).

How I fixed your immediate problem

The above change still didn't fix things. I verified that this was loaded (service NetworkManager status shows a log entry dnsmasq[<pid>]: using nameserver 192.168.0.1#53 for unqualified names), but it still returns NXDOMAIN on lookups. So I settled on the following hack:

The local machines I'm connecting to all have static IPs, so I manually specified these in a file in /etc/NetworkManager/dnsmasq.d with the contents:

address=/localserver/192.168.0.13
address=/localserve2/192.168.0.14
[...and so on...]

Solution 2

Sorry I'm a bit late here, but you were almost there with question 2! In the manual for dnsmasq which you linked is an option called --log-queries. So simply:

$ echo "log-queries" > /etc/NetworkManager/dnsmasq.d/log-queries
$ systemctl restart NetworkManager

Then you should see logs similar to:

$ journalctl -f
Jan 21 15:39:15 computor dnsmasq[12345]: query[A] github.com from 127.0.0.1
Jan 21 15:39:15 computor dnsmasq[12345]: forwarded github.com to 8.8.8.8
Jan 21 15:39:15 computor dnsmasq[12345]: forwarded github.com to 8.8.4.4
Jan 21 15:39:15 computor dnsmasq[12345]: reply github.com is 140.82.118.4

(I am running Debian rather than Ubuntu but I expect this will work the same.)


When we come back to your original problem though, I think the logical way to make this work is adding these host definitions to your /etc/hosts and forcing NetworkManager's dnsmasq to use them (see this question or this answer). That is where I would expect to find local server definitions rather than digging around in /etc/NetworkManager/dnsmasq.d/*.

Share:
5,192

Related videos on Youtube

KQS
Author by

KQS

Updated on September 18, 2022

Comments

  • KQS
    KQS over 1 year

    I'm having DNS issues on a new install of Ubuntu 16.04:

    kqs@mycomputer:~$ nslookup localserver
    Server:     127.0.0.1
    Address:    127.0.0.1#53
    
    ** server can't find localserver: NXDOMAIN
    

    But if I specify the DNS server (or sometimes if I just wait awhile), it works:

    kqs@mycomputer:~$ nslookup localserver 192.168.0.1
    Server:     192.168.0.1
    Address:    192.168.0.1#53
    
    Name:   localserver.localdomain
    Address: 192.168.0.24
    

    And this is the same DNS server that shows up first in Network Manager:

    kqs@mycomputer:~$ nmcli device show
    IP4.ADDRESS[1]:     192.168.0.152/24
    IP4.GATEWAY:        192.168.0.1
    IP4.ROUTE[1]:       dst = 169.254.0.0/16, nh = 0.0.0.0, mt = 1000
    IP4.DNS[1]:         192.168.0.1
    IP4.DNS[2]:         131.215.254.100
    IP4.DNS[3]:         131.215.139.100
    

    It seems to be the same problem as "dnsmasq sometimes resolves things, sometimes it doesn't" and "Intranet address resolution and dnsmasq", but in that solution they disable dnsmasq by commenting out the dns=dnsmasq line in /etc/NetworkManager/NetworkManager.conf.

    However, I'd like to troubleshoot dnsmasq rather than bypassing it completely.

    So my questions are:

    1. My understanding is that dnsmasq is a lightweight DNS server running on my computer. Presumably, the Network Manager DNS settings are used to configure dnsmasq, but ultimately it is dnsmasq that is solely responsible for handling DNS lookups (with the help of upstream DNS servers as it deems necessary). Is this correct?
    2. Can I see how dnsmasq is handling a particular DNS lookup? i.e. is it answering it from its cache? Which upstream DNS server is it forwarding it to?
    3. Can I instruct dnsmasq to use a particular DNS server for the local domain?