3

I'm having some trouble with my dnsmasq setup. All I want it to do is resolve certain hostnames to certain ip addresses for any machine on my network. More specifically, I'm trying to enable all devices on my network to be able to reach some of the machines on my network using only a specified hostname. I think I must be missing something important because even though I got it working once, after my DNS server rebooted, it stopped forwarding requests for servers outside the LAN.

Here's my setup: (all ip addresses only have the last digit of the IPv4 address)

  • Apple Airport Extreme set up in DHCP and NAT mode (can't just have NAT on this router, so to get NAT, I have the DHCP range set to 253-254 and reserved some bogus mac addresses to those IPs). On my network this has the IP address of 1

  • Raspberry PI running raspbian and dnsmasq. This has the ip address 4 and has the hostname 'pi'

  • A machine named 'tower' at 3

Dnsmasq is set up to be a DNS and DHCP server. All machines that connect to the network get an ip address in the correct range that I specified in dnsmasq, and have the raspberry pi (IP 4) designated automatically as the DNS server. Dnsmasq is also set to forward any requests it can't find to other public dns servers. Here is the entirety of my dns servers with full ip addresses redacted:

/etc/dnsmasq.conf:

# Dnsmasq.conf for raspberry pi    
# Full examples found here:  
# http://www.thekelleys.org.uk/dnsmasq/docs/dnsmasq.conf.example  

# Set up your local domain here    
domain=hyrule.home

# Example: The option local=/localnet/ ensures that any domain name query which ends in .localnet will be answered if possible from /etc/hosts or DHCP, but never sent to an upstream server
# don't forward requests (andrewoberstar.com/blog/2012/12/30/raspberry-pi-as-server-dns-and-dhcp)
local=/hyrule.home/

#resolv-file=/etc/resolv.dnsmasq  
resolv-file=/etc/resolv.conf  
#min-port=4096   

## DNS SERVERS
#openNic california
server=173.230.156.28

#openNic Washington
server=23.226.230.72

#google public DNS
server=8.8.8.8
server=8.8.4.4

# Max cache size dnsmasq can give us
cache-size=10000

# Use the hosts file on this machine
expand-hosts

# ethernet - ip address mappings from /etc/ethers file
read-ethers

# Below are settings for dhcp. 
dhcp-range=XXX.XXX.X.10,XXX.XXX.X.200,12h
dhcp-option=3,XXX.XXX.X.1
dhcp-authoritative
log-queries

/etc/resolv.conf:

domain hyrule.home 
#search hyrule.home
#nameserver 8.8.8.8

/etc/hosts

127.0.0.1   localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0     ip6-localnet
ff00::0     ip6-mcastprefix
ff02::1     ip6-allnodes
ff02::2     ip6-allrouters

127.0.1.1   raspberrypi
XXX.XXX.X.3 tower
XXX.XXX.X.4 pi

And the /etc/ethers file contains the mac addresses of the ethernet interfaces of the respective machines

I can see that dnsmasq is logging requests, and everything looks normal, all the requests look like

Nov  2 17:29:21 raspberrypi dnsmasq[2067]: query[AAAA] time.apple.com.hsd1.ca.comcast.net from 10.0.1.1
Nov  2 17:29:21 raspberrypi dnsmasq[2067]: forwarded time.apple.com.hsd1.ca.comcast.net to 173.230.156.28
Nov  2 17:29:21 raspberrypi dnsmasq[2067]: forwarded time.apple.com.hsd1.ca.comcast.net to 23.226.230.72
Nov  2 17:29:21 raspberrypi dnsmasq[2067]: forwarded time.apple.com.hsd1.ca.comcast.net to 8.8.8.8
Nov  2 17:29:21 raspberrypi dnsmasq[2067]: forwarded time.apple.com.hsd1.ca.comcast.net to 8.8.4.4
Nov  2 17:29:24 raspberrypi dnsmasq[2067]: query[A] north-america.pool.ntp.org from 10.0.1.59
Nov  2 17:29:24 raspberrypi dnsmasq[2067]: forwarded north-america.pool.ntp.org to 8.8.4.4
Nov  2 17:29:24 raspberrypi dnsmasq[2067]: forwarded north-america.pool.ntp.org to 8.8.8.8
Nov  2 17:29:24 raspberrypi dnsmasq[2067]: forwarded north-america.pool.ntp.org to 23.226.230.72
Nov  2 17:29:24 raspberrypi dnsmasq[2067]: forwarded north-america.pool.ntp.org to 173.230.156.28
Nov  2 17:29:24 raspberrypi dnsmasq[2067]: query[TXT] push.apple.com from 10.0.1.3
Nov  2 17:29:24 raspberrypi dnsmasq[2067]: forwarded push.apple.com to 8.8.8.8
Nov  2 17:29:24 raspberrypi dnsmasq[2067]: forwarded push.apple.com to 23.226.230.72
Nov  2 17:29:24 raspberrypi dnsmasq[2067]: forwarded push.apple.com to 173.230.156.28
Nov  2 17:29:24 raspberrypi dnsmasq[2067]: forwarded push.apple.com to 8.8.4.4
Nov  2 17:29:24 raspberrypi dnsmasq[2067]: query[AAAA] time.apple.com.hyrule.home from 10.0.1.14
Nov  2 17:29:24 raspberrypi dnsmasq[2067]: config time.apple.com.hyrule.home is NXDOMAIN-IPv6
Nov  2 17:29:24 raspberrypi dnsmasq[2067]: query[A] time.apple.com.hyrule.home from 10.0.1.14
Nov  2 17:29:24 raspberrypi dnsmasq[2067]: config time.apple.com.hyrule.home is NXDOMAIN-IPv4
Nov  2 17:29:24 raspberrypi dnsmasq[2067]: query[AAAA] time.apple.com from 10.0.1.14
Nov  2 17:29:24 raspberrypi dnsmasq[2067]: forwarded time.apple.com to 8.8.4.4
Nov  2 17:29:24 raspberrypi dnsmasq[2067]: forwarded time.apple.com to 8.8.8.8
Nov  2 17:29:24 raspberrypi dnsmasq[2067]: forwarded time.apple.com to 23.226.230.72
Nov  2 17:29:24 raspberrypi dnsmasq[2067]: forwarded time.apple.com to 173.230.156.28

EDIT: I've decided just reset the pi to the default raspbian because I was doing a lot of experimentation on it, so I wanted to remove any other variables. I went ahead and loaded up minibian and installed dnsmasq. I edited my resolv.conf to look like this (thanks to @Chuck Kollars for pointing out what that file was really doing):

domain hyrule.home
search hyrule.home
nameserver XXX.XXX.X.4

and only set my dnsmasq.conf to query out to these name servers (reading my hosts file by default):

server=/localnet/192.168.0.1 <--- still have the feeling this isn't right
## DNS SERVERS
#openNic california
server=173.230.156.28

#openNic Washington
server=23.226.230.72

In my hosts file, I also had the aliases set up as @Chuck Kollars suggested, with a format of

<ipv4>   <subdomain>  <fqdn>

At this point, I was still having trouble, so I noticed that whenever I pinged something like "tower", dnsmasq would try to resolve "tower.hsdn.comcast.com" or something like that, forwarding it on to the outside name servers because it didn't resolve internally. The comcast part looked familiar, so in my airport utility (5.6.1), under the internet tab, under TCP/IP, that same address was filled in the Domain Name field (ghosted, like it was inherited), so I changed that to also be hyrule.home, and everything worked as expected!

I'm still confused about why that domain name had to be in the router, and why it wasn't being respected from the resolv.conf file...

  • I say inherited in the sense that, since I have a custom, internal dns ip address, I've specified that in the router configuration, and consequently any machine on my network gets that same dns server address – BrDaHa Apr 1 '15 at 5:16
3

Although I can't quite figure out all the details of why your system misbehaves, I do have the following suggestions of things you could profitably look at:

1) Dnsmasq uses /etc/resolv.conf only for queries that originated on that same machine - queries from all other machines go directly into Dnsmasq. So /etc/resolv.conf typically contains a pointer to nameserver 127.0.0.1 in order to get requests originating from apps on that machine into Dnsmasq. In fact, /etc/resolv.conf may even be overwritten when Dnsmasq starts. Be very wary about putting operational instructions in /etc/resolv.conf; in particular I don't think "domain hyrule.home" is doing what you think it's doing for some of your hosts.

2) Another way to handle local shortnames (the way I do it), is to explicitly put both the shortname and the longname of each local machine into /etc/hosts (rather than relying on any software mechanism), something like this:

XXX.XXX.X.1   router router.hynet.home
XXX.XXX.X.3   tower tower.hynet.home
XXX.XXX.X.4   pi pi.hynet.home

3) I'm not too sure what the definition equating "raspberrypi" to "localhost" is for. I'd be afraid of such an equivalence sometimes generating the wrong response to the wrong system at the wrong time, resulting in some queries going in the round file rather than where they were supposed to. My system works with no such definition.

4) For clarity in your various logs, you may want a definition of "localnet" too (analogous to your definition for "ip6-localnet"). You would expect this to go in /etc/networks ...and in fact that may work. But Dnsmasq itself only looks at /etc/hosts, so you may have to instead put the definition into /etc/hosts even though it's for a network, something like this:

XXX.XXX.X.0 localnet hynet.home
| improve this answer | |
  • Thank you, @Chuck Kollars, I think it wasn't so much how I was configuring dnsmasq as it was how I set up the domain on my router. – BrDaHa Aug 26 '15 at 22:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.