AdGuardHome icon indicating copy to clipboard operation
AdGuardHome copied to clipboard

DHCP: expired dynamic leases are still served by DNS, shadow DNS rewrites and are hidden from the UI

Open dezzezer opened this issue 1 month ago • 1 comments

Prerequisites

  • [X] I have checked the Wiki and Discussions and found no answer
  • [X] I have searched other issues and found no duplicates
  • [X] I want to report a bug and not ask a question or ask for help

Platform (OS and CPU architecture)

Linux, ARM64 (Raspberry Pi 4), Docker

Installation

Docker (adguard/adguardhome)

Setup

On one machine; AdGuard Home acts as both DNS and DHCP server for the LAN

AdGuard Home version

v0.107.78

Action

AdGuard Home is the only DNS and DHCP server on the LAN, local_domain_name: lan, DHCP range 192.168.0.101-192.168.0.200.

  1. A client receives a dynamic lease, e.g. hostname pi4, MAC 2c:cf:67:59:00:13, IP 192.168.0.108 (pi4 is the same machine that also runs AdGuard Home).

  2. That lease expires (in my case 2026-09-13), but it stays in data/leases.json.

  3. The machine later gets a static address 192.168.0.100 (netplan on eth0), so .108 is not used anymore.

  4. DNS rewrites for the same name point to the correct address and are enabled:

    - domain: pi4.lan
      answer: 192.168.0.100
      enabled: true
    - domain: '*.pi4.lan'
      answer: 192.168.0.100
      enabled: true
    
  5. A LAN client queries pi4.lan:

    nslookup pi4.lan 192.168.0.100
    Name:    pi4.lan
    Address: 192.168.0.108   (dead address, no device answers on it)
    

Expected result

  • Expired dynamic leases should not be used to answer DNS queries.
  • Even if the DHCP hostname takes precedence over DNS rewrites (which is documented behaviour in the processing pipeline), an expired lease should not win over an explicit, enabled rewrite.

Actual result

  • pi4.lan still resolves to the expired lease address 192.168.0.108 (TTL 10), so the DNS rewrite is silently shadowed and clients get an unreachable IP.
  • *.pi4.lan works, because no lease hostname matches those names - only the exact, expired hostname is broken. This makes the failure look random.
  • The same happens for every expired lease in leases.json, e.g. rpi.lan -> 192.168.0.120 (expired 2026-09-16), s8.lan -> 192.168.0.124 (expired 2026-10-05), s10p.lan -> 192.168.0.114 (expired 2026-10-18).
  • Reverse records are stale as well: PTR for 192.168.0.108 still returns pi4.lan.
  • The expired leases are not shown in the UI, so there is no way to remove them: Settings -> DHCP settings lists only active leases, while the expired ones keep answering DNS queries. There is also no HTTP API to delete a single dynamic lease (only static leases can be removed), so the only workaround is to stop AdGuard Home and edit data/leases.json by hand.

Additional information

Root cause, verified in the source of v0.107.78:

  • internal/dhcpd/v4_unix.go, GetLeases() filters expired leases with l.Expiry.After(now). This is why expired leases are invisible in the UI and API - the data that is actually used by DNS cannot be managed from the UI.
  • internal/dhcpd/v4_unix.go, IPByHost() reads hostsIndex with no expiry check at all, so DNS keeps answering with expired data.
  • internal/dnsforward/process.go, processDHCPHosts() runs before processFilteringBeforeRequest(), so a DHCP-hostname answer always wins over a DNS rewrite for the same name. That order itself is fine, but combined with the missing expiry check it makes stale DHCP data override an explicit rewrite.
  • internal/dhcpd/db.go, dbStore() persists getLeasesRef() (all leases, expired included), so expired entries never age out of leases.json and survive restarts.
  • The same IPByHost() behaviour exists in the newer internal/dhcpsvc/server.go on master, so this is not fixed by the v0.108 changes.

Related issues: #8572 (leases with zero expiry never cleaned up - that fix in v0.108.0-b.91 does not cover leases that expired normally), #3932 (PTR TTL does not respect lease time), #3934 (visibility of DHCP leases), #7673 (stale lease data affecting DNS, closed by the reporter without a fix).

Possible fixes:

  1. Ignore leases whose Expiry is in the past in IPByHost()/HostByIP() and in the reverse-PTR path.
  2. Prune expired dynamic leases when loading and storing leases.json, so existing installations self-heal.
  3. Show expired leases in the UI (or add a "reset dynamic leases" action), so users can clean them up without stopping the server and editing files.

Workaround used: adding a static lease with the stale lease's MAC replaces the entry and restores correct resolution; adding a static lease with a different MAC (e.g. the machine's eth0 MAC) fails with hostname already exists, because rmDynamicLease() only clears the hostname but leaves the stale entry in hostsIndex.

dezzezer avatar Oct 26 '26 14:10 dezzezer

Thank you for letting us know. The information has been forwarded to the dev team.

sofvaskina avatar Oct 29 '26 13:10 sofvaskina