【Windows &MTU】Windows上最大传输单元MTU值的查看和设置

Win11 22000.120 IPv6 MTU 值怎么是 1472,Win10 中却是 1500 ?
以管理员 cmd 输入:


netsh interface ipv4 show subinterfaces

netsh interface ipv6 show subinterfaces

image.png

image.png

How to set MTU size on Windows 10?

C:\Windows\system32>netsh interface ipv4 set subinterface "Ethernet" mtu=352
Ok.
    
 C:\Windows\system32>netsh interface ipv4 set subinterface "Ethernet" mtu=100
 The parameter is incorrect.

ping使用的ICMP协议,ICMP信息占用8个字节,ICMP信息的信息被封装到IP的数据包中,IP包头大小为20-60字节,会指明源地址、目标地址、TOS(Type Of Service)等等,所以,ICMP的数据包中数据的最大长度只有1500-20-8=1472。


IP包头:
4 bits  VER  (Version)
4 bits  HLEN  (Header Length)
8 bits  Service Type 
16 bits Total Length(Header + DATA)
16 bits Identification   
3 bits Flags
13 bits Fragmenttation offset
8 bits Time to live
8 bits Protocol
16 bits Header checksum
4 byte  source IP address
4 byte Destination IP Address

ICMP:
ICMP包头占用8个Byte,封装在IP包的数据部分:
8bits Type 
8bits Code
16bits Checksum
其他4字节,共计8字节包头

ICMP信息分两类:Error-reporting 和Query

Error-reporting:
3 Destination unreachable
4 Source quench
11 Time exceeded
12 Parameter proble
5 redirection

Query:   
8 or 0   Echo request or Reply
13 or 14  Timestamp request and Reply
17 or 18  Address mask request & reply
10 or 19  Route; solicitation & Advertisement

image.png

关于Ping -l 和 MTU 的详细说明

Windows xp默认的MTU=1500(字节),即允许发送不需要分段的最大IP单包字节数。
如果使用ping –l data_length命令来ping大包的话,则其中的data_length指的是ICMP的数据长度,而不是IP包的数据长度,即data_length不等于MTU 。

他们两者之间的关系为:

data_length = MTU(典型值为1500)- IP头(20)- ICMP头(8)

在MTU=1500的情况下:
IP包的最大长度 = 20(IP头)+ IP包的数据长度 = 1500字节
IP包数据的最大长度 = 8(ICMP头)+ 1472(ICMP的数据)=1480字节
ICMP数据的最大长度(单IP包) = 1472 字节

通过以上描述,我们搞清了网络接口的配置数据MTU和Ping命令中的数据包长度这2 个概念,即:MTU是网络接口发送单个IP包的最大字节数,典型值=1500。Ping命令中的data_length是ICMP的数据长度。

例如(假设本端接口的MTU=1500,对端接口的MTU=1500):

1.ping x.x.x.x
这是一条不带-l参数的ping命令,网络接口以缺省的ICMP的数据长度(32字节或64字节)发送IP包(IP包长度=60或92)。

2.ping x.x.x.x –l 1472
这是一条带-l参数的ping命令,由于1472 + 20(IP头)+ 8(ICMP头)<= 1500(MTU),所以ping包不会被分段。网络接口以ICMP的数据长度=1472发送IP包(IP包长度=1500)。

3.ping x.x.x.x –l 1500
这是一条带-l参数的ping命令,由于1500 + 20(IP头)+ 8(ICMP头)> 1500(MTU),所以IP包需要被分段发送(先发IP包长度=1500,后发IP包长度=1500-1472+20+8=56)。

4.ping x.x.x.x –f –l 3000
这是一条带-l参数的ping命令,由于3000 + 20(IP头)+ 8(ICMP头)> 1500(MTU),所以IP包需要被分段发送,但由于本命令带了-f参数(不允许分段),故网络接口无法将此IP发送出去,ping命令执行失败。

当总长度=N字节的IP包到达接收端接口时,如果接收端接口的MTU<N的话,接收端将无法接收这个总长度=N的IP包,直接丢弃。发送端收不到任何响应消息,超时后自行发出告警:timeout。

由此可知,网络上任何2个直连接口的MTU必须一致,否则必埋下隐患。所以有ping大包一说,其道理就是:如果两直连接口中,A接口的MTU=1500,B接口的MTU=1400,而ping命令缺省的数据长度字节数是32或64,即加上20(IP头)+ 8(ICMP头),也只有60或92。

如果直接用命令ping ip(A或B),都不会发现任何问题,这只能证明两者在物理上没有问题;但如果用ping 大包(单包)的命令:ping ip(A或B) –l 1472 则分别会有2种情况发生:

1.A ping B:B接口无法接收该IP包,丢弃,A接口无法得到reply的回应。操作者就会迷茫:为什么小包能ping 通,大包就不行?

  1. B ping A: 由于B接口的MTU=1400,则B接口要发送1500字节的IP包就要分段成2个IP包发送出去,A接口作为IP地址的目的地,将收到的2个IP包重组成1个1500字节的IP包作为ICMP的响应包(reply)发回给B接口,但由于B接口的MTU=1400,无法接收这个IP包,丢弃。这样一来,B接口就永远也等不到A接口的响应(实际上A接口已发出reply)。同样,操作者也会迷茫:为什么小包能ping 通,大包就不行?

结论:当碰到小包能ping 通,大包ping不通的情况,首先要查看各相关接口的MTU配置。

参考

Windows上最大传输单元MTU值的查看和设置
https://www.cnblogs.com/waliwaliwa/p/7502997.html

Largest MTU shows packet loss from 1465 to 1472 using PPPoE ?
https://www.speedguide.net/faq/28-largest-mtu-shows-packet-loss-from-1465-to-1472-227

How to set MTU size on Windows 10?
https://docs.microsoft.com/en-us/answers/questions/535814/how-to-set-mtu-size-to-100-on-windows-10.html

MTU Limit - Test and change your connection’s MTU limit
https://www.sevenforums.com/tutorials/94721-mtu-limit-test-change-your-connections-mtu-limit.html

MTU stuck at 1440
https://www.speedguide.net/forums/showthread.php?111292-MTU-stuck-at-1440

关于Ping -l 和 MTU 的详细说明
https://answers.microsoft.com/zh-hans/windows/forum/all/%E8%AE%BE%E7%BD%AEmtu%E7%9A%84%E9%97%AE%E9%A2%98/7cb86599-5321-4d32-85c8-6c08fe731028

mtu changing automatically to 1420
https://answers.microsoft.com/en-us/windows/forum/all/mtu-changing-automatically-to-1420/456f24a1-ec52-4bc1-ae61-8293e7a3db81

optimal MTU definition and setting
https://answers.microsoft.com/en-us/windows/forum/all/optimal-mtu-definition-and-setting/1342586a-7ffc-4163-a4fe-3029c2da4a98

Windows do not allow MTU size smaller than 352 bytes
https://support.microsoft.com/en-us/topic/packet-loss-occurs-when-mtu-is-below-576-and-pmtu-discovery-is-enabled-in-windows-e7a54c21-6202-9788-fb24-99530c0e9d64

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值