MTU 影响对某些站点的访问

网络工程
2021-07-31 10:31:08

我不是这方面的专家,所以我想我会来这里征求一些意见。我在访问某些网站时遇到问题,例如 codility.com。据我了解(如果我错了,请纠正我)1500 是一个非常标准的 MTU 设置?但是,在我有访问问题的站点上,这给我带来了大量的数据包丢失,即:

ping -s 1464 -c1 codility.com
PING codility.com (52.71.87.144) 1464(1492) bytes of data.

--- codility.com ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms

但同样的事情在谷歌上说,每次都有效:

ping -s 1464 -c1 google.com
PING google.com (216.58.213.174) 1464(1492) bytes of data.
72 bytes from lhr26s02-in-f174.1e100.net (216.58.213.174): icmp_seq=1 ttl=54 (truncated)

--- google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 25.234/25.234/25.234/0.000 ms

我必须将 MTU 降低到 1200 左右,以免在 Codility 上丢包:

ping -s 1172 -c1 codility.com
PING codility.com (52.71.87.144) 1172(1200) bytes of data.
1180 bytes from ec2-52-71-87-144.compute-1.amazonaws.com (52.71.87.144): icmp_seq=1 ttl=43 time=119 ms

--- codility.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 119.048/119.048/119.048/0.000 ms

事实上,确切的最高值似乎是 1204:

ping -s 1176 -c1 codility.com
PING codility.com (52.71.87.144) 1176(1204) bytes of data.
1184 bytes from ec2-52-71-87-144.compute-1.amazonaws.com (52.71.87.144): icmp_seq=1 ttl=43 time=123 ms

--- codility.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 123.843/123.843/123.843/0.000 ms

从 1205 或更高版本开始,我完全丢包:

ping -s 1177 -c1 codility.com
PING codility.com (52.71.87.144) 1177(1205) bytes of data.

--- codility.com ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms

任何人都可以在这里给我一些一般性建议和信息吗?这是正常的吗?我应该将 MTU 永久设置为 1200 吗?这会产生什么影响?从我对我使用的路由器的观察来看,我认为 MTU 为 1500,所以我在这里查看 ISP 问题吗?

2个回答

首先:1500包大小是针对整个包的。通过多层协议头和其他开销,有效载荷少于 1500 字节。ping 的“-s”选项设置有效载荷的大小,而不是数据包的大小。

对于另一半:

在您的主机和目标之间的某处似乎有一条 MTU 较小的线。该线路上的路由器有两个选项:

将数据包拆分为适合该 MTU 的较小片段(大多数路由器不会这样做,因为这对它们来说工作量更大)

或者

丢弃数据包并向源 ip 发回一条消息,说“数据包丢失,发送较小的包。我可以通过线路容纳多达 1200 个字节”。然后发送方可以发送较小的数据包。

后者将是一个 ICMP 数据包。配置错误的防火墙可能会丢弃 ICMP 数据包(因为有些人认为 ICMP“仅被黑客使用”),因此发送方永远不知道数据包发生了什么。

此过程称为 PMTU 发现,它需要 ICMP 才能运行。

绝对不要将您的 MTU 设置为 1200 - 这会导致您在其他地方出现性能问题。

你能提供更多关于你的拓扑的信息吗?它只是您的 PC 和路由器,还是您和 Internet 之间有更大网络的企业环境?

当您测试受支持的 MTU 时,您需要使用以下命令之一来确保在 ICMP 请求中设置了 Do-Not-Fragment 位:

  • Linux: ping -s 1480 -M do codility.com
  • Mac OS X: ping -s 1480 -D codility.com
  • 视窗: ping -l 1480 -f codility.com

否则 ping 会很高兴地报告它收到了任何大小的数据包(即使它可能已被分成更小的帧以便接收)。例如:

 bdale@lojack:~$ ping -s 5000 codility.com
 PING codility.com (52.71.87.144) 5000(5028) bytes of data.
 5008 bytes from ec2-52-71-87-144.compute-1.amazonaws.com (52.71.87.144): icmp_req=1 ttl=38 time=242 ms

(不,我和 AWS 之间没有能够处理 5000 字节帧的接口!)

尝试进一步隔离问题 - 您和 AWS(托管 codility 的地方)之间是否存在问题?- 在 52.71.87.150(同一 AWS 子网中的活动主机)上尝试相同的 ping 测试,看看是否得到相同的结果。

在您和这两个地址之间运行 traceroute,然后运行到 AWS (prlog.com) 上托管的另一个站点 - 您的流量是否遵循相同的路径?

您的网络是否已经通过 VPN 直接连接到 AWS?您可能会通过此隧道路由所有 AWS 地址,这会降低 MTU(但更像是 1350 字节而不是 1200)。如果是这种情况,您将需要调整路由器上的 tcp-mss 设置,以便将通过此隧道的 TCP 流量限制在 1200 字节以下。