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


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

    
    netsh interface ipv4 show subinterfaces
    
    netsh interface ipv6 show subinterfaces
    
    
    • 1
    • 2
    • 3
    • 4
    • 5

    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.
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    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
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37

    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

    由此可知,网络上任何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

  • 相关阅读:
    亚马逊重大更新,底层卖家的机会来了(干货)
    jsp+ssm+maven大学生就业信息系统
    行业追踪,2023-09-20
    mysql基于Spring boot开发电子宿舍管理系统毕业设计源码132056
    域名生意逆市火爆 BNS能否接棒ENS?
    扫地机器人遇瓶颈?科沃斯、石头科技“突围”
    TMC5160问题,插上步进电机、步进电机一转或步进电机带负载转瞬间,TMC5160就无输出
    ANSYS mechanical如何在Workbench环境中使用高性能计算
    pandas之数据的合并与分组
    探索未来的视觉革命:卷积神经网络的崭新时代(二)
  • 原文地址:https://blog.csdn.net/michaelwoshi/article/details/126924526