Friday, December 22, 2023

OpenWRT, dnsmasq, dhcp, static mappings, but No DNS Resolution

The Problem

After poking around WAYYYYY too long to connect these dots, I finally have a reasonable explanation for why dnsmasq, running on on OpenWRT, absolutely refused to resolve an IP address from a hostname that was configured, in DHCP, with an IP for a specific client mac address.  The client machine was online, and reachable by that IP.

TL/DR

dnsmasq only resolves names from DHCP active leases, not from DHCP config.  (Read on if you need to know how to check, how to fix, etc.)

The circumstances were:

  • ip/name configured in DHCP for client machines mac address (as mentioned already).
  • client machine hostname configured to match the name also assigned by DHCP
  • client machine (linux) had been rebooted, after configuring DHCP and hostname
  • command dhclient -r issued repeatedly on the client machine
  • interface, domain, etc. set to "lan"
  • ipv6 disabled (just in case it was making things more complicated).
  • ping and nslookup from a different machine received NXDOMAIN response from dnsmasq/openwrt

Extra Circumstances (that didn't seem relevant, but were):

  • client machine had unexpired, cached DHCP lease info in /var/lib/dhcp/dhclient.eth0.leases
  • openwrt dhcp did NOT have an active lease registered in /tmp/dhcp.leases
  • dnsmasq had been restarted, the entire openwrt router had been restarted, and several updates had been "Saved and Applied" via LuCI.  This probably meant that any DHCP in-memory name:ip mappings were gone.

What fixed it?

On the client/host machine that can't be resolved/found by name...
  1. Delete /var/lib/dhcp/dhclient*.leases
  2. Reboot (because dhclient -r eth0 didn't help).

Verification

  1. Check that ping and nslookup now work as expected from other clients for the previously (let's hope) unresolvable hostname.
  2. Check that openwrt /tmp/dhcp.leases DOES now include a line for the recently, forcibly-renewed DHCP lease.

Explanation:

openwrt runs dnsmasq with a configuration that references the /tmp/dhcp.leases file.  
  • The setting is found on the Network - DHCP and DNS page in LuCI, on the Resolv and Hosts Files "tab" in the Leasefile field.
  • The setting is found in the /etc/config/dhcp file in the config dnsmasq section as option leasefile '/tmp/dhcp.leases'
    • See: https://openwrt.org/docs/guide-user/base-system/dhcp
    • This says: "leasefile stores leases in a file so they can be picked up again if dnsmasq is restarted."
    


No comments: