我的学校为所有同学分配了一个 /64 前缀的 IPv6 块,我想修复我的 Windows 10 22H2 PC 的 64 位后缀,因此我执行了以下 PowerShell 脚本将我的自定义 IPv6 地址设置为$ip
唯一实际用于传出包的 IP,并且成功了。
添加自定义 IPv6 地址:
New-NetIPAddress -InterfaceAlias Wi-Fi -IPAddress $ip -PolicyStore ActiveStore -PrefixLength 64
Set-NetIPAddress -IPAddress $ip -SkipAsSource $False
将所有其他公共 IPv6 地址设置为,SkipAsSource
以$True
防止它们被用于传出包:
Get-NetIPAddress -InterfaceAlias Wi-Fi | ForEach-Object {
if( ($_.AddressFamily.ToString() -eq "IPv6") -And ($_.IPAddress -ne $ip) -And ($_.PrefixOrigin.ToString() -ne "WellKnown") ){
Set-NetIPAddress -IPAddress $_.IPAddress -SkipAsSource $True
}
}
但几分钟后,IPv6 地址PrefixOrigin
变为,"Dhcp"
这使我的 PC 使用 DHCP IPv6 地址发送数据包。为了找出原因,我执行了以下 PowerShell 脚本来查找 DHCP IPv6 地址变为 的准确时间:SkipAsSource
$False
SkipAsSource
$False
$isChanged = $false
while( !$isChanged ){
Start-Sleep 10
Get-Date
Get-NetIPAddress -InterfaceAlias "Wi-Fi" -AddressFamily IPv6 | ForEach-Object{
if($_.PrefixOrigin -eq "Dhcp"){
if($_.SkipAsSource -eq $False){
$global:isChanged = $True
Write-Host -ForegroundColor Red "Found it"
break
}else{
Write-Host "Nothing wrong"
}
}
}
}
我发现的时间跨度在到之间2023-07-12 02:20:00 UTC+8
,2023-07-12 02:20:10 UTC+8
然后发现以下系统日志,其时间戳为,2023-07-12 02:20:01 UTC+8
这可能与此有关。
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="Netwtw04" />
<EventID Qualifiers="16384">7003</EventID>
<Version>0</Version>
<Level>4</Level>
<Task>0</Task>
<Opcode>0</Opcode>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2023-07-11T18:20:01.5397220Z" />
<EventRecordID>122318</EventRecordID>
<Correlation />
<Execution ProcessID="4" ThreadID="9152" />
<Channel>System</Channel>
<Computer>ComputerName</Computer>
<Security />
</System>
<EventData>
<Data>\Device\NDMP5</Data>
<Data>Intel(R) Dual Band Wireless-AC 3165</Data>
<Binary>0000080002003800000000005B1B00400000000000000000000000000000000000000000000000000000000000000000</Binary>
</EventData>
</Event>
并且以下两个日志的Applications and Services Logs\Microsoft\Windows\Dhcp-Client\Microsoft-Windows-DHCP Client Events/Admin
时间戳相同。没有日志的时间戳相同或相邻Applications and Services Logs\Microsoft\Windows\Dhcp-Client\Microsoft-Windows-DHCPv6 Client Events/Admin
:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="Microsoft-Windows-Dhcp-Client" Guid="{15a7a4f8-0072-4eab-abad-f98a4d666aed}" />
<EventID>50067</EventID>
<Version>0</Version>
<Level>4</Level>
<Task>3</Task>
<Opcode>57</Opcode>
<Keywords>0x4000000000000000</Keywords>
<TimeCreated SystemTime="2023-07-11T18:20:01.5559344Z" />
<EventRecordID>6641</EventRecordID>
<Correlation />
<Execution ProcessID="2044" ThreadID="6392" />
<Channel>Microsoft-Windows-Dhcp-Client/Admin</Channel>
<Computer>sanfrancisco</Computer>
<Security UserID="S-1-5-19" />
</System>
<EventData>
<Data Name="NetworkHintString">SSID</Data>
<Data Name="NetworkHint">SSID hex</Data>
<Data Name="HWLength">6</Data>
<Data Name="HWAddress">MAC address</Data>
</EventData>
</Event>
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="Microsoft-Windows-Dhcp-Client" Guid="{15a7a4f8-0072-4eab-abad-f98a4d666aed}" />
<EventID>50065</EventID>
<Version>0</Version>
<Level>4</Level>
<Task>3</Task>
<Opcode>55</Opcode>
<Keywords>0x4000000000000000</Keywords>
<TimeCreated SystemTime="2023-07-11T18:20:01.5559369Z" />
<EventRecordID>6642</EventRecordID>
<Correlation />
<Execution ProcessID="2044" ThreadID="6392" />
<Channel>Microsoft-Windows-Dhcp-Client/Admin</Channel>
<Computer>sanfrancisco</Computer>
<Security UserID="S-1-5-19" />
</System>
<EventData>
<Data Name="NetworkHintString">SSID</Data>
<Data Name="NetworkHint">SSID hex</Data>
<Data Name="HWLength">6</Data>
<Data Name="HWAddress">MAC address</Data>
</EventData>
</Event>
那么如何防止 DHCP IPv6 地址被恢复?或者如何禁用 DHCPv6?
答案1
我发现可以通过 禁用网卡的 DHCPv6 Set-NetIPInterface -Dhcp Disable -InterfaceAlias Wi-Fi -AddressFamily IPv6
。执行该操作后,我的网卡只有 2 个公网 IPv6 地址,分别是我自己手动设置的和 SLAAC 设置的。但即使我将 SLAAC 的 IPv6 设置SkipAsSource
为$True
,几个小时后它仍然恢复原样$False
。现在我通过 禁用了 SLAAC netsh interface ipv6 set interface Wi-Fi routerdiscovery=disabled
,我的问题就完全解决了,因为 Windows 只有一个公网 IPv6 地址。