AdguardTeam/AdGuardHome · error

subnet %s does not contain the ip %q

Error message

subnet %s does not contain the ip %q

What it means

addLease rejects a static lease whose IP is not inside the configured DHCP subnet. Static leases must belong to the served subnet, otherwise the server cannot legitimately hand them out. The subnet in the message is the server's configured range.

Source

Thrown at internal/dhcpd/v4_unix.go:326

		if !isStatic && l.Hostname == lease.Hostname {
			l.Hostname = ""
		}
	}

	return nil
}

// addLease adds a dynamic or static lease.
func (s *v4Server) addLease(l *dhcpsvc.Lease) (err error) {
	r := s.conf.ipRange
	leaseIP := net.IP(l.IP.AsSlice())
	offset, inOffset := r.offset(leaseIP)

	if l.IsStatic {
		// TODO(a.garipov, d.seregin): Subnet can be nil when dhcp server is
		// disabled.
		if sn := s.conf.subnet; !sn.Contains(l.IP) {
			return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP)
		}
	} else if !inOffset {
		return fmt.Errorf("lease %s (%s) out of range, not adding", l.IP, l.HWAddr)
	}

	// TODO(e.burkov):  l must have a valid hostname here, investigate.
	if l.Hostname != "" {
		if _, ok := s.hostsIndex[l.Hostname]; ok {
			return fmt.Errorf("hostname: %w", errors.ErrDuplicated)
		}

		s.hostsIndex[l.Hostname] = l
	}
	s.ipIndex[l.IP] = l

	s.leases = append(s.leases, l)
	s.leasedOffsets.set(offset, true)

View on GitHub (pinned to b41aefbe51)

Solutions

  1. Correct the static lease IP so it lies within the configured DHCP subnet
  2. Update the DHCP subnet configuration to cover the static lease range
  3. Remove stale static leases after changing network topology

Example fix

// before
subnet: 192.168.1.0/24
static_lease: { ip: 10.0.0.50, mac: "aa:bb:cc:dd:ee:ff" }

// after
static_lease: { ip: 192.168.1.50, mac: "aa:bb:cc:dd:ee:ff" }
Defensive patterns

Strategy: validation

Validate before calling

// before AddStaticLease / ResetLeases
if !subnet.Contains(lease.IP) {
    return fmt.Errorf("lease %s outside subnet %s", lease.IP, subnet)
}

Try / catch

if err := srv.AddStaticLease(l); err != nil {
    if strings.Contains(err.Error(), "does not contain the ip") {
        // fix lease IP to be within subnet
    }
}

Prevention

When it happens

Trigger: Calling ResetLeases/UpdateStaticLease/AddStaticLease (via addLease) with l.IsStatic=true and an l.IP outside s.conf.subnet — e.g. a static lease configured for a different subnet than the DHCP interface's subnet.

Common situations: Changed the DHCP interface or its subnet but kept old static lease entries; copied static lease configs between networks; typo in the static lease IP (wrong octet or wrong subnet prefix).

Related errors


AI-assisted analysis of AdguardTeam/AdGuardHome@b41aefbe51 (2026-08-27). Data as JSON: /api/errors/d7bc084003b27990. Report an issue: GitHub.