shownb / shownb.github.com

shownb.github.io
shownb.github.io
5 stars 1 forks source link

mtu和udp和ip #17

Open shownb opened 6 years ago

shownb commented 6 years ago

ip包=ip头(固定20bytes)+剩下 udp包=udp头(固定8bytes)+剩下

下面来测试一下自己家网络的MTU瓶颈是多少。

Mac OS 下,因为网关的MTU是1492(我估计是因为是pppoe拨号,由于PPPOE还要包括8字节的PPP头),所以总的包要过去,总的大小就不能大于这个数目 = 1492-20-8 = 1464

ping -D -s 1472 -c 2 45.77.140.xx

PING 45.77.140.xx (45.77.140.xx): 1472 data bytes 556 bytes from 192.168.2.1: frag needed and DF set (MTU 1492) Vr HL TOS Len ID Flg off TTL Pro cks Src Dst 4 5 00 dc05 157c 0 0000 40 01 a32c 192.168.2.100 45.77.140.xx

改一下,刚好通过 ping -D -s 1464 -c 2 45.77.140.xx

PING 45.77.140.xx (45.77.140.xx): 1464 data bytes 1472 bytes from 45.77.140.xx: icmp_seq=0 ttl=56 time=21.638 ms

如果是linuxping -s 1473 -c 2 -M do 8.8.8.8 PING 8.8.8.8 (8.8.8.8) 1473(1501) bytes of data. ping: local error: Message too long, mtu=1500 ping: local error: Message too long, mtu=1500

难以想象,编写udp程序的时候,upd数据发送的大小,对mtu影响巨大,例如在客户端你的udp+28之后硬是要发送大于网关的mtu,那你家的弱路由网关,就老是要分片,严重影响性能。

2018年7月30日 新增TCP TCP头长度20