在 Windows 上一切都很好,但在 Linux 上,当我尝试检索特定网页时,我需要等待很长时间,然后出现“对等方重置连接”
Ping 目标 IP 工作正常。
我尝试将接口 MTU 减少到 1476(使用“ping -c1 -M do -s”找到)甚至更低的值,但并没有解决问题。
在目标主机附近的另一台 Linux PC 上,没有问题,因此我怀疑路径中存在一些路由器。
这些是 wireshark 和 tshark 输出:
重置连接的Linux:http://pastebin.com/tpjS5qZc
没有问题的Windows:http://pastebin.com/iyN1GDxT
看起来第三个数据包在到目标主机的路径上丢失了,并且目标发回了几个重复的确认数据包,但我看不出 Windows 和 Linux 数据包有任何相关的差异。
答案1
在您的捕获中,两个服务器都设置了“不分段位”。这意味着两端都在尝试进行路径 MTU 发现。
似乎有防火墙阻止了ICMP Fragmentation Needed
您的 Linux 服务器与远程服务器之间的通信。解决方法是启用 MSS 限制,方法是:
iptables -A OUTPUT -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
您还可以尝试在 Linux 中禁用 P MTU 发现:
echo 1 |sudo tee /proc/sys/net/ipv4/ip_no_pmtu_disc
从iptables
手册页中:
TCPMSS 此目标允许更改 TCP SYN 数据包的 MSS 值,以控制该连接的最大大小(通常将其限制为传出接口的 MTU 减去 IPv4 的 40 或 IPv6 的 60)。当然,它只能与 -p tcp 结合使用。
This target is used to overcome criminally braindead ISPs or servers which block "ICMP Fragmentation Needed" or "ICMPv6 Packet Too
Big" packets. The symptoms of this problem are that everything works fine from your Linux firewall/router, but machines behind it
can never exchange large packets:
1) Web browsers connect, then hang with no data received.
2) Small mail works fine, but large emails hang.
3) ssh works fine, but scp hangs after initial handshaking.
Workaround: activate this option and add a rule to your firewall configuration like:
iptables -t mangle -A FORWARD -p tcp --tcp-flags SYN,RST SYN
-j TCPMSS --clamp-mss-to-pmtu
--set-mss value
Explicitly sets MSS option to specified value. If the MSS of the packet is already lower than value, it will not be
increased (from Linux 2.6.25 onwards) to avoid more problems with hosts relying on a proper MSS.
--clamp-mss-to-pmtu
Automatically clamp MSS value to (path_MTU - 40 for IPv4; -60 for IPv6). This may not function as desired where asymmetric
routes with differing path MTU exist — the kernel uses the path MTU which it would use to send packets from itself to the
source and destination IP addresses. Prior to Linux 2.6.25, only the path MTU to the destination IP address was considered
by this option; subsequent kernels also consider the path MTU to the source IP address.
These options are mutually exclusive.
看:http://lartc.org/howto/lartc.cookbook.mtu-mss.html
编辑:在我仔细查看捕获的内容后,我发现路径上有一个损坏的防火墙,它过滤了所有使用 TCP 时间戳选项的 IP 数据包。只需在 Linux 机器上运行:echo 0 | sudo tee /proc/sys/net/ipv4/tcp_timestamps