我的學校為我所有的同學分配了一個 /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"
了SkipAsSource
,$False
這使得我的電腦使用 DHCP IPv6 位址來傳送套件。為了找出原因,我執行了以下 PowerShell 腳本來尋找 DHCP IPv6 位址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 位址。