TechnitiumSoftware/DnsServer · warning · DhcpServerException

No lease was found for hardware address: {hardwareAddress}

Error message

No lease was found for hardware address: {hardwareAddress}

What it means

Thrown by Scope.RemoveLease(string hardwareAddress) when no existing lease matches the supplied hardware (MAC) address. RemoveLease scans all leases by HardwareAddress and, finding none, raises a DhcpServerException so the caller knows the client was never leased on this scope.

Source

Thrown at DnsServerCore/Dhcp/Scope.cs:1515

                _dhcpServer.RemoveDnsEntries(this, removedLease, true);

                return true;
            }

            return false;
        }

        public Lease RemoveLease(string hardwareAddress)
        {
            byte[] hardwareAddressBytes = Lease.ParseHardwareAddress(hardwareAddress);

            foreach (KeyValuePair<ClientIdentifierOption, Lease> entry in _leases)
            {
                if (entry.Value.HardwareAddress.SequenceEqual(hardwareAddressBytes))
                    return RemoveLease(entry.Key);
            }

            throw new DhcpServerException("No lease was found for hardware address: " + hardwareAddress);
        }

        public Lease RemoveLease(ClientIdentifierOption clientIdentifier)
        {
            if (!_leases.TryRemove(clientIdentifier, out Lease removedLease))
                throw new DhcpServerException("No lease was found for client identifier: " + clientIdentifier.ToString());

            if (removedLease.Type == LeaseType.Reserved)
            {
                //remove reserved lease
                ClientIdentifierOption reservedLeaseClientIdentifier = new ClientIdentifierOption((byte)DhcpMessageHardwareAddressType.Ethernet, removedLease.HardwareAddress);
                if (_reservedLeases.TryGetValue(reservedLeaseClientIdentifier, out Lease existingReservedLease))
                {
                    //remove reserved lease only if the IP addresses match
                    if (existingReservedLease.Address.Equals(removedLease.Address))
                    {
                        if (_reservedLeases.TryRemove(reservedLeaseClientIdentifier, out Lease removedExistingLease))
                        {

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Verify the MAC string is non-empty and in a parseable format (Lease.ParseHardwareAddress accepts common delimiters).
  2. Confirm a lease for this hardware address actually exists on this scope before calling.
  3. If the release may already be done, treat the exception as benign and ignore/log it.
  4. Make sure you are operating on the scope that issued the lease, not a sibling scope.

Example fix

// before
scope.RemoveLease(mac); // throws if absent

// after
bool exists = scope.Leases.Any(l => l.HardwareAddress.SequenceEqual(Lease.ParseHardwareAddress(mac)));
if (exists) scope.RemoveLease(mac);
else _log.Warn($"no lease for {mac}; nothing to remove");
Defensive patterns

Strategy: validation

Validate before calling

byte[] mac = Lease.ParseHardwareAddress(macString);
bool hasLease = scope.Leases.Any(l => l.HardwareAddress.SequenceEqual(mac));
if (!hasLease) return; // nothing to remove

Type guard

static bool ScopeHasLeaseForHardware(Scope scope, string mac){
    var bytes = Lease.ParseHardwareAddress(mac);
    return scope.Leases.Any(l => l.HardwareAddress.SequenceEqual(bytes));
}

Try / catch

try { scope.RemoveLease(macString); }
catch (DhcpServerException ex) when (ex.Message.Contains("No lease was found"))
{ /* already released; treat as success */ }

Prevention

When it happens

Trigger: Calling scope.RemoveLease(macString) for a MAC that has no lease: client never obtained an address, lease already expired/removed, MAC formatted differently than stored, or wrong scope object.

Common situations: Admin UI 'release lease' action on a stale list, automation retrying a release that already succeeded, MAC passed with dashes when stored with colons, or calling against a scope that doesn't own the client.

Related errors


AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13). Data as JSON: /api/errors/e03e970e4bf0d8c5. Report an issue: GitHub.