关于您在 MASQ 服务器上运行的 Linux 内核版本,人们对真正的问题存在分歧。以下两种观点都有其道理,并且相互关联,来自不同阵营的用户至今仍在争论不休。
对于现代 2.4.x Linux 系统,大多数用户将矛头指向这些远程故障网站(通常是 SSL 加密的 WWW 网站等)的管理员或您的 MASQ 服务器的上游路由器(由您的 ISP 运行)。主要观点是,这些机器要么正在过滤,要么没有正确响应某些或所有形式的 ICMP 数据包(特别是 ICMP 代码 3 类型 4 - 需要分片)消息,这源于一种错位的安全偏执。
这一切意味着什么? 基本上,假设您的机器以 1492 字节的 MTU(最大传输单元——您的计算机可以传输的最大数据包大小)连接到互联网,这对于 PPPoE 用户来说很常见。与此同时,远程 WWW/FTP 站点以 1500 字节的 MTU 连接到互联网。TCP/IP 的工作方式是,当为您的 HTTP / FTP 连接协商 TCP 连接时,远程端将尝试验证 1500 字节的数据包是否可以通过初始 TCP “SYN” 数据包到达您的计算机。
由于数据包对于您的连接来说太大,您的上游路由器(由您的 ISP 运行)将向远程 WWW / FTP 服务器发回 ICMP 3:4(需要分片)数据包。此数据包中包含建议的较小 MTU 大小以供重试。问题是,您的本地上游路由器、您和远程服务器之间的某些路由器,或者远程 HTTP / FTP 服务器要么配置错误,要么在其前面有一个防火墙,正在阻止这些 ICMP 数据包。
最终不太常见的可能性是 IPMASQ 代码中存在可争议的 2.0 / 2.2 内核错误。 一些用户指出,IPMASQ 可能在处理设置了 DF 或“禁止分片”位 的 ICMP 数据包时存在问题。 基本上,当 MASQ 盒以小于 1500 的 MTU 连接到互联网时,某些数据包将设置 DF 字段。 尽管将 MASQ 服务器的互联网链路 MTU 更改为 1500 似乎可以解决问题,但可能的错误仍然存在。 据信在这些较旧的内核中发生的情况是,MASQ 代码没有将 ICMP 3 子代码 4 数据包的返回 IP 地址正确地重写回原始的 MASQ 化计算机。 因此,这些关键数据包被丢弃了。
不过不用担心。 有几种非常好的方法可以解决这个棘手的 MTU 问题
在 PPPoE 中启用 PMTU 钳制
此解决方案主要适用于通过 PPPoE DSL 或有线调制解调器连接到互联网的现代 2.4.x 和 2.2.x 内核用户。 此解决方案允许仅在 MASQ 服务器本身上进行更改,而不是在所有内部 MASQ 客户端上进行更改。
通过 IPTABLES 启用 PMTU 钳制
此解决方案仅适用于通过任何类型的互联网连接连接的现代 2.4.x 内核用户。 此解决方案允许仅在 MASQ 服务器本身上进行更改,而不是在所有内部 MASQ 客户端上进行更改。
更改您的 MASQ 服务器的互联网链路 MTU
此解决方案适用于任何 Linux 内核版本,但如果您拥有用于 DSL 或有线调制解调器用户的 PPPoE 连接,则此解决方案不是一个好的选择。
应该注意的是,一些用户会反对这种解决方案,因为它可能会损害某些对延迟敏感的程序,如 TELNET 和互联网游戏,但影响只是轻微的。 另一方面,大多数 HTTP 和 FTP 流量将加速!
更改所有内部 MASQ 化机器的 MTU
此解决方案需要最多的工作,因为您必须对所有内部 IPMASQ 化机器进行细微的更改。 基本上,您需要将所有内部机器上的 MTU 更改为与您的 MASQ 服务器互联网连接的 MTU 匹配。 幸运的是,此解决方案通常是万无一失的,而本节中提到的其他一些解决方案可能很少不起作用。
对于那些使用 PPPoE 客户端(DSL / 有线调制解调器)或 PPP(拨号)的用户,您的互联网连接不是“eth0”(例如),而通常是“ppp0”。 除此之外,您的互联网链路的 MTU 或最大传输单元(您可以通过互联网传输的最大数据包)不是 1500 字节,而是 1492 字节。 1492 字节的 MTU 来自以太网的链路大小(1518 字节) - 以太网 MAC 开销(18)= 1500。 然后您减去 PPPoE 标头(8 字节)== MTU 为 1492。 这种开销没什么大不了的,但有时 ISP 或远程互联网站点会做一些愚蠢的事情来破坏 PPPoE 或非 1500 字节 MTU 连接的机器。
您可以在网上找到有关此主题的更多信息。 具体来说,这是一个关于该主题的很好的演示文稿:mss-talk 演示文稿 (PDF)。 这是完整的文档和其他有用的信息
要在 RP 或 PPPd PPPoE 客户端中启用钳制,请将以下行添加到您的 /etc/ppp/pppoe.conf 文件中
# - If you have a computer acting as a gateway for a LAN, choose "1412". # The setting of 1412 is safe for either setup, but uses slightly more # CPU power. # CLAMPMSS=1412 |
如上文针对 PPPoE 用户所述,一些 ISP 和 WWW 站点会过滤关键的 ICMP 数据包,如 MTU 路径发现。 因此,许多用户可能会发现更多网站可以访问,但其他网站会挂起或工作不佳。 幸运的是,最近的 IPTABLES 添加了 PMTU 钳制支持,这应该对您有所帮助。 如果您正在使用 IPTABLES 并且认为您遇到了这个问题,请尝试将以下行添加到您的 rc.firewall-iptables* 规则集的末尾。 应该注意的是,IPCHAINS 中没有 PMTU 钳制支持。
iptables -I FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu |
如果此行在您重新运行 rc.firewall-iptables* 防火墙规则集时导致错误,您可能需要升级您的 IPTABLES 版本,其中包含“TCPMSS”IPTABLES 模块。
此解决方案通常仅适用于拨号用户,因为 PPPoE 用户由于 PPPoE 的标头开销而无法增加其 MTU。
要使用此解决方案,首先请查看您的互联网链路的当前 MTU 是什么。 为此,请在 MASQ 服务器上运行“/bin/ifconfig”。 查看与您的互联网连接相对应的行,并查找 MTU(例如,ppp0)。 这需要设置为 1500。 通常,以太网链路的默认值为 1500,但串行/拨号调制解调器 PPP 链路的默认值可能为 576。
要更改标准以太网链路到您的桥接或路由 DSL、有线调制解调器等连接的 MTU,您需要编辑您的 Linux 发行版的正确网络启动脚本。 请参阅 TrinityOS - 第 16 节 文档,了解网络优化。
要更改 PPP(非 PPPoE)互联网链路上的 MTU 问题,请编辑您的“/etc/ppp/options”文件,并在顶部附近,在两行单独的行上添加以下文本,添加
mtu 1500 mru 1500 |
保存这些新更改,然后重新启动 PPP。 如上所示,验证您的 PPP 链路是否具有正确的 MTU 和 MTU。
CUA 用户: 最后,虽然这不是一个常见的问题,但一些 Linux 2.0.x 内核用户找到了以下问题的 MTU 解决方案。 对于 PPP 用户,验证您的 PPPd 代码连接到哪个端口。 它是 /dev/cua* 端口还是 /dev/ttyS* 端口? 它需要是 /dev/ttyS* 端口,因为 /dev/cua* 设备系统已被弃用,并且它会以非常奇怪的方式破坏某些东西。
如果您重新配置所有 MASQ 化的 PC 以使用与您的外部互联网链路的 MTU 相同的 MTU(例如,PPPoE 用户为 1492),一切都应该正常工作,并且这种方法有时是解决问题的最有效方法。 这包括上面提到的所有解决方案。 但是,如果有很多内部 MASQ 化机器,或者如果您没有对所有内部 MASQ 化机器的管理访问权限,则以这种方式做事可能会花费大量精力,甚至不可能做到。
请按照以下适用于您操作系统的简单步骤操作
以下示例使用 1492 的 MTU,用于某些 DSL 和有线调制解调器用户的典型 PPPoE 连接。 建议对所有速度为 128Kb/s 及更快的连接使用尽可能高的值。 应该注意的是,由于 ISP 内部网络中的额外开销,某些 PPPoE ISP 可能需要 1460(而不是 1492)的 MTU 设置才能实现正常连接。
使用小于 1492 或 1460 的 MTU 的唯一真正原因是降低您的互联网链路的延迟,但代价是吞吐量。 请参阅 http://www.ecst.csuchico.edu/~dranch/PPP/ppp-performance.html#mtu 以获取有关此主题的更多详细信息。
如果您知道如何对 OS/2、MacOS 等其他操作系统进行类似的更改,请发送电子邮件至 David Ranch,以便将其包含在 HOWTO 中。
------------------------------------------ 1. The setting of MTU can vary from Linux distribution to distribution. For Redhat: You need to edit the various "ifconfig" statements in the /sbin/ifup script For Slackware: You need to edit the various "ifconfig" statements in the /etc/rc.d/rc1.inet 2. Here is one good, any-distribution-will-work example, edit the /etc/rc.d/rc.local file and put the following at the END of the file: echo "Changing the MTU of ETH0" /sbin/ifconfig eth0 mtu 1492 Replace "eth0" with the interface name that is the machine's upstream connection which is connected to the Internet. 3. For advanced options like "TCP Receive Windows" and such, detailed examples on how to edit the respective networking scripts for your specific Linux distro, etc., please see Chapter 16 of http://www.ecst.csuchico.edu/~dranch/LINUX/index-linux.html#trinityos ------------------------------------------ |
------------------------------------------ 1. Making ANY changes to the Registry is inheritantly risky but with a backup copy, you should be safe. Proceed at your OWN RISK. 2. Goto Start-->Run-->RegEdit 3. Registry-->Export Registry File-->Save a copy of your registry to a reliable place 4. Navigate down to the key: [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Inter faces\<ID for Adapter> Each ID Adapter has default keys for DNS, TCP/IP address, Default Gateway, subnet mask, etc. Find the key one that is for your network card. 5. Create the following Entry: type=DWORD name="MTU" (Do NOT include the quotes) value=1492 (Decimal) (Do NOT include the text "(Decimal)") http://support.microsoft.com/support/kb/articles/Q120/6/42.asp?LN=EN-US&SD=gn&FR=0 *** If you know how to also change the MSS, TCP Window Size, and the *** TTL parameters in NT 2000, please email dranch@trinnet.net as I *** would love to add it to the HOWTO. 5. Reboot to let the changes take effect. ------------------------------------------ |
------------------------------------------ 1. Making ANY changes to the Registry is inheritantly risky but with a backup copy, you should be safe. Proceed at your OWN RISK. 2. Goto Start-->Run-->RegEdit 3. Registry-->Export Registry File-->Save a copy of your registry to a reliable place 4. Create the following keys in the Registry trees, choose two possible Registry trees. Multiple entries are for various network devices like DialUp Networking (ppp), Ethernet NICs, PPTP VPNs, etc. http://support.microsoft.com/support/kb/articles/Q102/9/73.asp?LN=EN-US&SD=gn&FR=0 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Parameters\Tcpip] and [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\<Adapter-name>\Parameters\Tcpip] Replace "<Adapter-Name>" with the respective name of your uplink LAN NIC interface type=DWORD name="MTU" (Do NOT include the quotes) value=1492 (Decimal) (Do NOT include the text "(Decimal>") (Do NOT include the quotes) *** If you know how to also change the MSS, TCP Window Size, and the *** TTL parameters in NT 4.x, please email dranch@trinnet.net as I *** would love to add it to the HOWTO. 5. Reboot to make the changes take effect. ------------------------------------------ |
------------------------------------------ 1. Making ANY changes to the Registry is inheritantly risky but with a backup copy, you should be safe. Proceed at your OWN RISK. 2. Goto Start-->Run-->RegEdit 3. You should make a backup copy of your Registry before doing anything. To do this, copy the "user.dat" and "system.dat" files from the \WINDOWS directory and put them into a safe place. It should be noted that the previously mentioned method of using "Regedit: Registry-->Export Registry File-->Save a copy of your registry" would only perform Registry MERGES and NOT do a replacement. 4. Search though each of the Registry trees that end in "n" (e.g. 0007) and have a Registry entry called "IPAddress" which has the IP address of your NIC. Under that key, add the following: From http://support.microsoft.com/support/kb/articles/q158/4/74.asp [Hkey_Local_Machine\System\CurrentControlset\Services\Class\NetTrans\000n] type=STRING name="MaxMTU" (Do NOT include the quotes) value=1492 (Decimal) (Do NOT include the text "(Decimal)") 5. You can also change the "TCP Receive Window" which sometimes increases network performance SUBSTANTIALLY. If you notice your throughput has DECREASED, put these items BACK to their original settings and reboot. [HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\MSTCP] type=STRING name="DefaultRcvWindow" (Do NOT include the quotes) value=32768 (Decimal) (Do NOT include the text "(Decimal>") type=STRING name="DefaultTTL" (Do NOT include the quotes) value=128 (Decimal) (Do NOT include the text "(Decimal>") 6. Reboot to let the changes take effect. ------------------------------------------ |
------------------------------------------ 1. Making ANY changes to the Registry is inheritantly risky but with a backup copy, you should be safe. Proceed at your OWN RISK. 2. Goto Start-->Run-->RegEdit 3. You should make a backup copy of your Registry before continuing. To do this, copy the "user.dat" and "system.dat" files from the \WINDOWS directory and put them into a safe place. It should be noted that the previously mentioned method of using "Regedit: Registry-->Export Registry File-->Save a copy of your registry" would only do Registry MERGES and NOT do a replacement. 4. Search through each of the Registry trees that end in "n" (e.g. 0007) and have a Registry entry called "IPAddress", which has the IP address of your NIC. Under that key, add the following: From http://support.microsoft.com/support/kb/articles/q158/4/74.asp [Hkey_Local_Machine\System\CurrentControlset\Services\Class\NetTrans\000n] type=DWORD name="MaxMTU" (Do NOT include the quotes) value=1492 (Decimal) (Do NOT include the text "(Decimal)") type=DWORD name="MaxMSS" (Do NOT include the quotes) value=1450 (Decimal) (Do NOT include the text "(Decimal>") 5. You can also change the "TCP Receive Window" which sometimes increases network performance SUBSTANTIALLY. If you notice your throughput has DECREASED, put these items BACK to their original settings and reboot. [HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\MSTCP] type=DWORD name="DefaultRcvWindow" (Do NOT include the quotes) value=32768 (Decimal) (Do NOT include the text "(Decimal>") type=DWORD name="DefaultTTL" (Do NOT include the quotes) value=128 (Decimal) (Do NOT include the text "(Decimal>") 6. Reboot to let the changes take effect. ------------------------------------------ |