以太网最大不分包只能到1472

Windows 上的ping命令

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] [-R] [-S srcaddr] [-c compartment] [-p]

            [-4] [-6] 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 (IPv4-only).

    -i TTL         Time To Live.

    -v TOS         Type Of Service (IPv4-only. This setting has been deprecated

                   and has no effect on the type of service field in the IP

                   Header).

    -r count       Record route for count hops (IPv4-only).

    -s count       Timestamp for count hops (IPv4-only).

    -j host-list   Loose source route along host-list (IPv4-only).

    -k host-list   Strict source route along host-list (IPv4-only).

    -w timeout     Timeout in milliseconds to wait for each reply.

    -R             Use routing header to test reverse route also (IPv6-only).

                   Per RFC 5095 the use of this routing header has been

                   deprecated. Some systems may drop echo requests if

                   this header is used.

    -S srcaddr     Source address to use.

    -c compartment Routing compartment identifier.

    -p             Ping a Hyper-V Network Virtualization provider address.

    -4             Force using IPv4.

    -6             Force using IPv6.


在Windows 上测试。发现最大只能带上1472的大小。

# ping 192.168.242.134 -f -l 1472 -n 1

Pinging 192.168.242.134 with 1472 bytes of data:
Reply from 192.168.242.134: bytes=1472 time<1ms TTL=64

Ping statistics for 192.168.242.134:
    Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms
# ping 192.168.242.134 -f -l 1473 -n 1

Pinging 192.168.242.134 with 1473 bytes of data:
Packet needs to be fragmented but DF set.

Ping statistics for 192.168.242.134:
    Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),

如果不加上-f  Set Don't Fragment flag in packet (IPv4-only),即允许分片. 是可以ping 通的。


为什么这个上限是1472

MTU大小是1500

1500 - 1472 = 28 字节

这个28 字节里,IP头部是20字节

ICMP的头部是8字节

网络-MTU_网络

WireShark 抓包

以1472大小的payload 没有分包可以正常发送。

网络-MTU_分包_02

这里看到的1514 是包含了以太网头部14字节(源MAC、目标MAC、iptype).

如果ping 192.168.242.134  -l 1473 -n 1网络-MTU_分包_03

可以看到数据包被拆分了。