用 ping 查找 MTU

PING

NAME
     ping -- send ICMP ECHO_REQUEST packets to network hosts

DESCRIPTION
     -c count
             Stop after sending (and receiving) count ECHO_RESPONSE packets.  If this option is not specified, ping will operate until interrupted.  If this option is specified in conjunction with ping sweeps, each sweep will consist of count packets.

     -D     
             Set the Do not Fragment bit.

     -s packetsize
             Specify the number of data bytes to be sent.  The default is 56, which translates into 64 ICMP data bytes when combined with the 8 bytes of ICMP header data.  This option cannot be used with ping sweeps.

MTU = max icmp data + icmp header(8 bytes) + ip header(20 bytes)
(题外话:MTU = MSS + tcp header(20 bytes) + ip header(20 bytes)
因为 ping -s 选项指定的是 icmp data size,所以:
ping -s (MTU-28) -D -c 1 ip_address
不断试探 -s 选项的参数最后可以查找到 MTU。

➜  ~ ping -s 1473 -D -c 1 192.168.1.105
PING 192.168.1.105 (192.168.1.105): 1473 data bytes
ping: sendto: Message too long

--- 192.168.1.105 ping statistics ---
1 packets transmitted, 0 packets received, 100.0% packet loss
➜  ~
➜  ~ ping -s 1472 -D -c 1 192.168.1.105
PING 192.168.1.105 (192.168.1.105): 1472 data bytes
1480 bytes from 192.168.1.105: icmp_seq=0 ttl=64 time=103.999 ms

--- 192.168.1.105 ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 103.999/103.999/103.999/0.000 ms

上面的例子可以看出测试机的 MTU 是 1472 + 28 = 1500(bytes)

你可能感兴趣的:(用 ping 查找 MTU)