![在 Windows Server 2008/2012 中禁用 NIC 高级属性](https://linux22.com/image/645335/%E5%9C%A8%20Windows%20Server%202008%2F2012%20%E4%B8%AD%E7%A6%81%E7%94%A8%20NIC%20%E9%AB%98%E7%BA%A7%E5%B1%9E%E6%80%A7.png)
我有一些 Rackspace VM,需要禁用这些高级 NIC 属性:
- 正确的 TCP/UDP 校验和值
- IPv4 校验和卸载
- 大型接收卸载
- 大型发送卸载版本 2
- TCP 校验和卸载
- UDP 校验和卸载
现在我需要使用 Powershell/Batch 来执行此操作,到目前为止我已经拥有它了。
Disable-NetAdapterChecksumOffload -Name private -UdpIPv4 -TcpIPv4
Disable-NetAdapterLso -Name private
cmd.exe /C "netsh int tcp set global chimney=disabled"
cmd.exe /C "netsh int tcp set global rss=disabled"
cmd.exe /C "netsh int tcp set global netdma=disabled"
cmd.exe /C "netsh int ip set global taskoffload=disabled"
new-ItemProperty -force -Path hklm:\\\\HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Services\\TCPIP\\Parameters -Name DisableTaskOffload -Value 1
new-ItemProperty -force -Path hklm:\\\\HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Services\\TCPIP\\Parameters -Name TCPChecksumOffloadIPv4 -Value 0
new-ItemProperty -force -Path hklm:\\\\HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Services\\TCPIP\\Parameters -Name UDPChecksumOffloadIPv4 -Value 0
但我无法让它工作。
答案1
我设法用这个 powershell 脚本来做到这一点。
$root = 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}'
$items = Get-ChildItem -Path Registry::$Root -Name
Foreach ($item in $items) {
if ($item -ne "Properties") {
$path = $root + "\" + $item
$DriverDesc = Get-ItemProperty -Path Registry::$path | Select-Object -expandproperty DriverDesc
if ($DriverDesc -eq "Citrix PV Ethernet Adapter") {
Set-ItemProperty -path Registry::$path -Name LROIPv4 -Value 0
}
}
}
new-ItemProperty -force -Path hklm:\\\\HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Services\\TCPIP\\Parameters -Name IPChecksumOffloadIPv4 -Value 0
new-ItemProperty -force -Path hklm:\\\\HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Services\\TCPIP\\Parameters -Name LSOv2IPv4 -Value 0
new-ItemProperty -force -Path hklm:\\\\HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Services\\TCPIP\\Parameters -Name NeedChecksumValue -Value 0
new-ItemProperty -force -Path hklm:\\\\HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Services\\TCPIP\\Parameters -Name TCPChecksumOffloadIPv4 -Value 0
new-ItemProperty -force -Path hklm:\\\\HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Services\\TCPIP\\Parameters -Name UDPChecksumOffloadIPv4 -Value 0
new-ItemProperty -force -Path hklm:\\\\HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Services\\TCPIP\\Parameters -Name LROIPv4 -Value 0
重要的是查看要改变的属性。
使用:
PS > Get-NetAdapter
PS > Get-NetAdapterAdvancedProperty name_of_the_nic
PS > Get-NetAdapterAdvancedProperty name_of_the_nic | ft RegistryKeyword
现在根据需要更新 RegistryKeyword
答案2
假设“以太网”是你的网卡的名称:
# Display valid values
Get-NetAdapterAdvancedProperty Ethernet | ft DisplayName , ValidDisplayValues
# Display existing settings:
Get-NetAdapterAdvancedProperty Ethernet | ft DisplayName, DisplayValue, RegistryKeyword , RegistryValue
# Set all the settings required to switch of TCP IPv4 offloading to fix SQL Server connection dropouts in high connection, high transaction environment:
# Note that RDP connection to instance will drop out momentarily
Set-NetAdapterAdvancedProperty Ethernet -DisplayName "IPv4 Checksum Offload" -DisplayValue "Disabled" -NoRestart
Set-NetAdapterAdvancedProperty Ethernet -DisplayName "Large Send Offload V2 (IPv4)" -DisplayValue "Disabled" -NoRestart
Set-NetAdapterAdvancedProperty Ethernet -DisplayName "TCP Checksum Offload (IPv4)" -DisplayValue "Disabled" -NoRestart
Set-NetAdapterAdvancedProperty Ethernet -DisplayName "Large Receive Offload (IPv4)" -DisplayValue "Disabled"
# Check its worked
Get-NetAdapterAdvancedProperty Ethernet | ft DisplayName, DisplayValue, RegistryKeyword , RegistryValue