加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows-7 – 通过powershell设置接口的MTU

发布时间:2020-12-14 00:00:11 所属栏目:Windows 来源:网络整理
导读:我正在尝试在 Windows 7上以编程方式设置物理接口的MTU: PS (Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Where { $_.Description -match '^Red Hat.*#2' })DHCPEnabled : FalseIPAddress : {10.10.8.3,fe80::447d:38dc:bb39:f311}DefaultIP
我正在尝试在 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#rootcimv2Win32_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

看起来很好,但这只影响子接口,而不是硬件接口:

即使重启后也是如此.

好吧,这并没有真正回答你的问题,但我想它无论如何都包含一些不错的信息,所以我会把它留下来.希望有人有一个更好的.

做:

(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.我认为差异是硬件特定的.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读