我正在尝试在
Windows 7上以编程方式设置物理接口的MTU:
PS> (Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Where { $_.Description -match '^Red Hat.*#2' }) DHCPEnabled : False IPAddress : {10.10.8.3,fe80::447d:38dc:bb39:f311} DefaultIPGateway : DNSDomain : ServiceName : netkvm Description : Red Hat VirtIO Ethernet Adapter #2 Index : 12 PS> (Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Where { $_.Description -match '^Red Hat.*#2' }).SetMTU(9000) Method invocation Failed because [System.Management.ManagementObject#root\cimv2\Win32_NetworkAdapterConfiguration] doesn't contain a method named 'SetMTU'. At line:1 char:113 + (Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Where { $_.Description -match '^Red Hat.*#2' }).SetMTU <<<< (9000) + CategoryInfo : InvalidOperation: (SetMTU:String) [],RuntimeException + FullyQualifiedErrorId : MethodNotFound
即使this method exists仍然出错?真的吗?
请帮忙.
PS> (Get-WmiObject -Class Win32_NetworkAdapterConfiguration | \ Where { $_.Description -match '^Red Hat.*#2' }) | Get-Member
返回,除其他外:
MTU Property System.UInt32 MTU {get;set;}
但试图获取或设置它什么都不做:
(Get-WmiObject -Class Win32_NetworkAdapterConfiguration | \ Where { $_.Description -match '^Red Hat.*#2' }).MTU
除非有Invoke-Magic或我需要做的事情.
根据Ryan的建议,我已经改变了IPv4 MTU(以及IPv6 MTU以获得良好的衡量标准):
C:\>netsh interface ipv4 show subinterface "Local Area Connection 2" MTU MediaSenseState Bytes In Bytes Out Interface ------ --------------- --------- --------- ------------- 9000 1 3686 6624 Local Area Connection 2
看起来很好,但这只影响子接口,而不是硬件接口:
即使重启后也是如此.
好吧,这并没有真正回答你的问题,但我想它无论如何都包含一些不错的信息,所以我会把它留下来.希望有人有一个更好的.
原文链接:https://www.f2er.com/windows/367802.html做:
(Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Where { $_.Description -match '^Red Hat.*#2' }) | Get-Member
并观察输出.您将看到该实例实际上并不包含名为SetMTU的方法,尽管该文档说明了这一点.编辑:其实你的可能.但我的网络界面没有.看起来像是硬件特定的.
所以我知道我要做的就是作弊,但它有效:
PS C:\> $AdapterName = $(Get-NetAdapter | Where { $_.Name -Match 'Ethernet'}).Name PS C:\> netsh interface ipv4 set subinterface "$AdapterName" mtu=1500 store=persistent Ok.
就像你说的那样,这适用于接口,但可能不适用于硬件NIC.所以我没有真正回答你的问题.
您还在评论中提到了Set-NetAdapterAdvancedProperty.但是,我也没有MTU设置.我也无法在Windows GUI中的设备属性上设置MTU.我认为差异是硬件特定的.