使用ping命令检测网络MTU

ping命令可以用来检测网络中的MTU的大小。但在windows下面和linux下面所使用的参数是不一样的。

其思想是发送一个非默认的大小的数据包,默认是56字节,并且指定不要进行分包。如果网络中传输的时候,需要分包就会通知调用者。

 

Windows

ping -f -l 1472  www.google.com

选项解释

-f: 表示不要分包

-l: 是小写的L,表示包的大小

 

Linux

ping -M do -s 1472 -c 4 www.google.com

选项解释

-M: 表示使用路径MTU检测策略,后面的值可以是

      do: 不要分包,即使是本地

      want: 使用路径MTU检测策略, 本地分包如果必要

      dont: 不要设置DF标志

-s: 表示包的大小

 

为什么上面采用的1472,是因为一般的机器和网络中的路由器采用的MTU都是1500字节,

1500 – 20(ip包头大小) – 8(icmp包头大小) = 1472

 

你可以通过改变这个值,来查看你所要测是的源地址和目标地址之前的最小的MTU,如果返回结果是包被分片了,可以减小包,直至不再分片。

 

是网络变成的时候,可使用发ping包给目的地址来检测。

 

下面是我检测的过程:

user@ubuntu:~/Downloads/openssl-1.0.1e/ssl$ ping -M do -s 1472 -c 4 www.google.com
PING www.google.com (74.125.239.115) 1472(1500) bytes of data.

— www.google.com ping statistics —
4 packets transmitted, 0 received, 100% packet loss, time 2999ms

user@ubuntu:~/Downloads/openssl-1.0.1e/ssl$ ping -M do -s 100 -c 4 www.google.com
PING www.google.com (173.194.38.178) 100(128) bytes of data.
108 bytes from xxxxx: icmp_req=1 ttl=52 time=3.09 ms
108 bytes from xxxxx: icmp_req=2 ttl=52 time=2.93 ms
108 bytes from xxxxx: icmp_req=3 ttl=52 time=3.07 ms
^C
— www.google.com ping statistics —
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 2.937/3.037/3.097/0.071 ms
user@ubuntu:~/Downloads/openssl-1.0.1e/ssl$ ping -M do -s 1000 -c 4 www.google.com
PING www.google.com (173.194.38.180) 1000(1028) bytes of data.
1008 bytes from xxxxx: icmp_req=1 ttl=53 time=4.02 ms
1008 bytes from xxxxx: icmp_req=2 ttl=53 time=4.00 ms
^C
— www.google.com ping statistics —
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 4.000/4.014/4.028/0.014 ms
user@ubuntu:~/Downloads/openssl-1.0.1e/ssl$ ping -M do -s 1200 -c 4 www.google.com
PING www.google.com (173.194.38.177) 1200(1228) bytes of data.
1208 bytes from xxxxx: icmp_req=1 ttl=53 time=4.05 ms
1208 bytes from xxxxx: icmp_req=2 ttl=53 time=3.88 ms
^[[A1208 bytes from xxxxx: icmp_req=3 ttl=53 time=4.04 ms
1208 bytes from xxxxx: icmp_req=4 ttl=53 time=4.90 ms

— www.google.com ping statistics —
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 3.881/4.220/4.909/0.408 ms
user@ubuntu:~/Downloads/openssl-1.0.1e/ssl$ ping -M do -s 1400 -c 4 www.google.com
PING www.google.com (173.194.38.179) 1400(1428) bytes of data.
1408 bytes from xxxxx: icmp_req=1 ttl=53 time=4.61 ms
1408 bytes from xxxxx: icmp_req=2 ttl=53 time=4.36 ms
1408 bytes from xxxxx: icmp_req=3 ttl=53 time=4.51 ms
^C
— www.google.com ping statistics —
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 4.365/4.496/4.611/0.101 ms
user@ubuntu:~/Downloads/openssl-1.0.1e/ssl$ ping -M do -s 1450 -c 4 www.google.com
PING www.google.com (173.194.38.176) 1450(1478) bytes of data.
^C
— www.google.com ping statistics —
3 packets transmitted, 0 received, 100% packet loss, time 1999ms

user@ubuntu:~/Downloads/openssl-1.0.1e/ssl$ ping -M do -s 1440 -c 4 www.google.com
PING www.google.com (173.194.38.177) 1440(1468) bytes of data.
1448 bytes from xxxxx: icmp_req=1 ttl=53 time=4.19 ms
1448 bytes from xxxxx: icmp_req=2 ttl=53 time=4.25 ms
1448 bytes from xxxxx: icmp_req=3 ttl=53 time=4.31 ms
^C
— www.google.com ping statistics —
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 4.192/4.256/4.318/0.051 ms
user@ubuntu:~/Downloads/openssl-1.0.1e/ssl$ ping -M do -s 1448 -c 4 www.google.com
PING www.google.com (173.194.38.178) 1448(1476) bytes of data.
^C
— www.google.com ping statistics —
2 packets transmitted, 0 received, 100% packet loss, time 1006ms

user@ubuntu:~/Downloads/openssl-1.0.1e/ssl$ ping -M do -s 1443 -c 4 www.google.com
PING www.google.com (173.194.38.180) 1443(1471) bytes of data.
^C
— www.google.com ping statistics —
4 packets transmitted, 0 received, 100% packet loss, time 2999ms

user@ubuntu:~/Downloads/openssl-1.0.1e/ssl$ ping -M do -s 1442 -c 4 www.google.com
PING www.google.com (173.194.38.177) 1442(1470) bytes of data.
1450 bytes from xxxxx: icmp_req=1 ttl=53 time=4.30 ms
1450 bytes from xxxxx: icmp_req=2 ttl=53 time=4.18 ms
1450 bytes from xxxxx: icmp_req=3 ttl=53 time=4.18 ms
1450 bytes from xxxxx: icmp_req=4 ttl=53 time=4.98 ms

— www.google.com ping statistics —
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 4.186/4.415/4.984/0.335 ms

所以从我的pc到www.google.com (173.194.38.177)的最小的MTU是1442.

 

关于检测网络MTU,ietf有专门的协议定义, PMTU Discovery = path MTU Disconvery

 

版权所有,禁止转载. 如需转载,请先征得博主的同意,并且表明文章出处,否则按侵权处理.

    分享到:

留言

你的邮箱是保密的 必填的信息用*表示