什么原因导致 DHCP 范围认为它已满但实际上并未满?

什么原因导致 DHCP 范围认为它已满但实际上并未满?

我们的 DHCP 服务器未在某个作用域上分配地址。统计信息似乎显示它已满:

在此处输入图片描述

但是,我看到只有 88 个地址在使用中。我在系统或应用程序日志中看不到任何错误。DHCP 日志为空。

什么原因造成这种情况?

更新:范围内似乎有大量奇怪的条目。有一大堆未识别的客户端(即有 IP 地址但没有主机名),这些客户端似乎属于具有重复 MAC 地址的群组,并添加了一些奇怪的额外字符。

答案1

以管理员身份尝试以下命令。

netsh dhcp 服务器范围(例如 192.168.1.0)显示客户端 v5。

您将获得活跃客户的总数。

此数字将用于计算“InUse”。如果发现 DHCP 租约已过期,请不要感到惊讶。

答案2

这是一个可能有助于释放过期租约的 PowerShell 脚本。有时它可以释放一定范围内的 IP 地址:

# Import the DHCP module
Import-Module DhcpServer

# Define the DHCP server and scope you want to work with
$DHCPServer = "YourDHCPServerName"
$ScopeID = "YourScopeID"  # e.g., 192.168.1.0

# Get the DHCP server
$Server = Get-DhcpServerInDC -ComputerName $DHCPServer

# Get a list of expired leases in the specified scope
$ExpiredLeases = Get-DhcpServerv4Lease -ComputerName $DHCPServer -ScopeId $ScopeID | Where-Object { $_.LeaseExpiry -lt (Get-Date) }

# Release the expired leases to free up IP addresses
foreach ($Lease in $ExpiredLeases) {
    $IPAddress = $Lease.IPAddress
    Write-Host "Releasing lease for $IPAddress"
    Remove-DhcpServerv4Lease -ComputerName $DHCPServer -IPAddress $IPAddress -ScopeId $ScopeID
}

# Close the DHCP server
$Server.Close()

Write-Host "Expired leases released."

下面是一个 PowerShell 脚本,用于识别您是否有恶意客户端(我怀疑您有)

# Import the DHCP module
Import-Module DhcpServer

# Define the DHCP server and scope you want to work with
$DHCPServer = "YourDHCPServerName"
$ScopeID = "YourScopeID"  # e.g., 192.168.1.0

# Get a list of all DHCP leases in the specified scope
$AllLeases = Get-DhcpServerv4Lease -ComputerName $DHCPServer -ScopeId $ScopeID

# Create a dictionary to store MAC addresses and associated IP addresses
$MACAddressIPDictionary = @{}

# Iterate through the leases and identify MAC address duplicates
foreach ($Lease in $AllLeases) {
    $MACAddress = $Lease.ClientID
    $IPAddress = $Lease.IPAddress

    if ($MACAddressIPDictionary.ContainsKey($MACAddress)) {
        $MACAddressIPDictionary[$MACAddress] += ", $IPAddress"
    } else {
        $MACAddressIPDictionary[$MACAddress] = $IPAddress
    }
}

# Identify MAC addresses with multiple associated IP addresses
$RogueMACAddresses = $MACAddressIPDictionary | Where-Object { $_.Value -match "," }

# Print out MAC addresses and associated IP addresses for potential rogue clients
foreach ($MACAddress in $RogueMACAddresses.Keys) {
    Write-Host "Potential Rogue Client MAC Address: $MACAddress"
    Write-Host "Associated IP Addresses: $($RogueMACAddresses[$MACAddress])"
}

答案3

我最近遇到了类似的问题,不过是在 Cisco 设备上。最终,问题是由于 IP 冲突引起的,清除这些冲突解决了问题。

我不完全确定这是否是你的问题,特别是,但值得研究(至少确保它已配置)。

在 Windows DHCP 服务器上启用 IP 地址冲突检测: https://mushaaf.net/enable-ip-address-conflict/

您还可以检查您的 DHCP 租用时间并将其降低到比如说 4 小时。

相关内容