«

ping大包与MTU的关系

学长 发布于 阅读:4681 网络


C:\Documents and Settings\Administrator>ping 132.96.144.254
Pinging 132.96.144.254 with 32 bytes of data:
Reply from 132.96.144.254: bytes=32 time=1ms TTL=255
Reply from 132.96.144.254: bytes=32 time=2ms TTL=255
Reply from 132.96.144.254: bytes=32 time=3ms TTL=255
Reply from 132.96.144.254: bytes=32 time=7ms TTL=255
Ping statistics for 132.96.144.254:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 1ms, Maximum = 7ms, Average = 3ms
C:\Documents and Settings\Administrator>ping 132.96.144.254 -h
Bad option -h.
Usage: ping [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS]
            [-r count] [-s count] [[-j host-list] | [-k host-list]]
            [-w timeout] target_name
Options:
    -t             Ping the specified host until stopped.
                   To see statistics and continue - type Control-Break;
                   To stop - type Control-C.
    -a             Resolve addresses to hostnames.
    -n count       Number of echo requests to send.
    -l size        Send buffer size.
    -f             Set Don't Fragment flag in packet.
    -i TTL         Time To Live.
    -v TOS         Type Of Service.
    -r count       Record route for count hops.
    -s count       Timestamp for count hops.
    -j host-list   Loose source route along host-list.
    -k host-list   Strict source route along host-list.
    -w timeout     Timeout in milliseconds to wait for each reply.
C:\Documents and Settings\Administrator>ping 132.96.144.254 -l 3000 //在同一个网段,没有IP MTU这一说法,可以ping一组3000字节的大包
Pinging 132.96.144.254 with 3000 bytes of data:
Reply from 132.96.144.254: bytes=3000 time=3ms TTL=255
Reply from 132.96.144.254: bytes=3000 time=3ms TTL=255
Reply from 132.96.144.254: bytes=3000 time=3ms TTL=255
Reply from 132.96.144.254: bytes=3000 time=3ms TTL=255
Ping statistics for 132.96.144.254:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 3ms, Maximum = 3ms, Average = 3ms
C:\Documents and Settings\Administrator>
C:\Documents and Settings\Administrator>ping 132.96.144.254 -l 6000 //在同一个网段,ping一组6000字节的大包也没有问题
Pinging 132.96.144.254 with 6000 bytes of data:
Reply from 132.96.144.254: bytes=6000 time=5ms TTL=255
Reply from 132.96.144.254: bytes=6000 time=5ms TTL=255
Reply from 132.96.144.254: bytes=6000 time=4ms TTL=255
Reply from 132.96.144.254: bytes=6000 time=4ms TTL=255
Ping statistics for 132.96.144.254:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 4ms, Maximum = 5ms, Average = 4ms
C:\Documents and Settings\Administrator>ping 132.96.144.9
Pinging 132.96.144.9 with 32 bytes of data:
Reply from 132.96.144.9: bytes=32 time=2ms TTL=128
Reply from 132.96.144.9: bytes=32 time=1ms TTL=128
Reply from 132.96.144.9: bytes=32 time=1ms TTL=128
Reply from 132.96.144.9: bytes=32 time=1ms TTL=128
Ping statistics for 132.96.144.9:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 1ms, Maximum = 2ms, Average = 1ms
C:\Documents and Settings\Administrator>ping 132.96.144.9 -l 6000 //在同一个网段,ping一组6000字节的大包也没有问题,但所耗时间肯定比ping小包要久
Pinging 132.96.144.9 with 6000 bytes of data:
Reply from 132.96.144.9: bytes=6000 time=2ms TTL=128
Reply from 132.96.144.9: bytes=6000 time=2ms TTL=128
Reply from 132.96.144.9: bytes=6000 time=2ms TTL=128
Reply from 132.96.144.9: bytes=6000 time=2ms TTL=128
Ping statistics for 132.96.144.9:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 2ms, Maximum = 2ms, Average = 2ms
C:\Documents and Settings\Administrator>ping 132.98.81.139
Pinging 132.98.81.139 with 32 bytes of data:
Reply from 132.98.81.139: bytes=32 time=15ms TTL=250
Reply from 132.98.81.139: bytes=32 time=15ms TTL=250
Reply from 132.98.81.139: bytes=32 time=14ms TTL=250
Reply from 132.98.81.139: bytes=32 time=13ms TTL=250
Ping statistics for 132.98.81.139:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 13ms, Maximum = 15ms, Average = 14ms
C:\Documents and Settings\Administrator>ping 132.98.81.139 -l 6000 //这就不行了,ping外网段的,不可以超过路由器的IP MTU值
Pinging 132.98.81.139 with 6000 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Ping statistics for 132.98.81.139:
    Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
C:\Documents and Settings\Administrator>ping 132.98.81.139 -l 1500 //一般路由器的接口的IP MTU值都设成1500字节
Pinging 132.98.81.139 with 1500 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Ping statistics for 132.98.81.139:
    Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
C:\Documents and Settings\Administrator>ping 132.98.81.139 -l 1472 //减去包头,1500字节的IP MTU值只剩下1472字节,所以1472是包大小的上限
Pinging 132.98.81.139 with 1472 bytes of data:
Reply from 132.98.81.139: bytes=1472 time=20ms TTL=250
Reply from 132.98.81.139: bytes=1472 time=18ms TTL=250
Reply from 132.98.81.139: bytes=1472 time=16ms TTL=250
Reply from 132.98.81.139: bytes=1472 time=15ms TTL=250
Ping statistics for 132.98.81.139:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 15ms, Maximum = 20ms, Average = 17ms
C:\Documents and Settings\Administrator>ping 132.98.81.139 -l 1473
Pinging 132.98.81.139 with 1473 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Ping statistics for 132.98.81.139:
    Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
C:\Documents and Settings\Administrator>

 先看看以太帧的结构:


 
由图中标示可知,MTU指的应该是第二层之上的数据包的长度。既然是这样,那么为什么上面的实验只能ping 1472个字节的包了,这是因为ping xx.xx.xx.xx -l 1472指令中的1472实际上指的是有效数据的大小。而MTU实际上还包括第三层和应用层的前缀。对于ICMP协议,IP包头占了20个字节,ICMP协议前缀占了8个字节,合起来28个字节,而ping包的有效负载就知剩下1500-28=1472。



 
也就是说,针对不同的应用,分组的有效负载会有所不同。而对于MPLS VPN业务,由于VPN前缀及MPLS标签都是算进了MTU里面的,所以MPLS VPN的IP包的最大有效负载也是要比普通的IP包来的要小的,具体小多少不清楚,可以百度一下,这在应用中是需要注意的。 

Windows也可以修改MTU,改小了上网速度会变慢,再改小就会打不开网页了:

Microsoft Windows [版本 6.1.7600]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。

C:\Users\Administrator>netsh
netsh>interface ipv4
netsh interface ipv4>show sub

   MTU  MediaSenseState   传入字节  传出字节      接口
------  ---------------  ---------  ---------  -------------
4294967295                1          0      12000  Loopback Pseudo-Interface 1
  1500                1    4344608    1042960  USB-KEY DIAL
  1500                5          0          0  本地连接
  1500                5          0          0  本地连接* 11

netsh interface ipv4>set subinterface "USB-KEY DIAL" mtu=200 ?
找不到元素。


netsh interface ipv4>set subinterface "USB-KEY DIAL" mtu=200
确定。

netsh interface ipv4>set subinterface "USB-KEY DIAL" mtu=200 store=persistent
确定。

netsh interface ipv4>show sub

   MTU  MediaSenseState   传入字节  传出字节      接口
------  ---------------  ---------  ---------  -------------
4294967295                1          0      12000  Loopback Pseudo-Interface 1
   200                1    7182456    1855509  USB-KEY DIAL
  1500                5          0          0  本地连接
  1500                5          0          0  本地连接* 11

netsh interface ipv4>show sub

   MTU  MediaSenseState   传入字节  传出字节      接口
------  ---------------  ---------  ---------  -------------
4294967295                1          0      12000  Loopback Pseudo-Interface 1
   200                1    7195890    1873527  USB-KEY DIAL
  1500                5          0          0  本地连接
  1500                5          0          0  本地连接* 11

netsh interface ipv4>set subinterface "USB-KEY DIAL" mtu=10 store=persistent
确定。

netsh interface ipv4>set subinterface "USB-KEY DIAL" mtu=100 store=persistent
确定。

netsh interface ipv4>set subinterface "USB-KEY DIAL" mtu=50 store=persistent
确定。

netsh interface ipv4>set subinterface "USB-KEY DIAL" mtu=1500
确定。

netsh interface ipv4>


扫描二维码,在手机上阅读