DD-WRT: DNSMasq expand-hosts not working

dd-wrtdhcpdnsdnsmasq

I have a Linksys router running DD-WRT (Firmware: DD-WRT v24-sp2 (09/08/09) mini). I have it successfully resolving the DNS names for my DHCP-assigned systems, but only when I fully-qualify those domains. This is despite using the "expand-hosts" DNSMasq additional option, which is supposed to activate this precise function.

Here's my dnsmasq.conf:

interface=br0
resolv-file=/tmp/resolv.dnsmasq
domain=example.com
dhcp-leasefile=/tmp/dnsmasq.leases
dhcp-lease-max=51
dhcp-option=lan,3,10.77.0.5
dhcp-authoritative
dhcp-range=lan,10.77.0.100,10.77.0.149,255.255.0.0,1440m
dhcp-host=00:1A:A0:1D:82:5A,astatichostname,10.77.1.40,infinite
expand-hosts

(FYI: example.com and astatichostname are placeholders for the real-deal names I use. My network uses 10.77.0.0/16; my router is on 10.77.0.5.)

Results:

> nslookup astatichostname 10.77.0.5
Server:     10.77.0.5
Address:    10.77.0.5#53

** server can't find astatichostname: NXDOMAIN

> nslookup astatichostname.example.com 10.77.0.5
Server:     10.77.0.5
Address:    10.77.0.5#53

Name:   astatichostname.example.com
Address: 10.77.1.40

Is there something else that could be tripping up expand-host in DNSMasq?

Best Answer

This question is old, but it's one of the top google results for the issue, and I finally figured it out.

The problem is that's not what expand-hosts does. The documentation on it is very fuzzy, but what expand-hosts does is adds the domain to host entries in /etc/hosts, not to dns queries. So for example

/etc/hosts:

10.77.0.5 astatichostname

dnsmasq.conf:

expand-hosts
domain=example.com

Then dns queries for astatichostname.example.com will resolve to 10.77.0.5 (in addition to DNS queries for just astatichostname).



Solution:

So, the solution is to get dd-wrt to create the entries in /etc/hosts without the domain on them, and then tell dnsmasq to consider those host entries as part of the example.com domain when a fully qualified A record DNS query comes in.
To do this you have to:

  1. Put the example.com domain in the Domain Name field on the Setup -> Basic Setup page under Optional Settings.
  2. Blank the LAN Domain setting on the Services page under DHCP Server.
  3. Add expand-hosts to Additional DNSMasq Options on the Services page under DNSMasq

Step #1 controls the domain= setting that gets put in the dnsmasq.conf file. Step #2 removes the domain from the entries that get put in /etc/hosts. Step #3 tacks the domain onto the entries in /etc/hosts when a fully qualified DNS query comes in.


I'm so glad dd-wrt made this nice and simple...

Related Question