Can I make local Dnsmasq also resolve sub-hostnames (subdomains)?


So, say I have a host dhcphostname.lan in my network, it changes it's IP address very often, the only part that won't change is it's hostname.

I can nslookup it's hostname to get it's IP. But it doesn't work if I'm trying to lookup it's subdomain, say test1.dhcphostname.lan or test2.dhcphostname.lan.

My question is, is there an option I can flip so OpenWrt knows to resolve *.dhcphostname.lan to the same IP address as dhcphostname.lan?


1 Like

Sorry, that wouldn't work as it requires to setup static resolves/records.

In my case, I need it to be done automatically, because it's not just one host needs to be configured. The host changes IP address, and the host comes and goes.

why should the host change IP?



  • Rely on mDNS or LLMNR.
  • Issue persistent IPv4 or IPv6 leases based on MAC or DUID.
  • Configure DNS with hotplug.

Thank you!

I've eventually settled down on writing a DNS proxy that transforms the query for a sub-hostname to the hostname itself before sending it back to Dnsmasq.

It goes like: Client (Sends query for -> Dnsmasq (Detects .dev.lan and forward to my proxy) -> My DNS Proxy (Sees, strips xxx and dev.lan, so the domain becomes host. Then it sends host back to Dnsmasq) -> Dnsmasq (Sees host, found the result) -> My DNS Proxy (Receives the result, repack it as the result for, and then reply to the previous Dnsmasq query) -> Dnsmasq (Receives the final result for, reply to the client) -> Client (Receives the final result).

Yeah, I really wish Dnsmasq can add an option for this function. But now I'll just have to live without it.

Thanks again!

mkdir -p /etc/hotplug.d/dhcp
cat << "EOF" > /etc/hotplug.d/dhcp/00-custom
if [ "${ACTION}" = "update" -a -z "${DNSMASQ_SUPPLIED_HOSTNAME}" ]
then exit 0
elif [ "${ACTION}" = "update" -o "${ACTION}" = "add" ]
then CMD="add"
elif [ "${ACTION}" = "remove" ]
then CMD="del"
uci del_list dhcp.@dnsmasq[0].address="/${HOSTNAME}/${IPADDR}"
uci ${CMD}_list dhcp.@dnsmasq[0].address="/${HOSTNAME}/${IPADDR}"
/etc/init.d/dnsmasq reload

Updated the code to remove duplicates and looping.


Wait hold on ...

I was doing almost the same thing with no sucess. I think it's because instead of calling uci to modify /etc/config/dhcp like in your script, I was directly writing a new config file with content address="/${HOSTNAME}/${IPADDR}" to /tmp/dnsmasq.d.

Apparently your script is much clever!

I'll look a little bit deeper. Thanks a lot!

1 Like