Linux IP 地址伪装 HOWTO

大卫·A·兰奇

2005年11月13日

2005年11月13日

本文档描述了如何在给定的 Linux 主机上启用 Linux IP 地址伪装功能。IP 地址伪装是一种网络地址转换 (NAT) 的形式,NAT 允许没有一个或多个注册互联网 IP 地址的内部连接计算机通过 Linux 服务器的互联网 IP 地址与互联网通信。


目录
1. 简介
1.1. IP 地址伪装或 IP MASQ 简介
1.2. 前言、反馈和致谢
1.3. 版权和免责声明
2. 背景知识
2.1. 什么是 IP 地址伪装?
2.2. 当前状态
2.3. 谁可以从 IP 地址伪装中获益?
2.4. 谁不需要 IP 地址伪装?
2.5. IP 地址伪装是如何工作的?
2.6. Linux 2.4.x 上 IP 地址伪装的要求
2.7. Linux 2.2.x 上 IP 地址伪装的要求
2.8. Linux 2.0.x 上 IP 地址伪装的要求
3. 设置 IP 地址伪装
3.1. 如果需要,编译新内核
3.2. 检查现有内核的 MASQ 功能
3.2.1. 编译 Linux 2.4.x 内核
3.2.2. 编译 Linux 2.2.x 内核
3.2.3. 编译 Linux 2.0.x 内核
3.3. 为内部 LAN 分配私有网络 IP 地址
3.4. 配置 IP 转发策略
3.4.1. 在 Linux 2.6.x 和 2.4.x 内核上配置 IP 地址伪装
3.4.2. 在 Linux 2.2.x 内核上配置 IP 地址伪装
3.4.3. 在 Linux 2.0.x 内核上配置 IP 地址伪装
4. 配置其他要进行 MASQ 的内部机器
4.1. 配置 Microsoft Windows 95 和 OSR2
4.2. 配置 Windows NT
4.3. 配置 Windows for Workgroup 3.11
4.4. 配置基于 UNIX 的系统
4.5. 使用 NCSA Telnet 包配置 DOS
4.6. 配置运行 MacTCP 的 MacOS 基于系统
4.7. 配置运行 Open Transport 的 MacOS 基于系统
4.8. 使用 DNS 配置 Novell 网络
4.9. 配置 OS/2 Warp
4.10. 在 IBM AS/400 上配置 OS/400
4.11. 配置其他系统
5. 测试 IP 地址伪装
5.1. 加载 rc.firewall 规则集
5.2. 测试内部 MASQ 客户端 PC 的连接性
5.3. 测试内部 MASQ 客户端到 MASQ 服务器的连接性
5.4. 测试内部 MASQ 服务器的连接性
5.5. 测试内部 MASQ 服务器到 MASQ 客户端的连接性
5.6. 测试外部 MASQ 服务器的互联网连接性
5.7. 测试内部 MASQ 客户端到外部 MASQ 服务器的连接性
5.8. 测试外部 MASQ ICMP 转发
5.9. 在没有 DNS 的情况下测试 MASQ 功能
5.10. 使用 DNS 解析测试 MASQ 功能
5.11. 使用 DNS 测试更多 MASQ 功能
5.12. 任何剩余的功能、性能等问题...
6. 其他 IP 地址伪装问题和软件支持
6.1. IP 地址伪装的问题
6.2. 入站服务
6.3. 支持的客户端软件和其他设置注意事项
6.3.1. 与 IP 地址伪装一起工作的网络客户端
6.3.2. 在 IP MASQ 中没有完全支持的客户端:
6.4. 在初始测试后运行更强大的防火墙规则集
6.4.1. 更强大的 IP 防火墙 (IPTABLES) 规则集
6.4.2. 更强大的 IP 防火墙 (IPCHAINS) 规则集
6.4.3. 更强大的 IP 防火墙 (IPFWADM) 规则集
6.5. IP 地址伪装多个内部网络
6.5.1. iptables 支持多个内部 lan
6.5.2. ipchains 支持多个内部 lan
6.5.3. ipfwadm 支持多个内部 lan
6.6. IP 地址伪装和按需拨号连接
6.7. 使用 IPTABLES 或外部工具(如 IPPORTFW、IPMASQADM、IPAUTOFW、REDIR、UDPRED 和其他端口转发工具)进行端口转发
6.7.1. 基于 IPTABLES 的 PORTFWD'ing:为 2.6.x 和 2.4.x 内核使用 IPTABLES 的 PREROUTING 选项
6.7.2. 基于 IPMASQADM 的 PORTFWD'ing:为 2.2.x 内核使用 IPMASQADM
6.7.3. 基于 IPPORTFW 的 PORTFWD'ing:在 2.0.x 内核上使用 IPPORTFW
6.8. CU-SeeMe 和 Linux IP 地址伪装
6.9. Mirabilis ICQ
6.10. 游戏玩家:LooseUDP 补丁
7. 常见问题解答
7.1. ( 发行版 ) - 哪些 Linux 发行版支持 IP 地址伪装?
7.2. ( 要求 ) - IP 地址伪装的最低硬件要求和任何限制是什么?它的性能如何?
7.3. ( 错误 ) - 当我运行特定的 rc.firewall-* 规则集时,我收到“command not found”错误。为什么?
7.4. ( 仍然无法工作 ) - 我已经检查了所有配置,但仍然无法让 IP 地址伪装工作。我该怎么办?
7.5. ( 邮件列表 ) - 如何加入或查看 IP 地址伪装和/或 IP Masqurade 开发者邮件列表和存档?
7.6. ( NAT 与代理 ) - IP 地址伪装与代理或 NAT 服务有何不同?
7.7. ( GUI ) - 是否有任何 GUI 防火墙创建/管理工具?
7.8. ( MASQ 和动态 IP ) - IP 地址伪装是否适用于动态分配的 IP 地址?
7.9. ( MASQ 和各种网络 ) - 我可以使用有线调制解调器(双向和带调制解调器返回)、DSL、卫星链路等连接到互联网并使用 IP 地址伪装吗?
7.10. ( 按需拨号 ) - 我可以将 Diald 或 PPPd 的按需拨号功能与 IP MASQ 一起使用吗?
7.11. ( 应用 ) - IP 地址伪装支持哪些应用程序?
7.12. ( 发行版设置 ) - 如何在 Redhat、Debian、Slackware 等上运行 IP 地址伪装?
7.13. ( 超时 ) - 如果我不经常使用连接,连接似乎会断开。为什么会这样?
7.14. ( 奇怪的行为 ) - 当我的互联网连接首次建立时,没有任何工作。如果我再次尝试,一切都正常工作。这是为什么?
7.15. ( MTU ) - IP MASQ 似乎工作正常,但某些网站无法工作。这种情况通常发生在 WWW 和某些 FTP 站点上。
7.15.1. 为 PPPoE 和某些 PPP 用户启用 PMTU 钳制:
7.15.2. 通过 IPTABLES 钳制 MSS:
7.15.3. 更改 MASQ 服务器的外部 MTU:
7.15.4. 更改各种操作系统的 MTU:
7.16. ( FTP ) - MASQ 的 FTP 客户端无法工作。
7.17. ( 性能 ) - IP 地址伪装似乎很慢
7.18. ( PORTFW ) - 当我的线路空闲很长时间时,使用 PORTFW 的 IP 地址伪装似乎会中断
7.19. ( PORTFW - 本地 ) - 我无法从内部 LAN 访问我的 PORTFW 服务器
7.20. ( 日志 ) - 既然我已经设置了 IP 地址伪装,我在 SYSLOG 日志文件中收到了各种奇怪的通知和错误。如何读取 IPTABLES/IPCHAINS/IPFWADM 防火墙错误?
7.21. ( 日志减少 ) - 由于新的“更强大”的规则集,我的日志充满了数据包命中。我该如何解决这个问题?
7.22. ( MASQ 安全性 ) - 我可以配置 IP MASQ 以允许 Internet 用户直接联系内部 MASQ 服务器吗?
7.23. ( 空闲端口 ) - 我在 SYSLOG 文件中收到“kernel: ip_masq_new(proto=UDP): no free ports.”。怎么回事?
7.24. ( SETSOCKOPT ) - 当我尝试使用 IPPORTFW 时,我收到“ipfwadm: setsockopt failed: Protocol not available”!
7.25. ( SAMBA ) - Microsoft 文件和打印共享以及 Microsoft 域客户端无法通过 IP Masq 工作!
7.26. ( IDENT ) - IRC 对于 MASQ 的 IRC 用户无法正常工作。为什么?
7.27. ( IRC DCC ) - mIRC 不适用于 DCC 发送
7.28. ( IP 别名 ) - IP 地址伪装是否可以使用只有一张以太网网卡工作?
7.29. ( 多 LAN ) - 我有两个 MASQ 的 LAN,但它们彼此无法通信!
7.30. ( 流量整形 ) - 我想能够限制特定类型流量的速度
7.31. ( 计费 ) - 我需要对谁在使用网络进行计费
7.32. ( 多个 IP - DMZ 段 ) - 我有多个外部 IP 地址,我想将它们 PORTFW 到多台内部机器。我该怎么做?
7.33. ( 一对一 NAT ) - 我想做 1:1 NAT,但我不知道该怎么做
7.34. ( Netstat ) - 我正在尝试使用 NETSTAT 命令来显示我的伪装连接,但它不起作用
7.35. ( VPN ) - 我想让 Microsoft PPTP(GRE 隧道)和/或 IPSEC(Linux SWAN)隧道通过 IP MASQ 运行
7.36. ( 游戏 ) - 我想让 XYZ 网络游戏通过 IP MASQ 工作,但它不起作用。救命!
7.37. ( 停止工作 ) - IP MASQ 一开始工作正常,但过一段时间后就停止工作了。重新启动似乎可以解决这个问题。为什么?
7.38. ( SMTP 中继 ) - 内部 MASQ 计算机无法发送 SMTP 或 POP-3 邮件!
7.39. ( 源路由 ) - 我需要不同的内部 MASQ 网络从不同的外部 IP 地址出口
7.40. ( 2.4.x 内核上的 IPCHAINS 规则集 ) - ipchains.o 模块在 2.4.x 内核上可以做什么
7.41. ( IPTABLES vs. IPCHAINS vs. IPFWADM ) - 为什么 2.4.x、2.2.x 和 2.0.x 内核使用不同的防火墙系统?
7.42. ( 升级 ) - 我刚刚升级到 x.y.z 内核,为什么 IP 地址伪装不起作用?
7.43. ( EQL ) - 我需要 EQL 连接和 IP Masq 的帮助
7.44. ( 放弃 ) - 我无法让 IP 地址伪装工作!对于 Windows 平台,我有哪些选择?
7.45. ( 开发者 ) - 我想帮助 IP 地址伪装的开发。我能做什么?
7.46. ( 更多信息 ) - 在哪里可以找到更多关于 IP 地址伪装的信息?
7.47. ( 翻译 ) - 我想将此 HOWTO 翻译成另一种语言,我该怎么办?
7.48. ( 更新 ) - 此 HOWTO 似乎已过时,您还在维护它吗?您可以包含更多关于 ... 的信息吗?是否有任何使其更好的计划?
7.49. ( 感谢 ) - 我让 IP 地址伪装工作了,太棒了!我想感谢你们,我能做什么?
8. 杂项
8.1. 有用的资源
8.2. Linux IP 地址伪装资源
8.3. 感谢以下支持者..
8.4. 参考
8.5. 更新日志

第 1 章 简介

1.1. IP 地址伪装或 IP MASQ 简介

本文档描述了如何在给定的 Linux 主机上启用 Linux IP 地址伪装功能。IP 地址伪装,简称“IPMASQ”或“MASQ”,是一种网络地址转换 (NAT) 的形式,它允许没有一个或多个注册互联网 IP 地址的内部连接计算机通过 Linux 服务器的互联网 IP 地址与互联网通信。由于 IPMASQ 是一种通用技术,您可以将 Linux 服务器的内部和外部通过 LAN 技术(如以太网、令牌环和 FDDI)以及拨号连接(如 PPP 或 SLIP 链路)连接到其他计算机。本文档主要在示例中使用以太网和 PPP 连接,因为它最常用于 DSL/有线调制解调器和拨号连接。

"本文档适用于运行稳定 Linux 内核(如 2.4.x、2.2.x 和 2.0.x)的系统,最好是在 IBM 兼容 PC 上。IP 地址伪装在其他 Linux 支持的平台(如 Sparc、Alpha、PowerPC 等)上也能工作,但本 HOWTO 没有详细介绍它们。诸如 2.5.x、2.3.x、2.1.x 等 Beta 内核以及任何低于 2.0.x 的内核都不在本文档的范围之内。主要原因是许多较旧的内核被认为是存在缺陷的。如果您正在使用较旧的内核版本,强烈建议您在使用 IP 地址伪装之前升级到稳定的 Linux 内核之一。"


1.2. 前言、反馈和致谢

来自原始 IPMASQ HOWTO 作者

"作为一名新用户,我发现 Linux 内核上设置 IP 地址伪装非常令人困惑(那时,它是 1.2.x 内核)。尽管有一个 FAQ 和一个邮件列表,但没有专门针对此的文档。邮件列表中也有一些关于 HOWTO 手册的请求。因此,我决定编写此 HOWTO 作为新用户的起点,并可能为其他知识渊博的用户创建构建块。如果您(读者)对本文档有任何其他想法、更正或问题,请随时与我们联系。"

本文档最初由 Ambrose Au 于 1996 年 8 月编写,基于 Ken Eves 编写的 1.x 内核 IPMASQ FAQ 以及来自原始 IP 地址伪装邮件列表的许多有益消息。特别是,Matthew Driver 的一封邮件列表消息启发 Ambrose 设置了 IP 地址伪装,并最终编写了本 HOWTO 的 0.80 版本。1997 年 4 月,Ambrose 创建了 Linux IP 地址伪装资源网站 http://ipmasq.webhop.net,该网站自那时以来一直提供关于 Linux IP 地址伪装的最新信息。1999 年 2 月,David Ranch 接管了 HOWTO 的维护工作。然后,David 重写了 HOWTO,并在文档中添加了大量章节。今天,HOWTO 仍然由 David 维护,他不断更新它并修复任何报告的错误等。

如果您有任何更正,或者如果缺少任何信息/URL/等,请随时将关于本 HOWTO 的任何反馈或评论发送至 dranch@trinnet.net。您宝贵的反馈肯定会影响本 HOWTO 的未来!

本 HOWTO 旨在成为一个相当全面的指南,以在尽可能短的时间内使您的 Linux IP 地址伪装系统工作起来。David 只是在电视上扮演技术作家,因此您可能会发现本文档中的信息可能不如它可能的那样通用和/或客观。如果您认为某个章节可以更清晰等等,请告知 David。MASQ HOWTO 的最新版本可以在 Dranch 的 Linux 页面 找到。有关 IPMASQ 的其他新闻、HOWTO 镜像和信息可以在 IP Masquerade Resource 网页上找到。如果您对 IP 地址伪装有任何技术问题,请加入 IP Masquerade Mailing List,而不是向 David 或 Ambrose 发送电子邮件。大多数 MASQ 问题对于所有 MASQ 用户来说都是 -common- 的,并且可以由列表中的用户轻松解决。除此之外,IP MASQ 电子邮件列表的响应时间将比 David 或 Ambrose 的回复快得多。

本文档的最新版本可以在以下站点找到,这些站点还包含 HTML、Postscript、PDF 等版本


1.3. 版权和免责声明

本文档是版权所有 (c) 2003,2002,2001,2000 David A. Ranch它是一份免费文档。您可以根据 GNU 通用公共许可证 (GPL) 的条款重新分发它。

据 David 所知,本文档中的信息是正确的。但是,Linux IP 地址伪装功能是由人编写的,因此,错误、bug 等的可能性可能会不时发生。

任何人、团体或其他机构均不对因使用本文档中的信息而对您的计算机造成的任何损害和任何其他损失负责。即

"作者和所有维护人员不对因根据本文档中的信息采取的行动而造成的任何损害负责。 "

好了,说完这些... 继续我们的正题..


第 2 章 背景知识

2.1. 什么是 IP 地址伪装?

IP 地址伪装是 Linux 中的一种网络功能,类似于许多商业防火墙和网络路由器中发现的一对多 (1:Many) NAT(网络地址转换)服务器。例如,如果 Linux 主机通过 PPP、以太网等连接到互联网,则 IP 地址伪装功能允许连接到此 Linux 盒子的其他“内部”计算机(通过 PPP、以太网等)也访问互联网。Linux IP 地址伪装允许实现此功能,即使这些内部机器没有正式分配的 IP 地址

MASQ 允许一组机器通过 MASQ 网关隐形地访问互联网。对于互联网上的其他机器,出站流量将看起来来自 IP MASQ Linux 服务器本身。除了增加的功能外,IP 地址伪装还为创建高度安全的网络环境奠定了基础。使用构建良好的防火墙,破坏配置良好的伪装系统和内部 LAN 的安全性应该相当困难。

如果您想了解更多关于 MASQ(1:Many)与 1:1(真)NAT 和代理解决方案的区别,请参阅 第 7.6 节 FAQ 条目。


2.2. 当前状态

IP 地址伪装已在 Linux 内核中存在多年,并且随着内核进入 2.4.x 阶段,它已经非常成熟。自 Linux 1.3.x 以来的内核都内置了 MASQ 支持。今天,许多个人和商业企业都在使用它,并取得了出色的效果。

2.4.x 内核用户

  • 2.4.x 内核托管了一组完全重写的 NAT 代码,它比为 Linux 编写的任何以前的版本都更优越、更快、更安全。不幸的是,为 2.2.x 内核编写的几个内核模块(用于支持基于 UDP 的 RealAudio 等)尚未移植到 2.4.x。因此,如果这些网络应用程序对他们至关重要,一些人应该考虑不升级。但是,与此同时,其中一些程序已经更新,现在使用不同的、NAT 友好的协议。因此不再需要特殊的 NAT 处理。与往常一样,请参阅 http://ipmasq.webhop.net/: IP 地址伪装资源 站点以获取更新的新闻等。

常见的网络功能(如 Web 浏览、telnet、ssh、ping、traceroute 等)在默认 IP 地址伪装设置下工作良好。其他网络应用程序(如 ftp、irc 和 Real Audio)在内核中加载适当的附加 IP MASQ 模块作为模块时也能很好地工作。其他特定于网络的程序(如流音频(MP3、True Speech 等))也应该可以工作,而无需任何特殊模块。邮件列表上的一些用户在使用视频会议软件时也取得了良好的效果。

应该注意的是,不建议仅使用一张网卡 (NIC) 运行 IP 地址伪装以在内部和外部以太网网络之间进行 MASQ。有关更多详细信息,请参阅 第 7.28 节 FAQ 部分。

无论如何,请参阅 第 6.3 节 以获取 IP Maquerade 所有内核版本支持的软件的更完整列表。

IP 地址伪装作为运行各种操作系统和硬件平台的其他“客户端机器”的服务器工作良好。以下是内部 MASQ 系统运行成功的报告示例

  • UNIX:Sun Solaris, [Net,Free,Open,*i]-BSD, Hp-UX, Linux, IBM AIX, Digital UNIX, Ultrix 等

  • Microsoft Windows 2000, NT (3.x 和 4.x), 95/98/ME, Windows for Workgroups (带有 TCP/IP 包)

  • IBM OS/2

  • 运行 MacTCP 或 Open Transport 的 Apple Macintosh MacOS 机器

  • 带有数据包驱动程序和 NCSA Telnet 包的基于 DOS 的系统

  • VAXen

  • 运行 Linux 和 NT 的 Compaq/Digital Alpha

  • 带有 AmiTCP 或 AS225-stack 的 Amiga 计算机。

列表还在继续,但重点是,如果您的操作系统平台支持 TCP/IP,它应该可以与 Linux 的 IP 地址伪装一起工作!


2.3. 谁可以从 IP 地址伪装中获益?

  • 如果您有一个连接到互联网的 Linux 主机并且..

  • 如果您有运行 TCP/IP 的内部计算机通过网络连接到此 Linux 盒子,和/或

  • 如果您的 Linux 主机有多个调制解调器,并且充当连接到其他计算机的 PPP 或 SLIP 服务器,并且这些机器没有官方或公共分配的 IP 地址(即使用私有 TCP/IP 号码寻址)。

  • 如果您希望这些其他机器与互联网通信,而无需花费额外的钱从您的 ISP 处获取额外的公共/官方 TCP/IP 地址,那么您应该将 Linux 配置为路由器或购买外部路由器。


2.4. 谁不需要 IP 地址伪装?

  • 如果您的机器是连接到互联网的独立 Linux 主机(尽管设置防火墙是个好主意),或者

  • 如果您已经为您的其他机器分配了多个公共地址,并且

  • 如果您不喜欢使用 Linux 进行“免费搭乘”的想法,并且更喜欢使用昂贵的商业工具来执行完全相同的功能。


2.5. IP 地址伪装是如何工作的?

基于 Ken Eves 的原始 IP 地址伪装 FAQ:这是一个最简单设置的图示

PPP/ETH/etc.        +------------+                         +-------------+
to ISP provider     |  Linux #1  |       PPP/ETH/etc.      | Anybox      |
                    |            |                         |             |
  <---------- modem1|            |modem2 ----------- modem3|             |
                    |            |                         |             |
    111.222.121.212 |            |           192.168.0.100 |             |
                    +------------+                         +-------------+

在上图中,安装了 IP_MASQUERADING 的 Linux 盒子作为 Linux #1,并通过 PPP、以太网等连接到互联网。它被分配了一个公共 IP 地址 111.222.121.212。它还具有另一个网络接口(例如 modem2),用于允许来自 PPP 连接、以太网连接等的入站网络流量。

第二个系统(不需要是 Linux)连接到 Linux #1 盒子并开始其到互联网的网络流量。第二台机器没有从互联网公开分配的 IP 地址,因此它使用 RFC1918 私有地址,例如 192.168.0.100。(有关更多信息,请参见下文)

通过正确配置 IP 地址伪装和路由,第二台机器“Anybox”可以像直接连接到互联网一样与互联网交互,但有一些小的例外[稍后会提到]。

引用 Pauline Middelink(Linux IPMASQ 的创始人)的话

"不要忘记提及“ANYBOX”机器应该将 Linux #1 盒子配置为其默认网关(无论是默认路由还是子网都无关紧要)。如果“ANYBOX”机器通过 PPP 或 SLIP 连接连接,则应将 Linux #1 机器配置为支持所有路由地址的代理 arp。但是,代理 arp 的设置和配置超出了本文档的范围。有关更多详细信息,请参阅 PPP-HOWTO。"

以下是关于 IPMASQ 如何简要工作的摘录,尽管稍后将更详细地解释。这段简短的文字基于 comp.os.linux.networking 上的先前帖子,并已编辑以匹配上面示例中使用的名称

   o I tell machine ANYBOX that my PPP or Ethernet connected Linux box is its 
     gateway.

   o When a packet comes into the Linux box from ANYBOX, it will assign the 
     packet to a new TCP/IP source port number and insert its own IP address 
     inside the packet header, saving the originals.  The MASQ server will 
     then send the modified packet over the PPP/ETH interface onto the 
     Internet.

   o When a packet returns from the Internet into the Linux box, Linux 
     examines if the port number is one of those ports that was assigned 
     above.  If so, the MASQ server will then take the original port and 
     IP address, put them back in the returned packet header, and send 
     the packet to ANYBOX.

   o The host that sent the packet will never know the difference. 

另一个 IP 地址伪装示例

下图给出了一个典型的例子

                  Ethernet
                 192.168.0.x
    +----------+
    |          |  
    | A-box    |::::::
    |          |.2   : 
    +----------+     :
                     :      +----------+   PPP/ETH   
    +----------+     :   .1 |  Linux   |     link
    |          |     :::::::| Masq-Gate|:::::::::::::::::::>> Internet
    | B-box    |::::::      |          |  111.222.121.212
    |          |.3   :      +----------+
    +----------+     :
                     :
    +----------+     :
    |          |     :
    | C-box    |::::::
    |          |.4    
    +----------+  

                
    |                       |          |                           >
    | <-Internal Network--> |          | <- External Network ----> >
    |   connected via an    |          |    Connected from the     >
    |   Ethernet hub or     |          |    Linux server to your   > 
    |       switch          |          |    Internet connection    >

在本示例中,我们关注 (4) 个计算机系统。在最右边可能还有一些东西,您的 PPP/ETH 互联网连接通过它(调制解调器服务器、DSL DSLAM、有线调制解调器路由器等)。在互联网上,存在一些您有兴趣与之通信的远程主机(在页面最右边很远的地方)。名为 Masq-Gate 的 Linux 系统是所有内部联网机器的 IP 地址伪装网关。在本示例中,机器 A-boxB-boxC-box 必须通过 Masq-Gate 才能访问互联网。内部网络使用多个 RFC-1918 分配的私有网络地址 之一,在本例中,将是 C 类网络 192.168.0.0。如果您不熟悉 RFC1918,建议您阅读 RFC 的前几章,但要点是 TCP/IP 地址 10.0.0.0/8、172.16-31.0.0/12 和 192.168.0.0/16 是保留的。当我们说“保留”时,我们的意思是任何人都可以使用这些地址,只要它们不在互联网上路由。甚至允许 ISP 使用此私有寻址空间,只要他们将这些地址保留在自己的网络中,而不要将它们广告给其他 ISP。不幸的是,情况并非总是如此,但这超出了本 HOWTO 的范围。

无论如何,上图中的 Linux 盒子的 TCP/IP 地址为 192.168.0.1,而其他系统的地址为

  • A-Box: 192.168.0.2

  • B-Box: 192.168.0.3

  • C-Box: 192.168.0.4

这三台机器,A-box, B-boxC-box,可以具有多种操作系统中的任何一种,只要它们可以支持 TCP/IP 即可。有些如 Windows 95, Macintosh MacTCP or OpenTransport , 甚至另一台 Linux 盒子 都具有连接到互联网上其他机器的能力。当运行 IP 地址伪装时,伪装系统或MASQ-gate会转换所有这些内部连接,使其看起来源自masq-gate其自身。然后,MASQ 会进行安排,以便将返回到伪装连接的数据中继到正确的始发系统。 因此,内部网络上的系统只能看到通往互联网的直接路由,而不知道它们的数据正在被伪装。 这被称为“透明”连接。

注意:有关诸如以下主题的更多详细信息,请参阅第 7 章

  • NAT、MASQ 和代理服务器之间的区别。

  • 数据包防火墙的工作原理


2.6. Linux 2.4.x 上 IP 伪装的要求

** 请参考 IP 伪装资源 以获取最新信息。 **

  • 最新的 2.4.x 内核现在同时使用全新的 TCP/IP 网络堆栈和一个名为 NetFilter 的新 NAT 子系统。 在这套 NetFilter 工具中,我们现在有一个名为 IPTABLES 的工具,用于 2.4.x 内核,就像 2.2.x 内核的 IPCHAINS 和 2.0.x 内核的 IPFWADM 一样。 新的 IPTABLES 系统功能更强大(将多个功能组合到一个地方,例如真正的 NAT 功能)、提供更好的安全性(状态检测),并通过新的 2.4.x TCP/IP 堆栈提供更好的性能。 但是,与旧一代内核相比,这套新工具可能有点复杂。 希望如果您仔细遵循本 HOWTO,设置 IPMASQ 不会太糟糕。 如果您发现任何不清楚、完全错误等,请通过电子邮件告知 David。

    从 IPFWADM 迁移到 IPCHAINS 不同,新的 NetFilter 工具具有内核模块,实际上可以用最小的更改来支持旧的 IPCHAINS 和 IPFWADM 规则集。 因此,不再需要重写旧的 MASQ 或防火墙规则集脚本。 但是.. 对于 2.4.x 内核,您不能使用旧的 2.2.x MASQ 模块,例如 ip_masq_ftp、ip_masq_irc 等。 并且 IPCHAINS 与新的 IPTABLES 模块(如 ip_conntrack_ftp 等)不兼容。 那么,这意味着什么? 这基本上意味着,如果您想在 2.4.x 内核下使用 IPMASQ 或 PORTFW 功能,则不应使用 IPCHAINS 规则,而应使用 IPTABLES 规则。 另请记住,完全重写规则集以利用较新的 IPTABLES 功能(如状态跟踪等)可能有一些好处,但这取决于您有多少时间来迁移旧规则集。 有关更多详细信息,请参阅第 7.40 节

一些新的 2.4.x 功能包括以下内容

优点

  • 许多新的协议模块,如:amanda、eggdrop、ipsec、ipv6、portscan、pptp、quota、rsh、talk 和 tftp

  • 真正的 1:1 NAT 功能,适用于那些拥有 TCP/IP 地址和子网的用户(不再需要 iproute2 命令)

  • 状态化应用层 (FTP、IRC 等) 和状态化协议层 (TCP/UDP/ICMP) 网络流量检测

  • 内置端口转发(不再需要 ipmasqadm 或 ipportfw 命令)

  • 内置的 PORTFW 支持适用于外部和内部流量。 这意味着,对于外部流量使用 PORTFW 和内部端口重定向使用 REDIR 的用户不再需要使用两个工具!

  • 现在完全支持将 FTP 流量端口转发到内部主机,并在 conn_trak_ftp 模块中处理

  • 完整的基于策略的路由功能(基于源的 TCP/IP 地址路由)

  • 与 Linux 的 FastRoute 功能兼容,可显着加快数据包转发速度(又名 Linux 网络交换)。

    请注意,此功能仍与用于强大防火墙规则集的数据包过滤不兼容。

  • 完全支持 TCP/IP v4、v6 甚至 DECnet (ack!)

  • 支持通配符接口名称,如“ppp*”,用于串行接口,如 ppp0、ppp1 等

  • 支持在输入和输出接口上进行过滤(不仅仅是 IP 地址)

  • 源以太网 MAC 过滤

  • 拒绝服务 (DoS) 数据包速率限制

  • 数据包 REJECT 现在具有用户可选择的返回 ICMP 消息

  • 可变级别的日志记录(不同的数据包可以转到不同的 SYSLOG 级别)

  • 其他功能,如流量镜像、保护每个登录名的流量等。

缺点

  • Netfilter 是一个全新的架构,因此大多数旧的 2.2.x MASQ 内核模块(编写用于使非 NAT 友好的网络应用程序通过 IPMASQ 工作)都需要为 2.4.x 内核重写。 因此,如果您特别需要来自其中一些模块的功能(见下文),您应该坚持使用 2.2.x 内核,直到这些模块被移植或应用程序已更新为使用 NAT 友好的协议。 如果您对给定模块的移植状态感到好奇,请通过电子邮件联系模块的作者,而不是 David 或 Ambrose。 我们不编码.. 我们只是记录。 :-)

    以下是在 IPMASQ WWW 站点应用程序支持矩阵上找到的已知 IP Masq 内核模块或补丁的状态。 此外,您还应该查看 Netfilter Patch-o-Matic URL。 如果您有时间和知识来帮助移植代码,您的努力将不胜感激

     Status   = Module name =      Description and notes
    ---------   -----------   ----------------------------------
     Ported     CuSeeme      Used for Video conferencing
    
    NotPorted   DirectPlay    Used for online Microsoft-based games
    
     Ported        FTP        Used for file transfers
                              - NOTEs:  Built into the kernel and
                                        fully supports PORTFWed FTP
    
    ReWritten     H.323       Used for Video conferencing
    
    NotPorted      ICQ        Used for Instant messaging
                              * No longer required for modern ICQ clients
    
     Ported        Irc        Used for Online chat rooms
    
     Ported      Quake        Used for online Quake games
    
     Ported       PPTP        Allow for multiple clients to the same server
    
    NotPorted   Real Audio    Used for Streaming video / audio
                              * No longer required for modern RealVideo clients
    
    NotPorted    VDO Live     Used for Streaming audio?

    有关如何执行 MASQ 模块移植的文档可在 http://www.netfilter.org/documentation/HOWTO/netfilter-hacking-HOWTO.html 找到。 如果您有时间和知识,您的才能将非常有助于移植这些模块。

如果您想阅读更多关于 NetFilter 和 IPTables 的信息,请参阅:http://www.netfilter.org/documentation/index.html#HOWTO,更具体地说是 http://www.netfilter.org/documentation/HOWTO//NAT-HOWTO.html

Linux 2.4.x IP 伪装要求包括

  • 任何体面的计算机硬件。 有关更多详细信息,请参阅第 7.2 节

  • 2.4.x 内核源代码可从 https://linuxkernel.org.cn/ 获取。

    注意:大多数现代 Linux 发行版,第 7.1 节,原生带有 2.4.x 内核的发行版通常是模块化内核,并且已经包含所有 IP 伪装功能。 在这种情况下,无需编译新的 Linux 内核。 如果您要升级内核,则应注意可能需要的和/或需要升级的其他程序(在本 HOWTO 的后面部分中提到)。

  • 程序“iptables”版本 1.2.4 或更高版本(强烈建议 1.2.7a 或更高版本)存档可从 http://www.netfilter.org/ 获取

    • 注意 #1:所有低于 1.2.3 版本的 IPTABLES 都存在 FTP 模块问题,可能会绕过任何现有的防火墙规则集。 强烈建议所有 IPTABLES 用户升级到最新版本。 URL 在上面。

      注意 #2:所有低于 1.2.2 版本的 IPTABLES 在 ip_conntrack_ftp 模块中都存在 FTP“端口”安全漏洞。 强烈建议所有 IPTABLES 用户升级到最新版本。 URL 在上面。

    • 此工具与旧的 IPCHAINS 和 IPFWADM 工具非常相似,它启用了各种伪装代码、更高级形式的 NAT、数据包过滤等。 它还利用了其他 MASQ 模块,如 FTP 和 IRC 模块。 有关最新 IPTABLES howto 等的版本要求的更多信息,请访问 不可靠的 IPTABLES HOWTOs 页面。

  • 可加载内核模块,最好是 2.1.121 或更高版本,可从 http://home.pi.se/blox/modutils/index.html ftp://ftp.kernel.org/pub/linux/utils/kernel/modutils 获取

  • 在 Linux 机器上配置和运行的 TCP/IP 网络,如 Linux NET HOWTO网络管理员指南 中所述。 另请查看 David Ranch 撰写的 TrinityOS 文档。 TrinityOS 是 Linux 网络的非常全面的指南。 一些主题包括 IP MASQ、安全性、DNS、DHCP、Sendmail、PPP、Diald、NFS、基于 IPSEC 的 VPN 和性能部分,仅举几例。 总共有五十多个章节!

  • 您的 Linux 主机与互联网的连接在 Linux ISP Hookup HOWTO, Linux PPP HOWTO, 和 TrinityOS 中介绍。 其他有用的 HOWTO 可能包括:Linux DHCP mini-HOWTO, Linux Cable Modem mini-HOWTOhttp://www.tldp.org/HOWTO/DSL-HOWTO/index.html

  • 了解如何配置、编译和安装新的 Linux 内核,如 Linux Kernel HOWTO 中所述。 本 HOWTO 确实涵盖了内核编译,但仅适用于与 IP 伪装相关的选项。


2.7. Linux 2.2.x 上 IP 伪装的要求

** 请参考 IP 伪装资源 以获取最新信息。 **

  • 任何体面的计算机硬件。 有关更多详细信息,请参阅第 7.2 节

  • 2.2.x 内核源代码可从 https://linuxkernel.org.cn/ 获取。

    注意:大多数现代 Linux 发行版,第 7.1 节,原生带有 2.2.x 内核的发行版通常是模块化内核,并且已经包含所有 IP 伪装功能。 在这种情况下,无需编译新的 Linux 内核。 如果您要升级内核,则应注意可能需要的和/或需要升级的其他程序(在本 HOWTO 的后面部分中提到)。

    • 注意 #1:--- 更新您的内核 --- 低于 2.2.20 版本的 Linux 2.2.x 内核包含几个不同的安全漏洞(其中一些是 MASQ 特有的)。 低于 2.2.20 的内核有一些本地漏洞。 低于 2.2.16 的内核存在 TCP 根利用漏洞,低于 2.2.11 的内核存在 IPCHAINS 分片错误。 由于这些问题,运行具有强大 IPCHAINS 规则集的防火墙的用户可能会受到入侵。 请将您的内核升级到修复版本。

  • 注意 #2:一些较新的 第 7.1 节,如 Redhat 5.2,可能尚未准备好 Linux 2.2.x(可升级)。 DHCP、NetUtils 等工具将需要升级。 更多详细信息可以在 HOWTO 的后面部分找到。

  • 可加载内核模块,最好是 2.1.121 或更高版本,可从 http://home.pi.se/blox/modutils/index.htmlftp://ftp.kernel.org/pub/linux/utils/kernel/modutils 获取

  • 在 Linux 机器上配置和运行的 TCP/IP 网络,如 Linux NET HOWTO网络管理员指南 中所述。 另请查看 David Ranch 撰写的 TrinityOS 文档。 TrinityOS 是 Linux 网络的非常全面的指南。 一些主题包括 IP MASQ、安全性、DNS、DHCP、Sendmail、PPP、Diald、NFS、基于 IPSEC 的 VPN 和性能部分,仅举几例。 总共有五十多个章节!

  • 您的 Linux 主机与互联网的连接在 Linux ISP Hookup HOWTO, Linux PPP HOWTO, 和 TrinityOS 中介绍。 其他有用的 HOWTO 可能包括:Linux DHCP mini-HOWTO, Linux Cable Modem mini-HOWTOhttp://www.tldp.org/HOWTO/DSL-HOWTO/index.html

  • IP Chains 1.3.10 或更高版本可从 http://www.netfilter.org/ipchains/ 获取。 有关最新 IPCHAINS HOWTO 等的版本要求的更多信息,请访问 Linux IP Chains 页面 (Samba.org 镜像)

  • 了解如何配置、编译和安装新的 Linux 内核,如 Linux Kernel HOWTO 中所述。 本 HOWTO 确实涵盖了内核编译,但仅适用于与 IP 伪装相关的选项。

其他用于 2.2.x 内核的可选补丁和工具

有关这些补丁以及可能还有其他补丁的更多信息,请参阅 IP 伪装资源 页面。


2.8. Linux 2.0.x 上 IP 伪装的要求

** 请参考 IP 伪装资源 以获取最新信息。 **

以下是 2.0.x 内核的 IP 伪装补丁列表

  • Steven Clarke 的 IP 端口转发 (IPPORTFW) - 推荐

  • IP AutoForward - 不推荐

  • TCP (REDIR) 的 REDIR - 不推荐,除非内部 PORTFW 需要

  • UDP 重定向器 (UDPRED) - 不推荐

  • PORTFWed FTP

    • 如果您要将 FTP 流量端口转发到内部 FTP 服务器,您可能需要下载 Fred Viles 的 FTP 服务器补丁 “可能”的原因是一些用户在没有使用这些补丁的情况下取得了成功,而另一些用户则需要它。 有关此主题的明确详细信息,请参见本 HOWTO 的 第 6.7 节

  • X-Windows 显示转发器

  • PPTP (GRE) 和 SWAN (IPSEC) VPN 隧道转发器

    • 如果您计划将内部 MASQed PC 连接到远程 PPTP 服务器,则必须安装可从以下 URL 获取的 PPTP-Masquerade 内核补丁。 如果您计划让外部 PPTP 用户连接到内部伪装的 PPTP 服务器,则不仅需要安装内核补丁,还需要在内核中启用 PORTFW 支持。 请参阅以下 URL 获取补丁和更多信息

      John Hardin 的 VPN 伪装转发器 或仅用于 PPTP 支持的旧补丁。

  • 游戏特定补丁


第 3 章。设置 IP 伪装

3.1. 根据需要编译新内核

如果您的专用网络包含任何重要信息,请在实施 IP 伪装之前仔细考虑安全性。 默认情况下,IP MASQ 成为您连接到互联网的网关,但它也可能允许来自互联网的某人可能进入您的内部网络。

一旦 IP MASQ 正常运行,强烈建议用户实施强大的 IPFWADM/IPCHAINS 防火墙规则集。 有关更多详细信息,请参阅下面的 第 6.4.1 节第 6.4.2 节第 6.4.3 节


3.2. 检查现有内核的 MASQ 功能

如今,几乎所有现代 Linux 发行版都已准备好 MASQ,但在尝试设置之前检查您的系统始终是好的。 请按照以下几个步骤检查您的内核是否已准备好 MASQ。

要查看您的系统正在运行哪个内核,请运行以下命令

uname -a

  • 为了清晰起见:2.4.x 内核运行 IPTABLES :: 2.2.x 内核运行 IPCHAINS :: 2.0.x 内核运行 IPFWADM

  • 一般来说,您必须具有内核支持

    • IP 转发

    • IP 伪装

    • IP 防火墙

    • 等等。

您还需要编译大多数与 MASQ 相关的模块(大多数模块化内核已经完成了您需要的所有操作。 那么您将不需要重新编译内核。 如果您不确定您的 Linux 发行版是否已准备好 MASQ,请执行以下操作

  • 2.4.x 内核(从更长的列表中查找以下大多数条目)

    • 运行命令“ls /proc/sys/net/ipv4“在登录到 Linux 机器时。 这些项目是必需的,无论您的内核是将 IPMASQ 构建为模块还是静态构建,都应该存在。

      • ip_dynaddr

        ip_forward

    • 要检查 IPMASQ 是否静态编译到内核中,请运行命令“/sbin/lsmod“并查看是否加载了 MODULE 部分中显示的模块,例如以下模块。 没有? 好的,现在运行命令“ls /proc/net/“并查看您是否看到其他 /proc 文件,例如

      • ip_masquerade

        ip_conntrack

        ip_tables_names

      如果您看到这些 /proc 条目,并且没有加载任何内核模块(通过上面提到的“lsmod”命令显示),则您的内核已静态编译到 IPTABLES 子系统中,并且可以准备好在此系统上使用 IPMASQ。

    • 如果您的内核通过模块使用 IPTABLES,则上面列出的大多数内容都应该缺失(因为模块可能未加载)。 运行命令“ls /lib/modules/`uname -r`/kernel/net/ipv4/netfilter/“您应该在其中看到如下文件

      • ip_conntrack.o, ip_conntrack_ftp.o, ip_conntrack_irc.o, ip_nat_ftp.o, ip_nat_irc.o

        ip_tables.o, ipt_MASQUERADE.o, iptable_nat.o, iptable_mangle.o, iptable_filter.o

        以及一些可选的,如ipchains.o, ipt_REJECT.o, 和 ipt_tcpmss.o

      如果您看到这些内核文件,则 IPTABLES 是使用模块编译的,并且看起来已准备好在此系统上使用 IPMASQ。

  • 2.2.x 内核(从更长的列表中查找以下大多数条目):列表)

    • 运行命令“ls /proc/sys/net/ipv4“在登录到 Linux 机器时。 这些项目是必需的,无论您的内核是将 IPMASQ 构建为模块还是静态构建,都应该存在。

      • ip_always_defrag

        ip_dynaddr

        ip_forward

        ip_masq_debug

        ip_masq_udp_dloose(某些发行版不支持此功能 -- 现在忽略它

        可以通过运行“ls /proc/net/”来检查其他 2.2.x 选项

        • ip_fwchains

          ip_fwnames

          ip_masquerade

        可以通过运行“ls /proc/net/”来检查更多 2.2.x 选项

        • app

          icmp

          icq

          mfw

          portfw

          tcp

          udp/

  • 2.0.x 内核(从更长的列表中查找以下大多数条目)

    • 运行命令“ls /proc/sys/net/ipv4“在登录到 Linux 机器时。 这些项目是必需的,无论您的内核是将 IPMASQ 构建为模块还是静态构建,都应该存在。

      • ip_dynaddr

        ip_forward

        运行“ls /proc/net”

        • ip_forward

          ip_masq_app

          ip_masquerade

          ip_portfw

最终,归结为是否看到 /proc 文件,例如“iip_forward", "ip_masq_debug", "ip_masq_udp_dloose”(可选)和“ip_always_defrag”(可选)存在。

所以。 大多数上述 /proc 条目或内核模块是否显示在您的相应内核中? 如果是,那就太好了! 如果您找不到上述任何条目,或者您不确定您的发行版是否默认支持 IP 伪装,请假定它不支持 MASQ。 您可以查看 第 7.1 节 部分,看看您的 Linux 发行版是否列在其中,来进行最后一次检查。 仍然没有? 听起来您需要编译内核,但不用担心.. 这并不难。

无论您当前的内核是否支持 MASQ,仍然强烈建议阅读本节的其余部分,因为它包含其他有用的信息。


3.2.1. 编译 Linux 2.4.x 内核

  • 首先,您需要获取一些 2.4.x 内核源代码(最好是最新的内核版本 - 在 LINUX 世界中,更新的版本*更好*)

    • 注意 #1:随着 2.4.x 内核系列和 iptables 程序开发的进展,编译配置选项会随着时间推移而变化。 截至本版本的 IPMASQ howto,本节反映了 IPTABLES 1.2.7a 和 2.4.20 内核的设置。 如果您正在针对更新或更早版本的内核或 IPTABLES 版本进行编译,则对话框甚至命令可能看起来有所不同。 建议您更新到最新版本的内核和 IPTABLES,以提高内核的功能、性能和稳定性。

  • 接下来,根据您下载的 Linux 内核和 IPTABLES 存档的版本,您可能需要将一些 IPTABLES “patch-o-matic” 补丁应用于内核。 这些可选补丁可能会修复一些已知问题,添加您可能需要的其他功能(H.323 协议,网络游戏的特定问题)等。 应该注意的是,Patch-O-Matic 补丁以前与 IPTABLES 存档一起提供。 现在情况不再如此,您必须单独下载它们(如果有的话)。 您可以在 第 2.6 节中找到用于下载 IPTABLES、Patch-o-matic 系统等的各种 URL。

  • 如果这是您第一次编译内核,请不要害怕。 实际上,这相当容易,并且在 第 2.6 节中找到的几个 URL 中对此进行了介绍。 请注意,此处包含的说明只是构建内核的一种方法。 有关完整详细信息,请参阅内核 HOWTO。

    注意:请注意,不建议将新内核源代码放入 /usr/src/linux 目录中。 您应该将 Linux 发行版随附的原始内核源代码保留在 /usr/src/linux 中。 有关此主题的更多详细信息,请阅读内核源代码顶层目录中的“README”文件。

  • 对于本 HOWTO 示例,创建一个名为/usr/src/kernel的目录。 接下来,“cd”进入此目录并将最新的 2.4.x 内核源代码下载到其中。 下载完成后,发出以下命令(如果文件以 .tar.gz 结尾)tar xvzf linux-2.4.x.tar.gz或(如果文件以 .tar.bzip2 结尾)tar xyvf linux-2.4.x.tar.bz2。 请将 2.4.x 文件名中的“x”替换为您下载的 Linux 2.4 内核版本。

    BZ2 注意:某些 Linux 发行版使用 “I” 选项而不是 “y” 选项来解压缩 bzip2 存档。

    解压缩后,我建议您将目录从默认的 “linux” 名称重命名为 “linux-2.4.x”(将 “x” 替换为您新安装的内核的特定版本),以使其更清晰。 为此,运行命令“mv linux linux-2.4.x”。 接下来,确保有一个目录或符号链接指向“/usr/src/kernel/linux”,即运行命令

    ln -s /usr/src/kernel/linux-2.4.x /usr/src/kernel/linux
    再次替换 “x” 为您正确的内核版本。

  • 如上所述,您可能需要考虑在编译最终内核之前,将任何适当的或可选的补丁应用于内核的 MASQ 代码。 股票内核中找到的 IP MASQ 代码已经非常有用,并且不需要任何特定的修补即可使系统适用于 NAT 友好的网络应用程序。 许多这些补丁仅用于修复可能的已知错误、添加新功能(有些非常酷)等。 有关 URL 和 IP 伪装资源,请参阅第 2.6 节,以获取最新信息和补丁 URL。

  • 应用 IPTABLES 和 Patch-o-Matic 内核补丁

    第 2.6 节下载 iptables 包和可选的 Patch-O-Matics,并将其放入目录中,例如“/usr/src/archive/netfilter”。 接下来,进入这个新的 netfilter 目录,并使用命令解压缩 iptables 存档

    tar xyvf iptables-x.y.z.tar.bz2
    tar xyvf patch-o-matic-x.tar.bz2

    现在,进入新的 iptables-x.y.x 目录 (/usr/src/archive/netfilter/iptables-x.y.z) 并运行命令

     #For iptables v1.2.7a:
     make KERNEL_DIR=/usr/src/kernel/linux
      
     #For iptables v1.2.4 (when Patch-o-matic was built-in):
     make pending-patches KERNEL_DIR=/usr/src/kernel/linux
      

    注意:这假定您的 2.4.x 内核源代码位于/usr/src/kernel/linux目录中。

    注意 #2:如果您在上述命令行末尾附加 “/”,您将收到一个错误,提示

    "make: *** [/usr/src/kernel/linux/include/asm/socket.h] Error 1".
    删除尾部的 “/” 并重试。

    以下是编译 IPTABLES v1.2.7a 的示例。 您的输出可能因您尝试使用的版本而异。

  • # make KERNEL_DIR=/usr/src/kernel/linux
    
    Extensions found:
    
    cc -O2 -Wall -Wunused -I/usr/src/kernel/linux/include -Iinclude/
    -DIPTABLES_VERSION=\"1.2.7a\"  -fPIC -o extensions/libipt_ah_sh.o -c
    extensions/libipt_ah.c
    ld -shared -o extensions/libipt_ah.so extensions/libipt_ah_sh.o
    cc -O2 -Wall -Wunused -I/usr/src/kernel/linux/include -Iinclude/
    -DIPTABLES_VERSION=\"1.2.7a\"  -fPIC -o extensions/libipt_conntrack_sh.o -c
    extensions/libipt_conntrack.c
    ld -shared -o extensions/libipt_conntrack.so extensions/libipt_conntrack_sh.o
    cc -O2 -Wall -Wunused -I/usr/src/kernel/linux/include -Iinclude/
    -DIPTABLES_VERSION=\"1.2.7a\"  -fPIC -o extensions/libipt_dscp_sh.o -c
    extensions/libipt_dscp.c
    extensions/libipt_dscp_helper.c:69: warning: `dscp_to_name' defined but not
    used
    ld -shared -o extensions/libipt_dscp.so extensions/libipt_dscp_sh.o
    .
    .
    .
    cc -O2 -Wall -Wunused -I/usr/src/kernel/linux/include -Iinclude/
    -DIPTABLES_VERSION=\"1.2.7a\"    -c -o libipulog/libipulog.o
    libipulog/libipulog.c
    ar rv libipulog/libipulog.a libipulog/libipulog.o
    a - libipulog/libipulog.o
    rm libiptc/libip6tc.o libiptc/libip4tc.o libipulog/libipulog.o libipq/libipq.o

  • 好的,希望 IPTABLES 程序为您编译完成。 现在,您需要安装它。 为此,进入目录并运行命令

     make install KERNEL_DIR=/usr/src/kernel/linux

  • 以下是安装 IPTABLES v1.2.7a 的示例。 您的输出可能因您尝试使用的版本而异。

  • # make install KERNEL_DIR=/usr/src/kernel/linux   
    
    cp iptables /usr/local/sbin/iptables
    cp iptables-save /usr/local/sbin/iptables-save
    cp iptables-restore /usr/local/sbin/iptables-restore
    cp ip6tables /usr/local/sbin/ip6tables
    cp extensions/libipt_ah.so /usr/local/lib/iptables/libipt_ah.so
    cp extensions/libipt_conntrack.so /usr/local/lib/iptables/libipt_conntrack.so
    cp extensions/libipt_dscp.so /usr/local/lib/iptables/libipt_dscp.so
    cp extensions/libipt_ecn.so /usr/local/lib/iptables/libipt_ecn.so
    cp extensions/libipt_esp.so /usr/local/lib/iptables/libipt_esp.so
    cp extensions/libipt_helper.so /usr/local/lib/iptables/libipt_helper.so
    .
    .
    .
    cp extensions/libip6t_udp.so /usr/local/lib/iptables/libip6t_udp.so
    cp extensions/libip6t_LOG.so /usr/local/lib/iptables/libip6t_LOG.so
    cp extensions/libip6t_MARK.so /usr/local/lib/iptables/libip6t_MARK.so

接下来,如果您有兴趣应用 Patch-O-Matic 补丁集,请进入patch-o-matic-X目录 (/usr/src/archive/netfilter/patch-o-matic-X) 并运行命令

  •  #For Patch-O-Matic later than the release of iptables v1.2.7a:
     KERNEL_DIR=/usr/src/kernel/linux
     ./runme pending
      

    注意 #1:“pending” 批处理的使用对于 IPMASQ 功能最常见,但还有其他几种。 请参阅下文。

    注意 #2:这假定您的 2.4.x 内核源代码位于/usr/src/kernel/linux目录中。

    注意 #3:如果您在命令行末尾附加 “/”,您将收到一个错误,提示

    "make: *** [/usr/src/kernel/linux/include/asm/socket.h] Error 1".
    Remove the trailing "/" and try again.

    以下是对于 2.4.20 内核和 “20030107” Patch-O-Matic 集,您可能会收到的 Patch-O-Matic 提示示例。 如果您愿意,您还可以以批处理模式运行 “runme” 程序以加快速度,添加实验性补丁等。 为了更好地理解您的选项,只需运行 “./runme” 命令本身。 请注意,这些提示会随着时间的推移而更改。

  • Welcome to Rusty's Patch-o-matic!
    
    Each patch is a new feature: many have minimal impact, some do not.
    Almost every one has bugs, so I don't recommend applying them all!
    -------------------------------------------------------
    Already applied: submitted/01_2.4.19
                     submitted/02_2.4.20
                     submitted/ipt_ULOG-mac_len-fix
                     submitted/ipt_multiport-invfix
                     pending/01_ip_conntrack_proto_tcp-lockfix
                     pending/02_newnat-udp-helper
                     pending/03_REJECT-fwspotting-phrack60-fix
                     pending/04_ftp-conntrack-msg-fix
    
    Testing... 05_ECN-tcpchecksum-littleendian-fix.patch NOT APPLIED (1 rejects out
    of 1 hunks)
    The pending/05_ECN-tcpchecksum-littleendian-fix patch:
       Author: Patrick McHardy 
       Status: Pending for kernel inclusion
       
       The 2.4.20 kernel included the new iptables 'ECN' target, enabling a
    selective
       ECN disable mechanism.   Unfortunately there was a bug in the incremental
    TCP
       checksum update, resulting in broken TCP checksums on little endian
    machines.
       
       This patch fixes the Bug.
       
    Testing patch pending/05_ECN-tcpchecksum-littleendian-fix.patch...
       Patch pending/05_ECN-tcpchecksum-littleendian-fix.patch applied cleanly.
    Applying patch pending/05_ECN-tcpchecksum-littleendian-fix.patch...
       Patch pending/05_ECN-tcpchecksum-littleendian-fix.patch applied cleanly.
    
    Excellent! Kernel is now ready for compilation.

  • 如果一切修补正常,您应该在屏幕底部看到类似以下文本的内容

    Excellent! Kernel is now ready for compilation.

    除此之外,您此时不必安装任何东西。 下一步是编译新的已修补内核。

  • 好的,现在新的内核已准备好编译,但您应该确保您也拥有适当匹配的iptables程序在您的机器上(只是为了确保)。 运行命令

    • whereis iptables

    并确保它安装在机器上(默认位置在/usr/local/sbin/iptables。 如果您找不到它或如上所示修补了您的内核源代码,我建议您如上所示重新编译它。

现在内核源代码已修补完毕,您需要对其进行配置,以了解您需要的功能类型(HD 支持、网络支持、MASQ 支持等)。 以下是启用 IP 伪装功能所需的最低内核配置选项。 请理解,本 HOWTO 仅说明了一种配置和编译内核的方法(模块与静态)。 本示例与不同 MASQ 指南给出的示例的主要区别在于,有些人可能希望将内核组件编译为模块或单体到内核中。 基本上,将事物编译为模块可以让您更灵活地选择内核中安装或未安装的内容(减少您不使用/不会使用的东西的不必要的内存使用,并且模块还允许插入式软件升级 [通常不需要重新启动机器])。 另一方面,内核模块会增加配置的复杂性,有时内核自动加载器可能会出错(并不是说我曾经见过这种情况发生)。 将事物直接编译到内核中会使事情更简单,但是您会失去很大的灵活性。 以下内核配置示例是将内核模块的选择和将它们单体构建结合在一起的混合体(您可能将始终需要准备好 MASQ 功能)。

  • 旁注:假设您还将内核配置为使用您安装的其他硬件,例如 USB 打印机、以太网网络接口、SCSI 和 IDE HD 控制器等。 另请参阅 Linux Kernel HOWTO 和内核源代码的 “README” 文件和 “Documentation/” 目录,以获取有关编译内核的详细帮助。

您将需要对以下程序回答 YES、NO 或 MODULE。 如果没有本 HOWTO 稍后描述的适当内核补丁,并非所有选项都可用。 这应该不是问题,因为大多数第三方补丁仅适用于非常选择的用户组。

运行以下命令来配置您的内核

  • cd /usr/src/kernel/linux

  • make menuconfig

请注意,以下内核提示反映了 2.4.14 内核(带有一些可选的 Patch-O-Matic 添加项。 请仔细阅读以下建议

[ Code maturity level options ]

  * Prompt for development and/or incomplete code/drivers (CONFIG_EXPERIMENTAL) [Y/n/?]
    - YES: though not required for IP MASQ, this option allows the kernel to create 
           the MASQ modules and enable the option for port forwarding

  * Enable loadable module support (CONFIG_MODULES) [Y/n/?]
    - YES: allows you to load kernel IP MASQ modules

  * Set version information on all module symbols (CONFIG_MODVERSIONS) [Y/n/?]
    - YES: allows newer kernels to load older modules if possible

  * Kernel module loader (CONFIG_KMOD) [Y/n/?] 
    - OPTIONAL: Recommended : allows the kernel to load various kernel modules as it needs them

  == Non-MASQ options skipped
  ==   (CPU type, memory, SMP, FPU, specific stuff)


[ General setup ]

  * Networking support (CONFIG_NET) [Y/n/?]
    - YES: Enables the network subsystem

  == Non-MASQ options skipped 
  ==   (specific hardware, PCI, kernel binaries, PCMCIA, etc.)


  * Sysctl support (CONFIG_SYSCTL) [Y/n/?] 
    - YES:  Enables the ability to enable disable options such as forwarding,
      dynamic IPs, etc. via the /proc interface


[ Block devices ]

  == Non-MASQ options skipped
  ==   (kernel binaries, power management, PnP, RAID, etc.)

    == Don't forget to compile in support for hardware that you might need:
    ==   IDE controllers, HDs, CDROMs, etc.

[ Networking options ]

  * Packet socket (CONFIG_PACKET) [Y/m/n/?]
    - YES: Though this is OPTIONAL, this recommended feature will allow you 
           to use TCPDUMP to debug any problems with IP MASQ

  * Packet socket: mmapped IO (CONFIG_PACKET_MMAP) [N/y/?] y
    - YES: Speed up the packet protocol

  * Kernel/User netlink socket (CONFIG_NETLINK) [Y/n/?] 
    - OPTIONAL:  Recommended : this feature will allow the logging of 
           advanced firewall issues such as routing messages, etc

  * Routing messages (CONFIG_RTNETLINK) [N/y/?] (NEW) y
    - OPTIONAL: Allows for support of advanced kernel routing messages
                if you enabled the CONFIG_NETLINK option

  * Netlink device emulation (CONFIG_NETLINK_DEV) [N/y/m/?] (NEW)  
    - NO:  This option does not have anything to do with packet firewall 
           logging

  * Network packet filtering (replaces ipchains) (CONFIG_NETFILTER) [N/y/?] y
    - YES: Enable this option to let IPTABLES configure the TCP/IP subsection
           of the kernel.  By enabling this, then you can turn on advanced 
           routing mechanisms like IP Masq, packet filtering, etc.

  * Network packet filtering debugging (CONFIG_NETFILTER_DEBUG) [N/y/?] (NEW) n
    - NO: Not required for Masquerading functionality though it may help 
          for troubleshooting.  There might be a performance penalty when
          enabling this.

  * Socket Filtering (CONFIG_FILTER) [Y/n/?]
    - OPTIONAL:  Recommended : Though this doesn't have anything do with IPMASQ, 
      if you plan on implimenting a DHCP server on the internal network, you WILL 
      need to enable this option.

  * Unix domain sockets (CONFIG_UNIX) [Y/m/n/?]
    - YES:  This enables the UNIX TCP/IP sockets mechanisms

  * TCP/IP networking (CONFIG_INET) [Y/n/?]
    - YES: Enables the TCP/IP protocol

  * IP: multicasting (CONFIG_IP_MULTICAST) [N/y/?] 
    - OPTIONAL:  You can enable this if you want to be able to receive
                 Multicast traffic.  Please note that your ISP must 
                 support Multicast as well for this all to work at all
                 
  * IP: advanced router (CONFIG_IP_ADVANCED_ROUTER) [Y/n/?]
    - OPTIONAL:  Though there is nothing in this section mandatory for 
                 Masquerade, some specific options might be useful

    == Non-MASQ options skipped 
    ==   ( autoconf, tunneling )

  * IP: multicast routing (CONFIG_IP_MROUTE) [N/y/?] n
    - OPTIONAL:  Though not needed for IPMASQ, enabling this feature will
                 let you route multicast traffic through your Linux box.
                 Please note that this requires that your ISP be multicast
                 enabled as well.

    == Non-MASQ options skipped 
    ==   (ARPd) 

  * IP: TCP Explicit Congestion Notification support (CONFIG_INET_ECN) [N/y/?] n
    - NO: Though enabling this option would be great, there are many Internet
          sites out there that will block this.  Hit the "?" when configuring
          the kernel to learn more about it but it is recommended to say NO for 
          now.

  * IP: TCP syncookie support (disabled per default) (CONFIG_SYN_COOKIES) [Y/n/?]
    - YES: Recommended : for basic TCP/IP network security


[ Networking options --> IP: Netfilter Configuration ]


  * Connection tracking (required for masq/NAT) (CONFIG_IP_NF_CONNTRACK) [N/y/m/?] (NEW) m
    - YES: (Module) This enables the kernel to track various network connections.
           This option is required for Masquerading support as well as to enable 
           Stateful tracking for various filewall mechanisms.  Please note that
           if you compile this directly into the kernel, you cannot enable
           the legacy IPCHAINS or IPFWADM compatibility modules.

  * FTP protocol support (CONFIG_IP_NF_FTP) [M/n/?] (NEW) m
    - YES: (Module) This enables the proper Masquerading of FTP connections if 
           CONFIG_IP_NF_CONNTRACK was enabled above

  * IRC protocol support (CONFIG_IP_NF_IRC) [M/n/?] (NEW) m
    - YES: (Module) This enables the proper Masquerading of IRC connections if 
           CONFIG_IP_NF_CONNTRACK was enabled above

  * Userspace queueing via NETLINK (EXPERIMENTAL) (CONFIG_IP_NF_QUEUE) [N/y/m/?] (NEW) m
    - OPTIONAL: Though this is OPTIONAL, this feature will allow IPTABLES to 
                copy specific packets to UserSpace tools for additional checks

  * IP tables support (required for filtering/masq/NAT) (CONFIG_IP_NF_IPTABLES) [N/y/m/?] (NEW) m
    - YES: (Module) Enables IPTABLES support

  * limit match support (CONFIG_IP_NF_MATCH_LIMIT) [N/y/m/?] (NEW) y
    - OPTIONAL:  (Module) Recommended : Though not required, this option can used to 
                 enable rate limiting of both traffic and loggin messages help slow down denial
                 of service (DoS) attacks.

  * MAC address match support (CONFIG_IP_NF_MATCH_MAC) [N/y/m/?] (NEW) m
    - OPTIONAL:  Though not required, the option can allow you to 
                 filter traffic based upon the SOURCE Ethernet MAC address.

  * netfilter MARK match support (CONFIG_IP_NF_MATCH_MARK) [N/y/m/?] (NEW) y
    - YES: (Module) Recommended : This enables IPTABLES to take action upon marked packets.  
           This mechanism can allow for PORTFW functionality, TOS marking, etc.

  * Multiple port match support (CONFIG_IP_NF_MATCH_MULTIPORT) [N/y/m/?] (NEW) y
    - YES: (Module) Recommended : This enables IPTABLES to accept mutliple SRC/DST port
           ranges (non-contiguous) instead of one port range per IPTABLES 
           statement.

  * TOS match support (CONFIG_IP_NF_MATCH_TOS) [Y/m/n/?] n
    - OPTIONAL:  This allows IPTABLES to match packets based upon their
                 DIFFSERV settings.

  * LENGTH match support (CONFIG_IP_NF_MATCH_LENGTH) [N/m/?] (NEW) n
    - OPTIONAL:  This allows IPTABLES to match packets based upon their
                 packet length.

  * TTL match support (CONFIG_IP_NF_MATCH_TTL) [N/m/?] (NEW) ? n
    - OPTIONAL:  This allows IPTABLES to match packets based upon their
                 TTL settings.

  * tcpmss match support (CONFIG_IP_NF_MATCH_TCPMSS) [N/y/m/?] m
    - OPTIONAL: (Module) Recommended :  This option allows users to examine the MSS value in
                 TCP SYN packets.  This is an advanced knob but can be very valuable in 
                 troubleshooting MTU problems.

  * Connection state match support (CONFIG_IP_NF_MATCH_STATE) [M/n/?]  m
    - YES: (Module) Recommended : This option allows for Stateful tracking of network
            connections.

  * Unclean match support (EXPERIMENTAL) (CONFIG_IP_NF_MATCH_UNCLEAN) [N/y/m/?] y
    - YES: (Module) Recommended :  This option allows for connection tracking on odd packets.
           It cal also help in the detection of possibly malicious packets.
            This can be a valuable tool in tracking hostile people on the network.

  * Owner match support (EXPERIMENTAL) (CONFIG_IP_NF_MATCH_OWNER) [N/y/m/?] n
    - OPTIONAL:  This option allows IPTABLES to match traffic based upon the 
                 user login, group, etc. who created the traffic.

  * Packet filtering (CONFIG_IP_NF_FILTER) [N/y/m/?] ? y
    - YES: (Module) This option allows for the kernel to be able filter traffic at
            the INPUT, FORWARDING, and OUTPUT traffic points.

    * REJECT target support (CONFIG_IP_NF_TARGET_REJECT) [N/y/m/?] (NEW) y
      - YES: (Module) With this option, a packet firewall can send an ICMP Reject packet
            back to the originator when a packet is blocked.

  * MIRROR target support (EXPERIMENTAL) (CONFIG_IP_NF_TARGET_MIRROR) [N/y/m/?] (NEW) n
    - OPTIONAL: This option allows the packet firewall to mirror the exact same 
                network packet back to the originator when it is supposed to be 
                blocked.  This is similar to the REJECT option above but it actually 
                sends the original packet back to the originator.  i.e. a
                hostile user could actually portscan themselves.


  * Full NAT (CONFIG_IP_NF_NAT) [M/n/?] m
    - YES: (Module) This option enables the future menus to enable Masquerading, 
           PORTFWing, Full (1:1) NAT, etc.


  * MASQUERADE target support (CONFIG_IP_NF_TARGET_MASQUERADE) [M/n/?] (NEW) m
    - YES: (Module) This option specifically enables Masquerade into the 
           kernel

  * REDIRECT target support (CONFIG_IP_NF_TARGET_REDIRECT) [N/y/m/?] n
    - OPTIONAL: Not needed for normal MASQ functionality though people who 
                want to do transparent proxy via Squid will want this.  

  * Basic SNMP-ALG support (EXPERIMENTAL) (CONFIG_IP_NF_NAT_SNMP_BASIC) [N/m/?] n
    - OPTIONAL: This enables IPTABLES to properly NAT internal SNMP packets so 
                that machines with duplicate addressing ranges can be properly
                managed.

                
  * Packet mangling (CONFIG_IP_NF_MANGLE) [N/y/m/?] y
    - YES: (Module) This option allows for advanced IPTABLES packet manipulation 
           options.


  * TOS target support (CONFIG_IP_NF_TARGET_TOS) [N/y/m/?] (NEW) n
    - OPTIONAL: Enables the kernel to modify the TOS field in a packet 
           before routing it on

  * MARK target support (CONFIG_IP_NF_TARGET_MARK) [N/y/m/?] (NEW) m
    - OPTIONAL: (Module) Recommended : This enables the kernel to manipulate 
                packets based upon the MARK field.  This can be used for PORTFW 
                as well as many other things.

  * LOG target support (CONFIG_IP_NF_TARGET_LOG) [N/y/m/?]  m
    - YES: (Module)  This allows for the logging of packets before they are accepted,
           denied, rejected, etc.

  * TCPMSS target support (CONFIG_IP_NF_TARGET_TCPMSS) [N/y/m/?] ? m
    - YES: (Module) This option help some people with MTU problems.  Typically,
           most users have to set their Internet connection's MTU to 
           1500 as well as ALL internal machines to 1500.  With this
           option, this whole MTU issue might be finally solved.

  * ipchains (2.2-style) support (CONFIG_IP_NF_COMPAT_IPCHAINS) [N/y/m/?] m
    - OPTIONAL: (Module) Recommended : If you have an existing IPCHAINS ruleset 
           (2.2.x kernels) and enable this option, you can continue to use the 
           IPCHAINS program and the majority of your old ruleset except for the 
           use of any 2.2.x kernel-specific modules.  Please note that if this
           IPCHAINS module is loaded, ALL IPTABLES modules will be non-
           operational.  This is an either/or deal only intended for legacy
           rulesets.

  * ipfwadm (2.0-style) support (CONFIG_IP_NF_COMPAT_IPFWADM) [N/y/m/?] n
    - OPTIONAL: If you have an existing IPFWADM ruleset (2.0.x kernels) and 
           enable this option, you can continue to use the IPFWADM program and 
           the majority of your old ruleset except for the use of any 2.0.x 
           kernel-specific modules.   Please note that if this IPFWADM module 
           is loaded, ALL IPTABLES modules will be non operational.  This is 
           an either/or deal only intended to support legacy rulesets.                 


    == Non-MASQ options skipped
    ==   (IPv6, khttpd, ATM, IPX, AppleTalk, etc.) --

  * Fast switching (read help!) (CONFIG_NET_FASTROUTE) [N/y/?] n
    - NO: This performance optimization is NOT compatible with IP MASQ and/or
          packet filtering


    == Non-MASQ options skipped
    == (QoS, Telephony, IDE, SCSI, 1394FW, I2O, etc)

      == Don't forget to compile in support for hardware that you might need:
      ==   IDE:    HDs, CDROMs, etc.
      ==   SCSI:   HDs, CDROMs, etc.


[ Network device support ]

  * Network device support (CONFIG_NETDEVICES) [Y/n/?]
    - YES: Enables the Linux Network device sublayer 

    == Non-MASQ options skipped
    ==   (Arcnet) 


  * Dummy net driver support (CONFIG_DUMMY) [M/n/y/?] 
    - YES:  Though OPTIONAL, this option can help when debugging problems

    == Non-MASQ options skipped
    == (EQL, etc..)

    == Don't forget to compile in support for hardware that you might need:
    ==   NICs:   eth, tr, etc.
    ==   MODEMs: ppp (ppp async) and/or slip
    ==   WANs:   T1, T3, ISDN, etc.
    ==   ISDN:   for internal ISDN modems


    == Non-MASQ options skipped
    ==   (Amateur Radio, IrDA, ISDN, USB, etc.)


[ Character devices ]

    == Don't forget to compile in serial port support if you are a modem user
    == Don't forget to compile in mouse support

    == Non-MASQ options skipped
    ==   (I2C, Watchdog cards, Ftape, Video for Linux, etc. )


[ File systems ]

    == Non-MASQ options skipped
    ==   (Quota, ISO9660, NTFS, etc )

  * /proc filesystem support (CONFIG_PROC_FS) [Y/n/?]
    - YES:  Required to dynamically configure the Linux forwarding 
            and NATing systems


    == Non-MASQ options skipped
    ==   (Console drivers, Sound, USB, Kernel Hacking) 
因此,继续选择 “退出”,您应该会收到保存配置的提示。

注意:这些只是您需要用于 IP 伪装网络支持的内核组件。 您将需要选择特定设置所需的任何其他选项。 如果您想了解有关这些内核模块中的每一个的作用的更多信息,请参阅本 HOWTO 的 FAQ 部分以获取详细信息。

  • 现在编译内核 (make dep; make clean; make bzImage; make modules; make modules_install) 等。 同样,如果您在编译内核时遇到问题,则超出了本 HOWTO 的范围。 请参阅 第 2.6 节 获取内核 howto 等的 URL。

  • 然后,您将需要移动内核二进制文件,更新您的引导加载程序(LILO、Grub 等),然后重新启动。 如果您对内核编译有疑问,我强烈建议您查阅本节上面提到的一些 URL。


3.2.2. 编译 Linux 2.2.x 内核

有关任何必需的软件、补丁等,请参阅第 2.7 节

  • 首先,您需要 2.2.x 的内核源代码(最好是最新的内核版本)

    • 注意 #1:--- 更新您的内核 --- 低于 2.2.20 版本的 Linux 2.2.x 内核包含几个不同的安全漏洞(其中一些是 MASQ 特有的)。 低于 2.2.20 的内核有一些本地漏洞。 低于 2.2.16 的内核存在 TCP 根利用漏洞,低于 2.2.11 的内核存在 IPCHAINS 分片错误。 由于这些问题,运行具有强大 IPCHAINS 规则集的防火墙的用户可能会受到入侵。 请将您的内核升级到修复版本。

    • 注意 #2:随着 2.2.x 系列的进展,编译时选项不断变化。 截至本版本,本节反映了 2.2.20 内核的设置。

      如果您运行的是更新或更旧的内核版本,则对话框看起来会有所不同。 建议您更新到最新的内核,以提高系统的功能和稳定性。

  • 如果这是您第一次编译内核,请不要害怕。 实际上,这相当容易,并且在 第 2.7 节中找到的几个 URL 中对此进行了介绍。 请注意,此处包含的说明只是构建内核的一种方法。 有关完整详细信息,请参阅内核 HOWTO。

    注意:请注意,不建议将新内核源代码放入 /usr/src/linux 中。 您应该将 Linux 发行版随附的原始内核源代码保留在 /usr/src/linux 中。 有关此主题的更多详细信息,请阅读内核源代码顶层目录中的 “README” 文件。

  • 对于本 HOWTO 示例,创建一个名为/usr/src/kernel。 接下来,“cd” 进入此目录并将最新的 2.2.x 内核源代码下载到其中。 下载完成后,发出以下命令(如果文件以 .tar.gz 结尾)tar xvzf linux-2.2.x.tar.gz或(如果文件以 .tar.bzip2 结尾)tar xyvf linux-2.2.x.tar.bz2。 请将 2.2.x 文件名中的 “x” 替换为您下载的 Linux 2.2 内核版本。

    注意:某些 Linux 发行版使用 “I” 选项而不是 “y” 选项来解压缩 bzip2 存档。

    解压缩后,我建议您将目录从 “linux” 重命名为 “linux-2.2.x”,以使其更清晰。 为此,运行命令mv linux linux-2.2.x。 接下来,确保有一个目录或符号链接指向/usr/src/kernel/linux即运行命令ln -s /usr/src/kernel/linux-2.2.x /usr/src/kernel/linuxo 再次将 “x” 替换为您正确的内核版本。

  • 对内核源代码应用任何适当的或可选的补丁。默认情况下,标准的 Linux 内核不需要任何特定的补丁即可使系统正常工作。PPTP/IPSEC 伪装等功能已内置于最新的内核中,但 Xwindows 转发器等其他工具是可选的。有关 URL,请参阅第 2.7 节,有关最新信息和补丁 URL,请参阅IP Masquerade 资源

  • 现在内核已打好补丁(如果需要),以下是启用 IP Masquerade 功能所需的最低内核配置选项。请理解,本 HOWTO 仅说明了一种编译内核的方法。此方法与另一种方法的主要区别在于,有些人希望将某些内容编译为模块或直接整体编译到内核中。基本上,将内容编译为模块可以为您提供更大的灵活性,以便决定哪些内容安装到内核中或不安装(减少不必要的内存使用并允许直接升级 [无需重启]),但它们会增加配置的复杂性。另一方面,直接将内容编译到内核中会使事情变得更简单,但您会失去一定程度的灵活性。以下示例是内置和模块的混合。

    旁注: 假设您还将配置内核以使用您安装的其他硬件,例如网络接口、可选的 SCSI 控制器等。有关编译内核的详细帮助,请参阅 Linux Kernel HOWTO 以及内核源代码的 README 文件和 Documentation/ 目录。

请注意以下选项的是或否答案。并非所有选项都可用,除非应用了本 HOWTO 后续描述的适当内核补丁。

运行以下命令来配置您的内核

  • cd /usr/src/kernel/linux

  • make menuconfig

以下内核提示反映了 2.2.20 内核

[ Code maturity level options ]

  * Prompt for development and/or incomplete code/drivers (CONFIG_EXPERIMENTAL) [Y/n/?]
    - YES: though not entirely required for IP MASQ, this option allows the kernel 
           to create possible additional MASQ modules such as PORTFW, etc.

  == Non-MASQ options skipped
  ==   (CPU, memory, MTRR, SMP, etc.)


[ Loadable module support ]

  * Enable loadable module support (CONFIG_MODULES) [Y/n/?] y
    - YES: allows you to load kernel IP MASQ modules

  * Set version information on all symbols for modules (CONFIG_MODVERSIONS) [N/y/?] y
    - YES: allows newer kernels to load older modules if possible

  * Kernel module loader (CONFIG_KMOD) [Y/n/?] y
    - OPTIONAL: Recommended : allows the kernel to load various kernel modules as 
         it needs them


[ General setup ]

  * Networking support (CONFIG_NET) [Y/n/?]
    - YES: This enables the network subsystem

  == Non-MASQ options skipped
  ==   (PCI, kernel binaries, specific hardware options, etc.)


  * Sysctl support (CONFIG_SYSCTL) [Y/n/?] 
    - YES:  Enables the ability to enable disable options such as forwarding,
      dynamic IPs, etc. via the /proc interface


[ Block devices ]

  == Non-MASQ options skipped
  ==   (kernel binaries, power management, PnP, IDE, SCSI, etc.)

    == Don't forget to compile in support for hardware that you might need:
    ==   IDE controllers, HDs, CDROMs, etc.


[ Networking options ]


  * Packet socket (CONFIG_PACKET) [Y/m/n/?] y
    - YES: Though this is OPTIONAL, this recommended feature will allow you 
           to use TCPDUMP to debug any problems with IP MASQ

  * Kernel/User netlink socket (CONFIG_NETLINK) [Y/n/?] y
    - OPTIONAL: Recommended :  This feature will allow the logging of 
           advanced firewall issues such as routing messages, etc

  * Routing messages (CONFIG_RTNETLINK) [Y/n/?] y
    - OPTIONAL: If you enabled the CONFIG_NETLINK option above, this option 
           will send routing messages and other information to SYSLOG.

  * Netlink device emulation (CONFIG_NETLINK_DEV) [N/y/m/?] (NEW) n
    - NO:  This option does not have anything to do with packet firewall 
           logging

  * Network firewalls (CONFIG_FIREWALL) [Y/n/?] y
    - YES: Enables the kernel to be comfigured by the IPCHAINS firewall tool

  * Socket Filtering (CONFIG_FILTER) [Y/n/?] y
    - OPTIONAL:  Though this doesn't have anything do with IPMASQ, if you 
         plan on implimenting a DHCP server on the internal network, you 
         WILL need this option.

  * Unix domain sockets (CONFIG_UNIX) [Y/m/n/?] y
    - YES:  This enables the UNIX TCP/IP sockets mechanisms

  * TCP/IP networking (CONFIG_INET) [Y/n/?] y
    - YES: Enables the TCP/IP protocol

  * IP: multicasting (CONFIG_IP_MULTICAST) [N/y/?] y
    - OPTIONAL:  You can enable this if you want to be able to receive
                 Multicast traffic.  Please note that your ISP must 
                 support Multicast as well for this all to work
                 
  * IP: advanced router (CONFIG_IP_ADVANCED_ROUTER) [Y/n/?] n
    - OPTIONAL:  Though there is nothing in this section mandatory for 
                 Masquerade, some specific options might be useful

  * IP: kernel level autoconfiguration (CONFIG_IP_PNP) [N/y/?] ?
    - NO:  Not needed for normal MASQ functionality

  * IP: firewalling (CONFIG_IP_FIREWALL) [Y/n/?] y
    - YES: This enables the kernel to support packet filtering, NAT, etc.

  * IP: firewall packet netlink device (CONFIG_IP_FIREWALL_NETLINK) [Y/n/?] n
    - OPTIONAL: Though this is OPTIONAL, this feature will allow IPCHAINS to 
                copy some packets to UserSpace tools for additional checks

  * IP: transparent proxy support (CONFIG_IP_TRANSPARENT_PROXY) [N/y/?] n
    - OPTIONAL:  Not needed for normal MASQ functionality though people who 
           want to do transparent proxy via Squid will want this.  Please note
           that there is a PERFORMANCE PENALTY enabling this feature.

  * IP: masquerading (CONFIG_IP_MASQUERADE) [Y/n/?] y
    - YES: Enable IP Masquerade to re-address specific internal to external 
           TCP/IP packets

  * IP: ICMP masquerading (CONFIG_IP_MASQUERADE_ICMP) [Y/n/?] y
    - YES: Enable support for masquerading ICMP ping packets (ICMP error 
           codes will be MASQed regardless).  This is an important feature 
           for troubleshooting connections.

  * IP: masquerading special modules support (CONFIG_IP_MASQUERADE_MOD) [Y/n/?] y
    - YES: Though OPTIONAL, this enables the option to later enable other
           modules like the PORTFW to give external computers a directly 
           connection to specified internal MASQed machines.

  * IP: ipautofw masq support (EXPERIMENTAL) (CONFIG_IP_MASQUERADE_IPAUTOFW) [N/y/m/?] n
    - NO:  NOT recommended : IPautofw is a legacy method of port forwarding.  It 
           is mainly old code and has been found to have some issues.  

  * IP: ipportfw masq support (EXPERIMENTAL) (CONFIG_IP_MASQUERADE_IPPORTFW) [Y/m/n/?] y
    - OPTIONAL: Recommended : This enables PORTFW which allows external computers 
           on the Internet to directly communicate to specified internal MASQed 
           machines.  This feature is typically used to allow access to internal 
           SMTP, TELNET, and WWW servers.  Please note that FTP port forwarding 
           needs an additional patch, as described in the FAQ section of the MASQ 
           HOWTO.  Please see the this FAQ section in the HOWTO for additional 
           information.

  * IP: ip fwmark masq-forwarding support (EXPERIMENTAL) (CONFIG_IP_MASQUERADE_MFW) [Y/m/n/?] y
    - OPTIONAL:  This is a NEW method of performing PORTFW-like functionality which is
           similar to how the new 2.4.x kernels do things.  With this option, IPCHAINS 
           can mark packets that should have additional work done upon it.  Using a 
           UserSpace tool, much like IPMASQADM or IPPORFW, IPCHAINS would then 
           do things like re-address the packets, change their TOS value, etc. 
           Currently, this code is less tested than PORTFW but it looks promising.  
           For now, this HOWTO recommends to use IPMASQADM and IPPORTFW.  If you 
           have specific thoughts or comments on MFW, please email dranch.

  * IP: optimize as a router not host (CONFIG_IP_ROUTER) [Y/n/?] y
    - YES:  This optimizes the kernel for the network subsystem, though it 
            isn't well known if this makes a siginificant performance difference 
            or not.

  == Non-MASQ options skipped 
  ==   ( autoconf, tunneling, GRE )


  * IP: multicast routing (CONFIG_IP_MROUTE) [N/y/?] n
    - OPTIONAL:  Though not needed for IPMASQ, enabling this feature will
                 let you route multicast traffic through your Linux box.
                 Please note that this requires that your ISP be multicast
                 enabled as well.


    == Non-MASQ options skipped 
    ==  (Aliasing, ARPd) 

  * IP: TCP syncookie support (disabled per default) (CONFIG_SYN_COOKIES) [Y/n/?]
    - YES: Recommended : for basic TCP/IP network security

  * IP: GRE tunnels over IP (CONFIG_NET_IPGRE) [N/y/m/?]
    - NO:   This OPTIONAL selection is to enable PPTP and GRE tunnels through 
            the IP MASQ box

    == Non-MASQ options skipped
    ==   (aliasing, ARPd) 


  * IP: TCP syncookie support (not enabled per default) (CONFIG_SYN_COOKIES) [Y/n/?]
    - YES: HIGHLY recommended for basic TCP/IP network security

    == Non-MASQ options skipped
    ==  (RARP)


  * IP: Allow large windows (not recommended if <16Mb of memory) * (CONFIG_SKB_LARGE) [Y/n/?]
    - YES:  This is recommended to optimize Linux's TCP window 

    == Non-MASQ options skipped
    ==   (IPv6, IPX, WAN router, etc.)

  * Fast switching (read help!) (CONFIG_NET_FASTROUTE) [N/y/?] n
    - NO: This performance optimization is NOT compatible with IP MASQ and/or
          packet filtering


  == Non-MASQ options skipped
  == (Slow CPU, Telephony, SCSI, I2O, etc. )

    == Don't forget to compile in support for hardware that you might need:
    ==   SCSI:   HDs, CDROMs, etc.


[ Network device support ]

  * Network device support (CONFIG_NETDEVICES) [Y/n/?]
    - YES: Enables the Linux Network device sublayer 


  == Non-MASQ options skipped
  ==   (Arcnet) 


  * Dummy net driver support (CONFIG_DUMMY) [M/n/y/?] 
    - YES:  Though OPTIONAL, this option can help when debugging problems


  == Non-MASQ options skipped
  == (EQL, NICs, Wireless, IrDA, ISDN, etc..)

    == Don't forget to compile in support for hardware that you might need:
    ==   NICs:   eth, tr, etc.
    ==   MODEMs: ppp and/or slip
    ==   WANs:   T1, T3, ISDN, etc.
    ==   ISDN:   for internal ISDN modems


 [ Character devices ]

  == Don't forget to compile in serial port support for modem users
  == Don't forget to compile in mouse support


  == Non-MASQ options skipped
  ==   (I2C, Watchdog cards, Ftape, Video for Linux, USB, etc. )


[ File systems ]

  == Non-MASQ options skipped
  ==   (Quota, ISO9660, NTFS, etc )


  * /proc filesystem support (CONFIG_PROC_FS) [Y/n/?]
    - YES:  Required to dynamically configure the Linux forwarding 
            and NATing systems


  == Non-MASQ options skipped
  ==   (network fs, NLS, video section, sound, kernel hacking)
因此,继续 “exit”,您应该会看到保存配置的提示。

注意:这些只是 IP Masquerade 所需的组件。您将需要根据您的具体设置选择任何其他需要的选项。

  • 现在编译内核(make dep; make clean; make bzImage; make modules; make modules_install)等等。同样,如果您在编译内核时遇到问题,则超出了本 HOWTO 的范围。有关 KERNEL howto 等的 URL,请参阅第 2.7 节

  • 然后,您需要移动内核二进制文件,更新引导加载程序(LILO、Grub 等),并重新启动。如果您对内核编译有疑问,我强烈建议您查阅本节中的一些 URL。


3.2.3. 编译 Linux 2.0.x 内核

有关任何所需的软件、补丁等,请参阅第 2.8 节

  • 首先,您需要 2.0.x 的内核源代码(最好是最新的内核版本)

    • 随着 2.0.x 系列的进展,编译时选项不断变化。截至本版本,本节反映了 2.0.39 内核的设置。

  • 如果这是您第一次编译内核,请不要害怕。实际上,这非常容易,并且在第 2.8 节中找到的几个 URL 中对此进行了介绍。请注意,此处包含的说明只是构建内核的一种方法。有关完整详细信息,请参阅 Kernel HOWTO。

    注意:请注意,不建议将新内核源代码放入 /usr/src/linux 中。 您应该将 Linux 发行版随附的原始内核源代码保留在 /usr/src/linux 中。 有关此主题的更多详细信息,请阅读内核源代码顶层目录中的 “README” 文件。

  • 对于本 HOWTO 示例,创建一个名为/usr/src/kernel. 接下来, “cd” 进入此目录,并将最新的 2.0.x 内核源代码下载到其中。下载完成后,执行以下命令tar xvzf linux-2.0.x.tar.gz. 请将 2.0.x 文件名中的 “x” 替换为您下载的 Linux 2.0 内核版本。

    解压后,我建议您将目录名从 “linux” 重命名为 “linux-2.0.x” 以使其更清晰。要执行此操作,请运行命令mv linux linux-2.0.x。 接下来,确保有一个目录或符号链接指向/usr/src/kernel/linux即运行命令ln -s /usr/src/kernel/linux-2.0.x /usr/src/kernel/linuxo 再次将 “x” 替换为您正确的内核版本。

  • 对内核源代码应用任何适当的或可选的补丁。默认情况下,标准的 Linux 内核不需要任何特定的补丁即可使系统正常工作。IPPORTFW、PPTP 和 Xwindows 转发器等功能是可选的,但非常有用。有关 URL,请参阅第 2.8 节,有关最新信息和补丁 URL,请参阅IP Masquerade 资源

  • 现在内核已打好补丁(如果需要),以下是启用 IP Masquerade 功能所需的最低内核配置选项。请理解,本 HOWTO 仅说明了一种编译内核的方法。此方法与另一种方法的主要区别在于,有些人希望将某些内容编译为模块或直接整体编译到内核中。基本上,将内容编译为模块可以为您提供更大的灵活性,以便决定哪些内容安装到内核中或不安装(减少不必要的内存使用并允许直接升级 [无需重启]),但它们会增加配置的复杂性。另一方面,直接将内容编译到内核中会使事情变得更简单,但您会失去一定程度的灵活性。以下示例是内置和模块的混合。

    旁注: 假设您还将配置内核以使用您安装的其他硬件,例如网络接口、可选的 SCSI 控制器等。有关编译内核的详细帮助,请参阅 Linux Kernel HOWTO 和内核源代码的 "README” 文件和 “Documentation/” 目录,以获取有关编译内核的详细帮助。

请注意以下选项的是或否答案。并非所有选项都可用,除非应用了本 HOWTO 后续描述的适当内核补丁

运行以下命令来配置您的内核

  • cd /usr/src/kernel/linux

  • make menuconfig

以下内核提示反映了 2.0.39 内核

[ Code maturity level options ]

  * Prompt for development and/or incomplete code/drivers (CONFIG_EXPERIMENTAL) [Y/n/?] 
    - YES: this will allow you to later select the IP Masquerade feature code 


[ Loadable module support ]

  * Enable loadable module support (CONFIG_MODULES) [Y/n/?] y
    - YES: allows you to load kernel IP MASQ modules

  * Set version information on all module symbols (CONFIG_MODVERSIONS) [N/y/?] y
    - YES: allows newer kernels to load older modules if possible

  * Kernel daemon support (e.g. autoload of modules) (CONFIG_KERNELD) [N/y/?] y
    - OPTIONAL: Recommended : allows the kernel to load various kernel modules as 
         it needs them


[ General setup ]

  == Non-MASQ options skipped
  ==   (FPU, memory) 

  * Networking support (CONFIG_NET) [Y/n/?] y
    - YES: Enables the network subsystem

  == Non-MASQ options skipped
  ==   (memory, PCI, binary format, APM, etc.) 

    == Don't forget to compile in support for hardware that you might need:
    ==   IDE controllers, HDs, CDROMs, etc.


[ Networking options ]

  * Network firewalls (CONFIG_FIREWALL) [Y/n/?] y
    - YES: Enables the IPFWADM firewall tool

  == Non-MASQ options skipped
  ==   (Aliasing)


  * TCP/IP networking (CONFIG_INET) [Y/n/?] y
    - YES: Enables the TCP/IP protocol

  * IP: forwarding/gatewaying (CONFIG_IP_FORWARD) [N/y/?] y
    - YES: Enables Linux network packet forwarding and routing 
           - Controlled by IPFWADM

  * IP: multicasting (CONFIG_IP_MULTICAST) [N/y/?] y
    - OPTIONAL:  You can enable this if you want to be able to receive
                 Multicast traffic.  Please note that your ISP must 
                 support Multicast as well for this all to work
                 
  * IP: syn cookies (CONFIG_SYN_COOKIES) [Y/n/?] y
    - YES: HIGHLY recommended for basic network security

  * IP: firewalling (CONFIG_IP_FIREWALL) [Y/n/?] y
    - YES: Enable the packet firewall features

  * IP: firewall packet logging (CONFIG_IP_FIREWALL_VERBOSE) [Y/n/?] y
    - YES: Allows the kernel to report back on various packets traversing
           the firewall.

  * IP: masquerading (CONFIG_IP_MASQUERADE [Y/n/?] y
    - YES: Enable the kernel to perform IP MASQ NAT functionality

  * IP: ipautofw masquerade support (EXPERIMENTAL) (CONFIG_IP_MASQUERADE_IPAUTOFW) [Y/n/?] n
    - NO:  NOT Recommended : IPautofw is a legacy method of TCP/IP port forwarding.  
           Though IPautofw works, IPPORTFW is a better choice.


  * IP: ipportfw masq support (EXPERIMENTAL) (CONFIG_IP_MASQUERADE_IPPORTFW) [Y/n/?] y
    - YES: This option is ONLY AVAILABLE VIA A PATCH for the 2.0.x kernels.  
           With this option, external computers on the Internet can directly 
           communicate to specified internal MASQed machines.  This feature is 
           typically used to access internal SMTP, TELNET, and WWW servers.  
           FTP port forwarding sometimes might require an additional patch as 
           described in the FAQ section.  Additional information on port 
           forwarding is available in the Forwards section of this HOWTO.


  * IP: MS PPTP masq support (EXPERIMENTAL) (CONFIG_IP_MASQUERADE_PPTP) [N/y/?] (NEW) n
    - OPTIONAL: Enabling this feature will allow internal MASQ clients to
          properly connect to PPTP servers on the Internet.

  * IP: MS PPTP Call ID masq support (CONFIG_IP_MASQUERADE_PPTP_MULTICLIENT) [N/y/?] (NEW) n
    - OPTIONAL:  If you enabled the CONFIG_IP_MASQUERADE_PPTP above, this
          option will allow for multiple internal PPTP clients behind the MASQ 
          server to communicate to the same PPTP server.

  * IP: MS PPTP masq debugging (DEBUG_IP_MASQUERADE_PPTP) [N/y/?] n
    - OPTIONAL:  NOT recommended : This is not required for IP MASQ or MASQing PPTP 
           connections unless you need additional troubleshooting help.  If enabled, 
           this can fill up your logs quickly.

  * IP: MS PPTP masq verbose debugging (DEBUG_IP_MASQUERADE_PPTP_VERBOSE) [N/y/?] (NEW) n
    - OPTIONAL: NOT Recommended : If you enabled the DEBUG_IP_MASQUERADE_PPTP
           option above, this will make the logging even more verbose.

  * IP: IPSEC ESP & ISAKMP masq support (EXPERIMENTAL) * (CONFIG_IP_MASQUERADE_IPSEC) [N/y/?] m
    - OPTIONAL: This option allows for some forms of IPSEC tunnels to be
           masquraded

  * IP: IPSEC masq table lifetime (minutes) (CONFIG_IP_MASQUERADE_IPSEC_EXPIRE) * [30] (NEW) 
    - OPTIONAL: This feature allows to change the MASQ table timeouts so that
      idle IPSEC tunnels won't be prematurely disconnected.

  * IP: Disable inbound ESP destination guessing * (CONFIG_IP_MASQUERADE_IPSEC_NOGUESS) [N/y/?] n
    - OPTIONAL: This feature allows the kernel to guess where the fully encrypted IPSEC VPN 
           might be going and add it to the MASQ table.

  * IP: IPSEC masq debugging (DEBUG_IP_MASQUERADE_IPSEC) [N/y/?] ? n
    - OPTIONAL:  NOT recommended : This is not required for IP MASQ or MASQing IPSEC 
           connections unless you need additional troubleshooting help.  If enabled, 
           this can fill up your logs quickly.

  * IP: IPSEC masq verbose debugging (DEBUG_IP_MASQUERADE_IPSEC_VERBOSE) [N/y/?] (NEW) n
    - OPTIONAL: NOT Recommended : If you enabled the DEBUG_IP_MASQUERADE_IPSEC
           option above, this will make the logging even more verbose.


  * IP: ICMP masquerading (CONFIG_IP_MASQUERADE_ICMP) [Y/n/?]
    - YES: Enable support for masquerading ICMP packets. Though thought of as 
           optional, many programs will NOT function properly with out ICMP 
           support.

  * IP: transparent proxy support (EXPERIMENTAL) (CONFIG_IP_TRANSPARENT_PROXY) [N/y/?] n
    - OPTIONAL:  Not needed for normal MASQ functionality though people who 
           want to do transparent proxy via Squid will want this.  Please note
           that there is a PERFORMANCE PENALTY enabling this feature.

  * IP: loose UDP port managing (EXPERIMENTAL) (CONFIG_IP_MASQ_LOOSE_UDP) [Y/n/?] 
    - YES: This option is ONLY AVAILABLE VIA A PATCH for the 2.0.x kernels.
           With this option, internally masqueraded computers can play 
           NAT-friendly games over the Internet.  Explicit details are given 
           in the FAQ section of this HOWTO.

  * IP: always defragment (CONFIG_IP_ALWAYS_DEFRAG) [Y/n/?]
    - YES:  This feature optimizes IP MASQ connections

  == Non-MASQ options skipped
  ==   (Accounting)


  * IP: optimize as router not host (CONFIG_IP_ROUTER) [Y/n/?] 
    - YES:  This optimizes the kernel for the network subsystem 

  == Non-MASQ options skipped
  ==   (Tunneling, Mcast routing, RARP, PMTU, etc.)


  * IP: Drop source routed frames (CONFIG_IP_NOSR) [Y/n/?]
    - YES: HIGHLY recommended for basic network security

  == Non-MASQ options skipped
  ==   (IPX, Bridging, SCSI, etc.)

    == Don't forget to compile in support for hardware that you might need:
    ==   SCSI controllers, HDs, CDROMs, etc.


[ Network device support ]

  * Network device support (CONFIG_NETDEVICES) [Y/n/?]
    - YES: Enables the Linux Network device sublayer 


  == Non-MASQ options skipped
  ==   (Dummy, EQL, PPP, SLIP, NICs, Wireless, etc.) 

    == Don't forget to compile in support for hardware that you might need:
    ==   NICs:   eth, tr, etc.
    ==   MODEMs: ppp and/or slip
    ==   WANs:   T1, T3, ISDN, etc.
    ==   ISDN:   for internal ISDN modems


[ File systems ]

  == Non-MASQ options skipped
  ==   (Quota, ISO9660, Codepages, NTFS, etc )


  * /proc filesystem support (CONFIG_PROC_FS) [Y/n/?]
    - YES:  Required to dynamically configure the Linux forwarding 
            and NATing systems
  

 [ Character devices ]

  == Non-MASQ options skipped
  ==   (multi-port serial, parallel, mice, Ftape, Sound, etc. )

    == Don't forget to compile in serial port support for modem users
    == Don't forget to compile in mouse support

因此,继续 “exit”,您应该会看到保存配置的提示。

注意:这些只是 IP Masquerade 功能的组件。您可能还需要选择其他选项以匹配您的特定网络和硬件设置。

  • 现在编译内核(make dep; make clean; make bzImage; make modules; make modules_install)等等。同样,如果您在编译内核时遇到问题,则超出了本 HOWTO 的范围。有关 KERNEL howto 等的 URL,请参阅第 2.8 节

  • 然后,您需要移动内核二进制文件,更新引导加载程序(LILO、Grub 等),并重新启动。如果您对内核编译有疑问,我强烈建议您查阅本节中的一些 URL。


3.3. 为内部 LAN 分配私有网络 IP 地址

由于所有内部 MASQed 机器都不应具有官方分配的 Internet 地址,因此必须有一种特定且公认的方式为这些机器分配地址,而不会与任何其他人的 Internet 地址冲突。

来自原始 IP Masquerade FAQ

RFC 1918 是关于在未连接或 “私有” 网络中使用哪些 IP 地址的官方文档。其中有 3 个数字块专门为此目的而预留。

Section 3: Private Address Space

The Internet Assigned Numbers Authority (IANA) has reserved the
following three blocks of the IP address space for private networks:

              10.0.0.0        -   10.255.255.255
              172.16.0.0      -   172.31.255.255
              192.168.0.0     -   192.168.255.255

We will refer to the first block as "24-bit block", the second as "20-bit 
block", and the third as "16-bit" block".  Note that the first block is 
nothing but a single class A network number, while the second block is a set 
of 16 continuous class B network numbers, and the third block is a set of 255 
continuous class C network numbers.

为了记录,我个人偏好使用 192.168.0.0 网络和 255.255.255.0 C 类子网掩码,因此本 HOWTO 反映了这一点。上述任何私有网络都是有效的,但请务必使用正确的子网掩码。

因此,如果您使用的是 C 类网络,则应将启用 TCP/IP 的机器编号为 192.168.0.1、192.168.0.2、192.168.0.3、...、192.168.0.x

192.168.0.1 通常设置为内部网关或 Linux MASQ 机器,用于连接外部网络。请注意,192.168.0.0 和 192.168.0.255 分别是网络地址和广播地址(这些地址是保留地址)。避免在您的机器上使用这些地址,否则您的网络将无法正常运行。


3.4. 配置 IP 转发策略

此时,您应该已经安装了内核和其他必需的软件包。所有网络 IP 地址、网关和 DNS 地址都应在您的 Linux MASQ 服务器上配置。如果您不知道如何配置 Linux 网卡,请查阅 2.4.x 第 2.6 节、2.2.x 第 2.7 节 或 2.0.x 第 2.8 节 中列出的 HOWTO。

现在,剩下要做的唯一事情是配置 IP 防火墙工具,以便将适当的数据包转发和伪装到正确的机器。

** 本节仅向用户提供使 IP Masquerading 工作所需的最低防火墙规则集。

一旦成功测试了 IP MASQ(如本 HOWTO 后续所述),请参阅 第 6.4.1 节中适用于 2.4.x 内核的更强大的 IPTABLES 规则集、第 6.4.2 节中适用于 2.2.x 内核的更强大的 IPCHAINS 规则集以及 第 6.4.3 节中适用于 2.0.x 内核的更强大的 IPFWADM 规则集。请注意,这些更强大的防火墙规则集更多的是模板而不是其他任何东西。对于真正安全的防火墙规则集,请查看 HOWTO 的需求部分(2.4.x - 第 2.6 节,2.2.x - 第 2.7 节,2.0.x - 第 2.8 节)。

与其手动键入其中一个文件,我建议您直接浏览示例目录下载所有这些 rc.firewall-* 文件的存档


3.4.1. 在 Linux 2.6.x 和 2.4.x 内核上配置 IP Masquerade

请注意,对于 2.6.x 和 2.4.x 内核,IPCHAINS 不再是主要的防火墙配置工具。新内核现在使用 IPTABLES 工具包,尽管新的 2.4.x 内核仍然可以通过兼容性模块运行大多数旧的 IPCHAINS 或 IPFWADM 规则集。还应注意,当在兼容性模式下运行时,无法加载任何 IPTABLES 模块。原因是 2.2.x IPMASQ 模块与 2.4.x 内核不兼容。有关这些更改的更多详细信息,请参阅 第 7.40 节

好的,如前所述,/etc/rc.d/rc.local-*脚本可以在每次重启后加载一次。加载脚本的机制因不同的 Linux 发行版而异(请参阅下面的示例)。rc.firewall-iptables 脚本将加载所有必需的 IPMASQ 模块,并启用最终的 IPMASQ 功能。对于高级设置,此文件也将包含非常安全的防火墙规则集。

无论如何,使用以下初始简单规则集创建文件 /etc/rc.d/rc.firewall-iptables

<rc.firewall-iptables START>

#!/bin/sh
#
# rc.firewall-iptables
FWVER=0.76
#
#               Initial SIMPLE IP Masquerade test for 2.6 / 2.4 kernels
#               using IPTABLES.  
#
#               Once IP Masquerading has been tested, with this simple 
#               ruleset, it is highly recommended to use a stronger 
#               IPTABLES ruleset either given later in this HOWTO or 
#               from another reputable resource.
#
#
#
# Log:
#       0.76 - Added comments on why the default policy is ACCEPT
#       0.75 - Added more kernel modules to the comments section
#       0.74 - the ruleset now uses modprobe vs. insmod
#       0.73 - REJECT is not a legal policy yet; back to DROP
#       0.72 - Changed the default block behavior to REJECT not DROP
#       0.71 - Added clarification that PPPoE users need to use
#              "ppp0" instead of "eth0" for their external interface
#       0.70 - Added commented option for IRC nat module
#            - Added additional use of environment variables 
#            - Added additional formatting
#       0.63 - Added support for the IRC IPTABLES module
#       0.62 - Fixed a typo on the MASQ enable line that used eth0
#              instead of $EXTIF
#       0.61 - Changed the firewall to use variables for the internal
#              and external interfaces.
#       0.60 - 0.50 had a mistake where the ruleset had a rule to DROP
#              all forwarded packets but it didn't have a rule to ACCEPT
#              any packets to be forwarded either
#            - Load the ip_nat_ftp and ip_conntrack_ftp modules by default
#       0.50 - Initial draft
#

echo -e "\n\nLoading simple rc.firewall-iptables version $FWVER..\n"


# The location of the iptables and kernel module programs
#
#   If your Linux distribution came with a copy of iptables, 
#   most likely all the programs will be located in /sbin.  If 
#   you manually compiled iptables, the default location will
#   be in /usr/local/sbin
#
# ** Please use the "whereis iptables" command to figure out 
# ** where your copy is and change the path below to reflect 
# ** your setup
#
#IPTABLES=/sbin/iptables
IPTABLES=/usr/local/sbin/iptables
DEPMOD=/sbin/depmod
MODPROBE=/sbin/modprobe


#Setting the EXTERNAL and INTERNAL interfaces for the network
#
#  Each IP Masquerade network needs to have at least one
#  external and one internal network.  The external network
#  is where the natting will occur and the internal network
#  should preferably be addressed with a RFC1918 private address
#  scheme.
#
#  For this example, "eth0" is external and "eth1" is internal"
#
#
#  NOTE:  If this doesnt EXACTLY fit your configuration, you must 
#         change the EXTIF or INTIF variables above. For example: 
#
#            If you are a PPPoE or analog modem user:
#
#               EXTIF="ppp0" 
#
#
EXTIF="eth0"
INTIF="eth1"
echo "   External Interface:  $EXTIF"
echo "   Internal Interface:  $INTIF"


#======================================================================
#== No editing beyond this line is required for initial MASQ testing ==


echo -en "   loading modules: "

# Need to verify that all modules have all required dependencies
#
echo "  - Verifying that all kernel modules are ok"
$DEPMOD -a

# With the new IPTABLES code, the core MASQ functionality is now either
# modular or compiled into the kernel.  This HOWTO shows ALL IPTABLES
# options as MODULES.  If your kernel is compiled correctly, there is
# NO need to load the kernel modules manually.  
#
#  NOTE: The following items are listed ONLY for informational reasons.
#        There is no reason to manual load these modules unless your
#        kernel is either mis-configured or you intentionally disabled
#        the kernel module autoloader.
#

# Upon the commands of starting up IP Masq on the server, the
# following kernel modules will be automatically loaded:
#
# NOTE:  Only load the IP MASQ modules you need.  All current IP MASQ 
#        modules are shown below but are commented out from loading.
# ===============================================================

echo "----------------------------------------------------------------------"

#Load the main body of the IPTABLES module - "iptable"
#  - Loaded automatically when the "iptables" command is invoked
#
#  - Loaded manually to clean up kernel auto-loading timing issues
#
echo -en "ip_tables, "
$MODPROBE ip_tables


#Load the IPTABLES filtering module - "iptable_filter" 
#  - Loaded automatically when filter policies are activated


#Load the stateful connection tracking framework - "ip_conntrack"
#
# The conntrack  module in itself does nothing without other specific 
# conntrack modules being loaded afterwards such as the "ip_conntrack_ftp"
# module
#
#  - This module is loaded automatically when MASQ functionality is 
#    enabled 
#
#  - Loaded manually to clean up kernel auto-loading timing issues
#
echo -en "ip_conntrack, "
$MODPROBE ip_conntrack


#Load the FTP tracking mechanism for full FTP tracking
#
# Enabled by default -- insert a "#" on the next line to deactivate
#
echo -en "ip_conntrack_ftp, "
$MODPROBE ip_conntrack_ftp


#Load the IRC tracking mechanism for full IRC tracking
#
# Enabled by default -- insert a "#" on the next line to deactivate
#
echo -en "ip_conntrack_irc, "
$MODPROBE ip_conntrack_irc


#Load the general IPTABLES NAT code - "iptable_nat"
#  - Loaded automatically when MASQ functionality is turned on
# 
#  - Loaded manually to clean up kernel auto-loading timing issues
#
echo -en "iptable_nat, "
$MODPROBE iptable_nat


#Loads the FTP NAT functionality into the core IPTABLES code
# Required to support non-PASV FTP.
#
# Enabled by default -- insert a "#" on the next line to deactivate
#
echo -en "ip_nat_ftp, "
$MODPROBE ip_nat_ftp


#Loads the IRC NAT functionality into the core IPTABLES code
# Required to support NAT of IRC DCC requests
#
# Disabled by default -- remove the "#" on the next line to activate
#
#echo -e "ip_nat_irc"
#$MODPROBE ip_nat_irc

echo "----------------------------------------------------------------------"

# Just to be complete, here is a partial list of some of the other  
# IPTABLES kernel modules and their function.  Please note that most 
# of these modules (the ipt ones) are automatically loaded by the 
# master kernel module for proper operation and don't need to be 
# manually loaded.
# --------------------------------------------------------------------
#
#    ip_nat_snmp_basic - this module allows for proper NATing of some 
#                        SNMP traffic
#
#    iptable_mangle    - this target allows for packets to be 
#                        manipulated for things like the TCPMSS 
#                        option, etc.
#
# --
#
#    ipt_mark       - this target marks a given packet for future action.
#                     This automatically loads the ipt_MARK module
#
#    ipt_tcpmss     - this target allows to manipulate the TCP MSS
#                     option for braindead remote firewalls.
#                     This automatically loads the ipt_TCPMSS module
#
#    ipt_limit      - this target allows for packets to be limited to
#                     to many hits per sec/min/hr
#
#    ipt_multiport  - this match allows for targets within a range
#                     of port numbers vs. listing each port individually
#
#    ipt_state      - this match allows to catch packets with various
#                     IP and TCP flags set/unset
#
#    ipt_unclean    - this match allows to catch packets that have invalid
#                     IP/TCP flags set
#
#    iptable_filter - this module allows for packets to be DROPped, 
#                     REJECTed, or LOGged.  This module automatically 
#                     loads the following modules:
#
#                     ipt_LOG - this target allows for packets to be 
#                               logged
#
#                     ipt_REJECT - this target DROPs the packet and returns 
#                                  a configurable ICMP packet back to the 
#                                  sender.
# 

echo -e "   Done loading modules.\n"



#CRITICAL:  Enable IP forwarding since it is disabled by default since
#
#           Redhat Users:  you may try changing the options in
#                          /etc/sysconfig/network from:
#
#                       FORWARD_IPV4=false
#                             to
#                       FORWARD_IPV4=true
#
echo "   Enabling forwarding.."
echo "1" > /proc/sys/net/ipv4/ip_forward


# Dynamic IP users:
#
#   If you get your IP address dynamically from SLIP, PPP, or DHCP, 
#   enable this following option.  This enables dynamic-address hacking
#   which makes the life with Diald and similar programs much easier.
#
echo "   Enabling DynamicAddr.."
echo "1" > /proc/sys/net/ipv4/ip_dynaddr


# Enable simple IP forwarding and Masquerading
#
#  NOTE:  In IPTABLES speak, IP Masquerading is a form of SourceNAT or SNAT.
#
#  NOTE #2:  The following is an example for an internal LAN address in the
#            192.168.0.x network with a 255.255.255.0 or a "24" bit subnet mask
#            connecting to the Internet on external interface "eth0".  This
#            example will MASQ internal traffic out to the Internet but not
#            allow non-initiated traffic into your internal network.
#
#            
#         ** Please change the above network numbers, subnet mask, and your 
#         *** Internet connection interface name to match your setup
#         


#Clearing any previous configuration
#
#  Unless specified, the defaults for INPUT and OUTPUT is ACCEPT
#    The default for FORWARD is DROP (REJECT is not a valid policy)
#
#   Isn't ACCEPT insecure?  To some degree, YES, but this is our testing
#   phase.  Once we know that IPMASQ is working well, I recommend you run
#   the rc.firewall-*-stronger rulesets which set the defaults to DROP but
#   also include the critical additional rulesets to still let you connect to
#   the IPMASQ server, etc.
#
echo "   Clearing any existing rules and setting default policy.."
$IPTABLES -P INPUT ACCEPT
$IPTABLES -F INPUT 
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -F OUTPUT 
$IPTABLES -P FORWARD DROP
$IPTABLES -F FORWARD 
$IPTABLES -t nat -F

echo "   FWD: Allow all connections OUT and only existing and related ones IN"
$IPTABLES -A FORWARD -i $EXTIF -o $INTIF -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A FORWARD -i $INTIF -o $EXTIF -j ACCEPT
$IPTABLES -A FORWARD -j LOG

echo "   Enabling SNAT (MASQUERADE) functionality on $EXTIF"
$IPTABLES -t nat -A POSTROUTING -o $EXTIF -j MASQUERADE

echo -e "\nrc.firewall-iptables v$FWVER done.\n"
<rc.firewall-iptables STOP>

完成编辑此 /etc/rc.d/rc.firewall-iptables 规则集后,通过键入以下命令使其可执行chmod 700 /etc/rc.d/rc.firewall-iptables

现在防火墙规则集已准备就绪,您需要使其在每次重启后运行。您可以手动每次运行它(这很麻烦)或将其添加到启动脚本中。我们在下面介绍了两种方法:Redhat(Sys-V 样式)和 Slackware(BSD 样式)

1. Redhat 和 Redhat 衍生发行版

  • 在 Redhat 中自动加载内容有两种方法:/etc/rc.d/rc.local 或 /etc/rc.d/init.d/ 中的 init 脚本。第一种方法最简单,但不是 Sys-V 的方式。您只需添加以下行

    echo "Loading the rc.firewall-iptables ruleset.. "
    /etc/rc.d/rc.firewall-iptables

    到 /etc/rc.d/rc.local 文件的末尾即可(如本 HOWTO 前面所述)。

    此方法的缺点是防火墙直到启动的最后阶段才执行。

  • 首选方法是在网络子系统加载后立即加载防火墙。为此,请将以下文件复制到 /etc/rc.d/init.d 目录

    <firewall-iptables START>

    #!/bin/sh
    #
    # chkconfig: 2345 11 89
    #
    # description: Loads the rc.firewall-iptables ruleset.
    #
    # processname: firewall-iptables
    # pidfile: /var/run/firewall.pid
    # config: /etc/rc.d/rc.firewall-iptables
    # probe: true
    
    # ----------------------------------------------------------------------------
    # v05/24/03
    #
    # Part of the copyrighted and trademarked TrinityOS document.
    # http://www.ecst.csuchico.edu/~dranch
    #
    # Written and Maintained by David A. Ranch
    # dranch@trinnet.net
    #
    # Updates
    # -------
    # 05/24/03 - removed a old networking up check that had some
    #            improper SGML ampersand conversions.
    # ----------------------------------------------------------------------------
    
    
    # Source function library.
    . /etc/rc.d/init.d/functions
    
    # Check that networking is up.
    
    [ "XXXX${NETWORKING}" = "XXXXno" ] && exit 0
    
    [ -x /sbin/ifconfig ] || exit 0
    
    # The location of various iptables and other shell programs
    #
    #   If your Linux distribution came with a copy of iptables, most
    #   likely it is located in /sbin.  If you manually compiled
    #   iptables, the default location is in /usr/local/sbin
    #
    # ** Please use the "whereis iptables" command to figure out
    # ** where your copy is and change the path below to reflect
    # ** your setup
    #
    IPTABLES=/usr/local/sbin/iptables
    
    
    # See how we were called.
    case "$1" in
      start)
        /etc/rc.d/rc.firewall-iptables
        ;;
    
      stop)
        echo -e "\nFlushing firewall and setting default policies to DROP\n"
        $IPTABLES -P INPUT DROP
        $IPTABLES -F INPUT
        $IPTABLES -P OUTPUT DROP
        $IPTABLES -F OUTPUT
        $IPTABLES -P FORWARD DROP
        $IPTABLES -F FORWARD
        $IPTABLES -F -t nat
    
        # Delete all User-specified chains
        $IPTABLES -X
        #
        # Reset all IPTABLES counters
        $IPTABLES -Z
        ;;
    
      restart)
            $0 stop
            $0 start
            ;;
    
      status)
            $IPTABLES -L
            ;;
    
      mlist)
        cat /proc/net/ip_conntrack
        ;;
    
      *)
            echo "Usage: firewall-iptables {start|stop|status|mlist}"
            exit 1
    esac
    
    exit 0
    <firewall-iptables STOP>

    有了这个脚本,您现在需要做的就是使其可执行,然后使其在重启时加载。首先,通过运行以下命令使其可执行

    #Redhat-style
    #
    chmod 700 /etc/rc.d/init.d/firewall-iptables
    现在,启用在重启时加载规则集
    #Redhat style
    #
    /sbin/chkconfig --level=345 firewall-iptables on
    就是这样!现在重启后,防火墙将自动加载。为了确保这一点,运行以下命令以查看防火墙是否应在重启时启动
    #Redhat style
    #
    chkconfig --list firewall-iptables
    
    #The output should look like:
    #
    firewall-iptables 0:off 1:off 2:off 3:on 4:on 5:on 6:off

2. Slackware

  • 在 Slackware 中加载内容有两种方法:/etc/rc.d/rc.local 或编辑 /etc/rc.d/rc.inet2 文件。第一种方法最简单,但不是最安全的(见下文)。您只需将以下行附加到 /etc/rc.d/rc.local 文件

    echo "Loading the rc.firewall-iptables ruleset.."
     
    /etc/rc.d/rc.firewall-iptables

    此方法的缺点是,如果您运行的是强大的防火墙规则集,则防火墙直到启动的最后阶段才执行。首选方法是在网络子系统加载后立即加载防火墙。目前,本 HOWTO 仅介绍如何使用 /etc/rc.d/rc.local 执行此操作,但如果您知道自己在做什么(这很容易),请继续修改 inet2 启动脚本以在网络启动后立即加载 /etc/rc.d/rc.firewall-iptables 文件。如果您想要更详细的指南和/或更强大的防火墙规则集,我建议您查看本 HOWTO 底部链接部分中 TrinityOS 的第 10 节。

关于用户可能希望如何更改上述防火墙规则集的说明

您还可以基于每台机器启用 IP Masquerading,而不是上述方法,后者是启用整个 TCP/IP 网络。例如,假设我只想让 192.168.0.2 和 192.168.0.8 主机访问 Internet,而不是任何其他内部机器。我将更改 /etc/rc.d/rc.firewall-iptables 规则集的 “启用简单 IP 转发和 Masquerading” 部分(如上所示)中的内容。

#!/bin/sh
#
# Partial IPTABLES config to enable simple IP forwarding and Masquerading
# v0.61
#
#  NOTE:  The following is an example to allow only IP Masquerading for the 
#         192.168.0.2 and 192.168.0.8 machines with a 255.255.255.0 or a 
#         "/24" subnet mask connecting to the Internet on interface eth0.
#
#         ** Please change the network number, subnet mask, and the Internet
#         ** connection interface name to match your internal LAN setup
#
echo "  - Setting the default FORWARD policy to DROP"
$IPTABLES -P FORWARD DROP

echo "  - Enabling SNAT (IPMASQ) functionality on $EXTIF"
$IPTABLES -t nat -A POSTROUTING -o $EXTIF -s 192.168.0.2/32 -j MASQUERADE
$IPTABLES -t nat -A POSTROUTING -o $EXTIF -s 192.168.0.8/32 -j MASQUERADE

echo "  - Setting the FORWARD policy to 'DROP' all incoming / unrelated traffic"
$IPTABLES -A INPUT -i $EXTIF -m state --state NEW,INVALID -j DROP
$IPTABLES -A FORWARD -i $EXTIF -m state --state NEW,INVALID -j DROP

常见错误

对于新的 IP Masq 用户来说,一个常见的错误似乎是将第一个命令简单地设置为以下内容

IPTABLES:
---------
iptables -t nat -A POSTROUTING -j MASQUERADE

不要将您的默认策略设置为 MASQUERADING。否则,有人可以操纵他们的路由表以直接隧道返回到您的网关,并使用它来伪装他们自己的身份!

同样,您可以将这些行添加到/etc/rc.d/rc.firewall-iptables文件、您喜欢的其他 rc 文件之一,或者在每次需要 IP Masquerade 时手动执行。

有关强大的 IPTABLES 规则集示例的详细指南,请参阅第 6.4.1 节。有关 IPTABLES 用法的更多详细信息,请参阅主要 IPTABLES 站点 http://www.netfilter.org/


3.4.2. 在 Linux 2.2.x 内核上配置 IP Masquerade

请注意,对于 2.1.x 和 2.2.x 内核,IPFWADM 不再是用于操作 IP Masquerading 规则的防火墙工具。这些新内核现在使用 IPCHAINS 工具包。有关此更改的更详细原因,请参阅 第 7 章

使用以下初始简单规则集创建文件 /etc/rc.d/rc.firewall-ipchains

<rc.firewall-ipchains START>

#!/bin/sh
#
# rc.firewall-ipchains
#
#     - Initial SIMPLE IP Masquerade test for 2.1.x and 2.2.x kernels 
#       using IPCHAINS.
#
#       Once IP Masquerading has been tested, with this simple 
#       ruleset, it is highly recommended to use a stronger 
#       IPTABLES ruleset either given later in this HOWTO or 
#       from another reputable resource.

FWVER="1.23"
#
# 1.23 - Added comments on why the default policy is ACCEPT
# 1.22 - ruleset now uses modprobe instead of insmod
# 1.21 - Added clarification that PPPoE users need to use
#        "ppp0" instead of "eth0" for their external interface
# 1.20 - Updated the script to use environment vars
# 1.01 - Original version


echo -e "\n\nLoading simple rc.firewall-ipchains : version $FWVER..\n"


# The location of the ipchains and kernel module programs
#
#   If your Linux distribution came with a copy of ipchains, 
#   most likely all the programs will be located in /sbin.  If 
#   you manually compiled ipchains, the default location will
#   be in /usr/local/sbin
#
# ** Please use the "whereis ipchains" command to figure out 
# ** where your copy is and change the path below to reflect 
# ** your setup
#
IPCHAINS=/sbin/ipchains
#IPTABLES=/usr/local/sbin/ipchains
DEPMOD=/sbin/depmod
MODPROBE=/sbin/modprobe


#Setting the EXTERNAL and INTERNAL interfaces for the network
#
#  Each IP Masquerade network needs to have at least one
#  external and one internal network.  The external network
#  is where the NATing will occur and the internal network
#  should preferably be addressed with a RFC1918 private addressing
#  scheme.
#
#  For this example, "eth0" is external and "eth1" is internal"
#
#  NOTE:  If this doesnt EXACTLY fit your configuration, you must
#         change the EXTIF or INTIF variables above. For example:
#
#            If you are a PPPoE or analog modem user:
#
#               EXTIF="ppp0" 
#
#  ** Please change this to reflect your specific configuration **
#
EXTIF="eth0"
INTIF="eth1"
echo "   External Interface:  $EXTIF"
echo "   Internal Interface:  $INTIF"


# Network Address of the Internal Network
#
#   This example rc.firewall-ipchains file uses the 192.168.0.0 network
#   with a /24 or 255.255.255.0 netmask.
#
#    ** Change this variable to reflect your specific setup **
#
INTLAN="192.168.0.0/24"
echo -e "   Internal Interface:  $INTLAN\n"



# Load all required IP MASQ modules
#
#   NOTE:  Only load the IP MASQ modules you need.  All current IP MASQ modules
#          are shown below but are commented out from loading.
echo "   loading required IPMASQ kernel modules.."

# Needed to initially load modules
#
$DEPMOD -a

echo -en "   Loading modules: "

# Supports the proper masquerading of FTP file transfers using the PORT method
#
echo -en "FTP, "
$MODPROBE ip_masq_ftp

# Supports the masquerading of RealAudio over UDP.  Without this module,
#       RealAudio WILL function but in TCP mode.  This can cause a reduction
#       in sound quality
#
#echo -en "RealAudio, "
$MODPROBE ip_masq_raudio

# Supports the masquerading of IRC DCC file transfers
#
#echo -en "Irc, "
#$MODPROBE ip_masq_irc


# Supports the masquerading of Quake and QuakeWorld by default.  This modules is
#   for for multiple users behind the Linux MASQ server.  If you are going to 
#   play Quake I, II, and III, use the second example.
#
#   NOTE:  If you get ERRORs loading the QUAKE module, you are running an old
#   -----  kernel that has bugs in it.  Please upgrade to the newest kernel.
#
#echo -en "Quake, "
#Quake I / QuakeWorld (ports 26000 and 27000)
#$MODPROBE ip_masq_quake
#
#Quake I/II/III / QuakeWorld (ports 26000, 27000, 27910, 27960)
#$MODPROBE ip_masq_quake 26000,27000,27910,27960


# Supports the masquerading of the CuSeeme video conferencing software
#
#echo -en "CuSeeme, "
#$MODPROBE ip_masq_cuseeme

#Supports the masquerading of the VDO-live video conferencing software
#
#echo -en "VdoLive "
#$MODPROBE ip_masq_vdolive

echo ".  Done loading modules."


#CRITICAL:  Enable IP forwarding since it is disabled by default since
#
#           Redhat Users:  you may try changing the options in 
#                          /etc/sysconfig/network from:
#
#                       FORWARD_IPV4=false
#                             to
#                       FORWARD_IPV4=true
#
echo "   enabling forwarding.."
echo "1" > /proc/sys/net/ipv4/ip_forward


#CRITICAL:  Enable automatic IP defragmenting since it is disabled by default 
#           in 2.2.x kernels.  This used to be a compile-time option but the 
#           behavior was changed in 2.2.12
#
echo "   enabling AlwaysDefrag.."
echo "1" > /proc/sys/net/ipv4/ip_always_defrag


# Dynamic IP users:
#
#   If you get your IP address dynamically from SLIP, PPP, or DHCP, enable this 
#   following option.  This enables dynamic-ip address hacking in IP MASQ, 
#   making the life with Diald and similar programs much easier.
#
#echo "   enabling DynamicAddr.."
#echo "1" > /proc/sys/net/ipv4/ip_dynaddr


# Enable the LooseUDP patch which some Internet-based games require
#
#  If you are trying to get an Internet game to work through your IP MASQ box,
#  and you have set it up to the best of your ability without it working, try
#  enabling this option (delete the "#" character).  This option is disabled
#  by default due to possible internal machine UDP port scanning 
#  vulnerabilities.
#
#echo "   enabling LooseUDP.."
#echo "1" > /proc/sys/net/ipv4/ip_masq_udp_dloose


#Clearing any previous configuration
#
#  Unless specified, the defaults for INPUT and OUTPUT is ACCEPT
#    The default for FORWARD is REJECT
#
#   Isn't ACCEPT insecure?  To some degree, YES, but this is our testing
#   phase.  Once we know that IPMASQ is working well, I recommend you run
#   the rc.firewall-*-stronger rulesets which set the defaults to DROP but
#   also include the critical additional rulesets to still let you connect to
#   the IPMASQ server, etc.
#
echo "   clearing any existing rules and setting default policy.."
$IPCHAINS -P input ACCEPT
$IPCHAINS -P output ACCEPT
$IPCHAINS -P forward REJECT
$IPCHAINS -F input
$IPCHAINS -F output
$IPCHAINS -F forward


# MASQ timeouts
#
#   2 hrs timeout for TCP session timeouts
#  10 sec timeout for traffic after the TCP/IP "FIN" packet is received
#  160 sec timeout for UDP traffic (Important for MASQ'ed ICQ users) 
#
echo "   setting default timers.."
$IPCHAINS -M -S 7200 10 160


# DHCP:  For people who receive their external IP address from either DHCP or 
#        BOOTP for connctions such as DSL or Cablemodem users, it is necessary 
#        to use the following before the deny command.  
#
#        This example is currently commented out.
#
#
#$IPCHAINS -A input -j ACCEPT -i $EXTIF -s 0/0 67 -d 0/0 68 -p udp

# Enable simple IP forwarding and Masquerading
#
#  NOTE:  The following is an example for an internal LAN address in the 
#         192.168.0.x network with a 255.255.255.0 or a "24" bit subnet mask
#         connecting to the Internet on interface eth0.
#
#         ** Please change this network number, subnet mask, and your Internet
#         ** connection interface name to match your internal LAN setup
#
echo "   enabling IPMASQ functionality on $EXTIF"
$IPCHAINS -P forward DENY
$IPCHAINS -A forward -i $EXTIF -s $INTLAN -j MASQ

echo -e "\nrc.firewall-ipchains v$FWVER done.\n"
<rc.firewall-ipchains STOP>

完成编辑 /etc/rc.d/rc.firewall-ipchains 规则集后,通过键入以下命令使其可执行chmod 700 /etc/rc.d/rc.firewall-ipchains

现在防火墙规则集已准备就绪,您需要使其在每次重启后运行。您可以手动每次运行它(这很麻烦)或将其添加到启动脚本中。我们在下面介绍了两种方法:Redhat(Sys-V 样式)和 Slackware(BSD 样式)

1. Redhat 和 Redhat 衍生发行版

  • 在 Redhat 中自动加载内容有两种方法:/etc/rc.d/rc.local 或 /etc/rc.d/init.d/ 中的 init 脚本。第一种方法最简单,但不是 Sys-V 的方式。您只需添加以下行

    echo "Loading the rc.firewall ruleset.."
    /etc/rc.d/rc.firewall-ipchains

    到 /etc/rc.d/rc.local 文件的末尾即可(如本 HOWTO 前面所述)。

    此方法的缺点是防火墙直到启动的最后阶段才执行。首选方法是在网络子系统加载后立即加载防火墙。为此,请将以下文件复制到 /etc/rc.d/init.d 目录

    <firewall-ipchains START>

    #!/bin/sh
    #
    # chkconfig: 2345 11 89
    #
    # description: Loads the rc.firewall-ipchains ruleset.
    #
    # processname: firewall-ipchains
    # pidfile: /var/run/firewall.pid
    # config: /etc/rc.d/rc.firewall-ipchains
    # probe: true
    
    # ----------------------------------------------------------------------------
    # v08/29/02
    #
    # Part of the copyrighted and trademarked TrinityOS document.
    # http://www.ecst.csuchico.edu/~dranch
    #
    # Written and Maintained by David A. Ranch
    # dranch@trinnet.net
    #
    # Updates
    # -------
    #
    # ----------------------------------------------------------------------------
    
    
    # Source function library.
    . /etc/rc.d/init.d/functions
    
    # Check that networking is up.
    
    # This line no longer work with bash2
    #[ ${NETWORKING} = "no" ] && exit 0
    # This should be OK. 
    [ "XXXX${NETWORKING}" = "XXXXno" ] && exit 0
    
    [ -x /sbin/ifconfig ] || exit 0
    
    # The location of various iptables and other shell programs
    #
    #   If your Linux distribution came with a copy of iptables, most
    #   likely it is located in /sbin.  If you manually compiled
    #   iptables, the default location is in /usr/local/sbin
    #
    # ** Please use the "whereis iptables" command to figure out
    # ** where your copy is and change the path below to reflect
    # ** your setup
    #
    IPCHAINS=/sbin/ipchains
    
    
    # See how we were called.
    case "$1" in
      start)
        /etc/rc.d/rc.firewall-ipchains
        ;;
    
      stop)
        echo -e "\nFlushing firewall and setting default policies to REJECT\n"
    
        $IPCHAINS -P input REJECT
        $IPCHAINS -P output REJECT
        $IPCHAINS -P forward REJECT
    
        $IPCHAINS -F input
        $IPCHAINS -F output
        $IPCHAINS -F forward
        ;;
    
      restart)
        $0 stop
        $0 start
        ;;
    
      status)
        $IPCHAINS -L
        ;;
    
      mlist)
        $IPCHAINS -M -L
        ;;
    
      *)
        echo "Usage: firewall-ipchains {start|stop|status|mlist}"
        exit 1
    esac
    
    exit 0
    <firewall-ipchains STOP>

    有了这个脚本,您现在需要做的就是使其可执行,然后使其在重启时加载。首先,通过运行以下命令使其可执行

    #Redhat-style
    #
    chmod 700 /etc/rc.d/init.d/firewall-ipchains
    现在,使规则集在重启时加载
    #Redhat style
    #
    chkconfig --level=345 firewall-ipchains on
    就是这样!现在启动后,防火墙将自动加载。为了确保这一点,运行命令以查看防火墙是否应在重启时启动
    #Redhat style
    #
    chkconfig --list firewall-ipchains
    
    #The output should look like:
    #
    firewall-ipchains 0:off 1:off 2:off 3:on 4:on 5:on 6:off

2. Slackware

  • 在 Slackware 中加载内容有两种方法:/etc/rc.d/rc.local 或编辑 /etc/rc.d/rc.inet2 文件。第一种方法最简单,但不是最安全的(见下文)。您只需将以下行附加到 /etc/rc.d/rc.local 文件

    echo "Loading the rc.firewall-ipchains ruleset.."
    /etc/rc.d/rc.firewall-ipchains

    此方法的缺点是,如果您运行的是强大的防火墙规则集,则防火墙直到启动的最后阶段才执行。首选方法是在网络子系统加载后立即加载防火墙。目前,本 HOWTO 仅介绍如何使用 /etc/rc.d/rc.local 执行此操作,但如果您知道自己在做什么(这很容易),请继续修改 inet2 启动脚本以在网络启动后立即加载 /etc/rc.d/rc.firewall-ipchains 文件。如果您想要更详细的指南和/或更强大的防火墙规则集,我建议您查看本 HOWTO 底部链接部分中 TrinityOS 的第 10 节。

关于用户可能希望如何更改上述防火墙规则集的说明

您还可以基于每台机器启用 IP Masquerading,而不是上述方法,后者是启用整个 TCP/IP 网络。例如,假设我只想让 192.168.0.2 和 192.168.0.8 主机访问 Internet,而不是任何其他内部机器。我将更改 /etc/rc.d/rc.firewall-ipchains 规则集的 “启用简单 IP 转发和 Masquerading” 部分(如上所示)中的内容。

#!/bin/sh
#
# Enable simple IP forwarding and Masquerading
# v1.01
#
#  NOTE:  The following is an example used in addition to the simple 
#         IPCHAINS ruleset anove to allow only IP Masquerading for the 
#         192.168.0.2 and 192.168.0.8 machines with a 255.255.255.0 or a 
#         "24" bit subnet mask connecting to the Internet on interface $EXTIF.
#
#         ** Please change the network number, subnet mask, and the Internet
#         ** connection interface name to match your internal LAN setup
#
$IPCHAINS -P forward DENY
$IPCHAINS -A forward -i $EXTIF -s 192.168.0.2/32 -j MASQ
$IPCHAINS -A forward -i $EXTIF -s 192.168.0.8/32 -j MASQ

常见错误

对于新的 IP MASQ 用户来说,一个常见的错误似乎是将第一个命令设置为

$IPCHAINS -P forward masquerade

不要将您的默认策略设置为 MASQUERADING。否则,有人可以操纵他们的路由表以直接隧道返回到您的网关,并使用它来伪装他们自己的身份!

同样,您可以将这些行添加到/etc/rc.d/rc.firewall-ipchains文件、您喜欢的其他 rc 文件之一,或者在每次需要 IP Masquerade 时手动执行。

有关 IPCHAINS 和强大的 IPCHAINS 规则集示例的详细指南,请参阅第 6.4.2 节。有关 IPCHAINS 用法的更多详细信息,请参阅主要 IPCHAINS 站点 http://www.netfilter.org/ipchains/Linux IP CHAINS HOWTO 备份站点


3.4.3. 在 Linux 2.0.x 内核上配置 IP Masquerade

使用以下初始简单规则集创建文件 /etc/rc.d/rc.firewall-ipfwadm:<rc.firewall-ipfwadm START>

#!/bin/sh
#
# rc.firewall-ipfwadm
#
#  A Initial SIMPLE IP Masquerade setup for 2.0.x kernels using IPFWADM
#
FWVER="2.03"
# 
# 2.03 - Added comments on why the default policy is ACCEPT
# 2.02 - Added clarification that PPPoE users need to use
#        "ppp0" instead of "eth0" for their external interface
#
#
#        Once IP Masquerading has been tested, with this simple 
#        ruleset, it is highly recommended to use a stronger 
#        IPTABLES ruleset either given later in this HOWTO or 
#        from another reputable resource.
#
echo -e "\n\nLoading simple rc.firewall-ipfwadm version $FWVER..\n"


#Setting the EXTERNAL and INTERNAL interfaces for the network
#
#  Each IP Masquerade network needs to have at least one
#  external and one internal network.  The external network
#  is where the NATing will occur and the internal network
#  should preferably be addressed with a RFC1918 private addressing
#  scheme.
#
#  For this example, "eth0" is external and "eth1" is internal"
#
#  NOTE:  If this doesnt EXACTLY fit your configuration, you must
#         change the EXTIF or INTIF variables above. For example:
#
#            If you are a PPPoE or analog modem user:
#
#               EXTIF="ppp0" 
#
#  ** Please change this to reflect your specific configuration **
#
EXTIF="eth0"
INTIF="eth1"
echo "   External Interface:  $EXTIF"
echo "   Internal Interface:  $INTIF"


# Network Address of the Internal Network
#
#   This example rc.firewall-ipfwadm file uses the 192.168.0.0 network
#   with a /24 or 255.255.255.0 netmask.
#
#    ** Change this variable to reflect your specific setup **
#
INTLAN="192.168.0.0/24"
echo -e "   Internal Interface:  $INTLAN\n"


# Load all required IP MASQ modules
#
#   NOTE:  Only load the IP MASQ modules you need.  All current available IP 
#          MASQ modules are shown below but are commented out from loading.
echo -en "Loading modules: "


# Needed to initially load modules
#
/sbin/depmod -a

# Supports the proper masquerading of FTP file transfers using the PORT method
#
echo -en "FTP, "
/sbin/modprobe ip_masq_ftp

# Supports the masquerading of RealAudio over UDP.  Without this module, 
#	RealAudio WILL function but in TCP mode.  This can cause a reduction
#	in sound quality
#
#echo -en "RealAudio, "
#/sbin/modprobe ip_masq_raudio

# Supports the masquerading of IRC DCC file transfers
#
#echo -en "Irc, "
#/sbin/modprobe ip_masq_irc

# Supports the masquerading of Quake and QuakeWorld by default.  These modules 
#   are for multiple users behind the Linux MASQ server.  If you are going to 
#   play Quake I, II, and III, use the second example.
#
#   NOTE:  If you get ERRORs loading the QUAKE module, you are running an old
#   -----  kernel that has bugs in it.  Please upgrade to the newest kernel.
#
#echo -en "Quake, "
#Quake I / QuakeWorld (ports 26000 and 27000)
#/sbin/modprobe ip_masq_quake
#
#Quake I/II/III / QuakeWorld (ports 26000, 27000, 27910, 27960)
#/sbin/modprobe ip_masq_quake 26000,27000,27910,27960

# Supports the masquerading of the CuSeeme video conferencing software
#
#echo -en "CuSeeme, "
#/sbin/modprobe ip_masq_cuseeme

#Supports the masquerading of the VDO-live video conferencing software
#
#echo -en "VdoLive, "
#/sbin/modprobe ip_masq_vdolive

echo ".  Done loading modules."


#CRITICAL:  Enable IP forwarding since it is disabled by default 
#
#           Redhat Users:  you may try changing the options in 
#                          /etc/sysconfig/network from:
#
#                       FORWARD_IPV4=false  
#                             to
#                       FORWARD_IPV4=true
#
echo "   enabling forwarding.."
echo "1" > /proc/sys/net/ipv4/ip_forward


#CRITICAL:  Enable automatic IP defragmenting since it is disabled by default 
#
#           This used to be a compile-time option but the behavior was changed 
#           in 2.2.12.  This option is required for both 2.0 and 2.2 kernels.
#
echo "   enabling AlwaysDefrag.."
echo "1" > /proc/sys/net/ipv4/ip_always_defrag


# Dynamic IP users:
#
#   If you get your Internet IP address dynamically from SLIP, PPP, or DHCP, 
#   enable the following option.  This enables dynamic-ip address hacking in 
#   IP MASQ, making the life with DialD, PPPd, and similar programs much easier.
#
#echo "   enabling DynamicAddr.."
#echo "1" > /proc/sys/net/ipv4/ip_dynaddr


#Clearing any previous configuration
#
#  Unless specified, the defaults for INPUT and OUTPUT is ACCEPT
#    The default for FORWARD is REJECT
#
#   Isn't ACCEPT insecure?  To some degree, YES, but this is our testing
#   phase.  Once we know that IPMASQ is working well, I recommend you run
#   the rc.firewall-*-stronger rulesets which set the defaults to DROP but
#   also include the critical additional rulesets to still let you connect to
#   the IPMASQ server, etc.
#
echo "   clearing any existing rules and setting default policy.."
/sbin/ipfwadm -I -p accept
/sbin/ipfwadm -O -p accept
/sbin/ipfwadm -F -p reject
/sbin/ipfwadm -I -f
/sbin/ipfwadm -O -f
/sbin/ipfwadm -F -f


# MASQ timeouts
#
#   2 hrs timeout for TCP session timeouts
#  10 sec timeout for traffic after the TCP/IP "FIN" packet is received
#  160 sec timeout for UDP traffic (Important for MASQ'ed ICQ users)
#
echo "   setting default timers.."
/sbin/ipfwadm -M -s 7200 10 160


# DHCP:  For people who receive their external IP address from either DHCP or 
#        BOOTP such as DSL or Cablemodem users, it is necessary to use the 
#        following before the deny command.  
#
#        This example is currently commented out.
#
#
#/sbin/ipfwadm -I -a accept -S 0/0 67 -D 0/0 68 -W $EXTIF -P udp


# Enable simple IP forwarding and Masquerading
#
#  NOTE:  The following is an example for an internal LAN address in the 
#         192.168.0.x network with a 255.255.255.0 or a "24" bit subnet mask
#         connecting to the Internet on interface eth0.
#
#         ** Please change this network number, subnet mask, and your Internet
#         ** connection interface name to match your internal LAN setup.
#
echo "   enabling IPMASQ functionality on $EXTIF"
/sbin/ipfwadm -F -p deny
/sbin/ipfwadm -F -a m -W $EXTIF -S $INTLAN -D 0.0.0.0/0

echo -e "\nrc.firewall-ipfwadm v$FWVER done.\n"
<rc.firewall-ipfwadm STOP>

完成编辑 /etc/rc.d/rc.firewall-ipfwadm 规则集后,通过键入 “chmod 700 /etc/rc.d/rc.firewall-ipfwadm"

现在防火墙规则集已准备就绪,您需要使其在每次重启后运行。您可以手动每次运行它(这很麻烦)或将其添加到启动脚本中。我们在下面介绍了两种方法:Redhat(Sys-V 样式)和 Slackware(BSD 样式)

Redhat 和 Redhat 衍生发行版

  • 在 Redhat 中自动加载内容有两种方法:/etc/rc.d/rc.local 或 /etc/rc.d/init.d/ 中的 init 脚本。第一种方法最简单,但不是 Sys-V 的方式。您只需添加以下行

    echo "Loading the rc.firewall-ipfwadm ruleset.." 
    
    /etc/rc.d/rc.firewall-ipfwadm

    此方法的缺点是防火墙直到启动的最后阶段才执行。首选方法是在网络子系统加载后立即加载防火墙。为此,请将以下文件复制到 /etc/rc.d/init.d 目录

    <firewall-ipfwadm START>

    #!/bin/sh
    #
    # chkconfig: 2345 11 89
    #
    # description: Loads the rc.firewall-ipfwadm ruleset.
    #
    # processname: firewall-ipfwadm
    # pidfile: /var/run/firewall.pid
    # config: /etc/rc.d/rc.firewall-ipfwadm
    # probe: true
    
    # ----------------------------------------------------------------------------
    # v02/09/02
    #
    # Part of the copyrighted and trademarked TrinityOS document.
    # http://www.ecst.csuchico.edu/~dranch
    #
    # Written and Maintained by David A. Ranch
    # dranch@trinnet.net
    #
    # Updates
    # -------
    #
    # ----------------------------------------------------------------------------
    
    
    # Source function library.
    . /etc/rc.d/init.d/functions
    
    # Check that networking is up.
    
    # This line no longer work with bash2
    #[ ${NETWORKING} = "no" ] && exit 0
    # This should be OK. 
    [ "XXXX${NETWORKING}" = "XXXXno" ] && exit 0
    
    [ -x /sbin/ifconfig ] || exit 0
    
    # The location of various iptables and other shell programs
    #
    #   If your Linux distribution came with a copy of iptables, most
    #   likely it is located in /sbin.  If you manually compiled
    #   iptables, the default location is in /usr/local/sbin
    #
    # ** Please use the "whereis iptables" command to figure out
    # ** where your copy is and change the path below to reflect
    # ** your setup
    #
    IPFWADM=/sbin/ipfwadm
    
    
    # See how we were called.
    case "$1" in
      start)
        /etc/rc.d/rc.firewall-ipfwadm
        ;;
    
      stop)
        echo -e "\nFlushing firewall and setting default policies to REJECT\n"
    
        $IPFWADM -I -p REJECT
        $IPFWADM -O -p REJECT
        $IPFWADM -F -p REJECT
    
        $IPFWADM -I -f
        $IPFWADM -O -f
        $IPFWADM -F -f
        ;;
    
      restart)
        $0 stop
        $0 start
        ;;
    
      status)
        $IPFWADM -l
        ;;
    
      mlist)
        $IPFWADM -M -l
        ;;
    
      *)
        echo "Usage: firewall-ipfwadm {start|stop|status|mlist}"
        exit 1
    esac
    
    exit 0
    <firewall-ipfwadm STOP>

    有了这个脚本,您现在需要做的就是使其可执行,然后使其在重启时加载。首先,通过运行以下命令使其可执行

    #Redhat-style
    #
    chmod 700 /etc/rc.d/init.d/firewall-ipfwadm
    现在,使规则集在重启时加载
    #Redhat style
    #
    chkconfig --level=345 firewall-ipfwadm on
    就是这样!现在启动后,防火墙将自动加载。为了确保这一点,运行命令以查看防火墙是否应在重启时启动
    #Redhat style
    #
    chkconfig --list firewall-ipfwadm
    
    #The output should look like:
    #
    firewall-ipfwadm 0:off 1:off 2:off 3:on 4:on 5:on 6:off

Slackware

  • 在 Slackware 中自动加载内容有两种方法:/etc/rc.d/rc.local 或编辑 /etc/rc.d/rc.inet2 文件。第一种方法最简单,但不是最安全的(见下文)。您只需将以下行附加到 /etc/rc.d/rc.local 文件

    echo "Loading the rc.firewall-ipfwadm ruleset.."
    
    /etc/rc.d/rc.firewall-ipfwadm

    此方法的缺点是,如果您运行的是强大的防火墙规则集,则防火墙直到启动的最后阶段才执行。首选方法是在网络子系统加载后立即加载防火墙。目前,本 HOWTO 仅介绍如何使用 /etc/rc.d/rc.local 执行此操作,但如果您知道自己在做什么(这很容易),请继续修改 inet2 启动脚本以在网络启动后立即加载 /etc/rc.d/rc.firewall-ipfwadm 文件。如果您想要更详细的指南和/或更强大的防火墙规则集,我建议您查看本 HOWTO 底部链接部分中 TrinityOS 的第 10 节。

关于用户可能希望如何更改上述防火墙规则集的说明

您还可以基于每台机器启用 IP Masquerading,而不是上述方法,后者是启用整个 TCP/IP 网络。例如,假设我只想让 192.168.0.2 和 192.168.0.8 主机访问 Internet,而不是任何其他内部机器。我将更改 /etc/rc.d/rc.firewall-ipfwadm 规则集的 “启用简单 IP 转发和 Masquerading” 部分(如上所示)中的内容。

# Enable simple IP forwarding and Masquerading
# v2.01
#
#  NOTE:  The following is an example to only allow IP Masquerading for the 
#         192.168.0.2 and 192.168.0.8 machines with a 255.255.255.0 or a "24" 
#         bit subnet mask connected to the Internet on interface eth0.
#
#         ** Please change this network number, subnet mask, and your Internet
#         ** connection interface name to match your internal LAN setup 
#
#         Please use the following in ADDITION to the simple rulesets above for 
#         specific MASQ networks.  
#
/sbin/ipfwadm -F -p deny
/sbin/ipfwadm -F -a m -W $EXTIF -S 192.168.0.2/32 -D 0.0.0.0/0
/sbin/ipfwadm -F -a m -W $EXTIF -S 192.168.0.8/32 -D 0.0.0.0/0

常见错误

对于新的 IP Masq 用户来说,一个常见的错误似乎是将第一个命令设置为

ipfwadm -F -p masquerade

不要将您的默认策略设置为 MASQUERADING。否则,有能力操纵其路由表的人将能够直接隧道返回到您的网关,并使用它来伪装他们自己的身份!

同样,您可以将这些行添加到/etc/rc.d/rc.firewall-ipfwadm文件、您喜欢的其他 rc 文件之一,或者在每次需要 IP Masquerade 时手动添加这些行。

有关 IPCHAINS 和 IPFWADM 规则集示例的详细指南和更强大的示例,请参阅第 6.4.3 节第 6.4.3 节


第 4 章。配置其他内部待 MASQed 机器

除了为每台内部 MASQed 机器设置适当的 IP 地址(静态或通过 DHCP)外,您还应为每台内部机器设置 Linux MASQ 服务器的适当网关 IP 地址和所需的 DNS 服务器。一般来说,这非常简单。您只需输入您的 Linux 主机地址(本 HOWTO 中始终使用 192.168.0.1)作为机器的网关地址。

对于域名服务 (DNS),您可以添加任何可供您使用的 DNS 服务器。最明显的一个或多个应该是您的 Linux 服务器使用的 DNS 服务器。您可以选择性地添加任何 “域搜索” 后缀,以加快连接速度等。

正确重新配置内部 MASQed 机器后,请记住重启其适当的网络服务或在必要时重启它们。

以下配置说明假定您正在使用 C 类网络,并将 192.168.0.1 作为 Linux MASQ 服务器的地址。请注意,根据 RFC1918,192.168.0.0 和 192.168.0.255 是保留的 TCP/IP 地址,用于启用 IP Masquerade 服务等用途。

目前,以下平台已测试为内部 MASQed 机器。这只是所有兼容操作系统的示例


4.1. 配置 Microsoft Windows 95 和 OSR2

  1. ** 请注意,某些提示可能因您运行的 Windows 95 构建版本而异 **

    如果您尚未安装网卡和适配器驱动程序,请立即执行此操作。执行此步骤的说明超出了本文档的范围,尽管它相当简单,但如果您以前没有做过,请寻求帮助。

  2. 转到“控制面板” --> “网络”

  3. 单击添加 --> 协议 --> 制造商:Microsoft --> 协议: “TCP/IP 协议”(如果您尚未安装)。

  4. 突出显示绑定到您的正确 Windows 95 网卡的 TCP/IP 项,例如(TCP/IP --> Intel EtherExpress Pro/100+),然后选择“属性”。在这里,您有两个选项:配置静态地址或使用 DHCP。静态地址很简单,但要求您永远不要在不同的机器上配置重复的 IP。另一种选择是 DHCP,它可以自动配置所有启用 DHCP 的工作站,例如 IP 地址、DNS 服务器等,这些信息来自中央服务器(通常是 Linux MASQ 服务器)。

    已启用 DHCP

    要使用 DHCP,只需单击 “使用 DHCP 分配地址” 按钮。请注意,配置 DHCP 服务器超出了本 HOWTO 的范围,但在 TrinityOS 和其他 Linux HOWTO 中对此进行了全面介绍。

    静态地址

    现在转到“IP 地址”选项卡,并将 IP 地址设置为 192.168.0.x,(1 < x < 255),并将子网掩码设置为 255.255.255.0

  5. 现在选择“网关”选项卡,并在“网关”下添加 192.168.0.1 作为您的网关,然后单击 “添加”。

  6. “DNS 配置”选项卡下,请务必输入此机器的名称并指定您的官方域名。如果您没有自己的域名,请输入您的 ISP 的域名。接下来,您需要指定您计划使用的 DNS 服务器。

    DHCP:不需要任何条目,因为这是通过 DHCP 动态配置的。

    静态:添加您的 Linux MASQ 服务器使用的所有 DNS 服务器(通常在/etc/resolv.conf中找到)。通常,这些 DNS 服务器位于您的 ISP,尽管您也可以在您的 Linux MASQ 服务器上运行您自己的缓存或权威 DNS 服务器。同样,设置 DNS 服务超出了本 HOWTO 的范围,但 TrinityOS 以及 LDP 的 DNS HOWTO 中对此进行了介绍。

    可选地,您也可以添加任何适当的域搜索后缀。这允许用户简单地键入目标计算机的主机名,而不是完全限定域名 (FQDN)。这类似于 PATH 函数,用于查找常见的 Unix 命令。

  7. 除非您知道自己在做什么(甚至是危险的),否则请保持所有其他设置不变。

  8. 在所有对话框中单击“确定”并重启您的系统。

  9. 作为初始测试,PingLinux MASQ 服务器以测试网络连接:“开始/运行”,键入ping 192.168.0.1(这只是一个内部 LAN 连接测试,您可能还无法ping外部世界。)如果您没有看到对您的 PING 的 “回复”,请验证您的网络配置。

  10. 您可以选择创建一个HOSTS文件,该文件位于 C:\Windows 目录中,这样您就可以 ping LAN 上机器的 “hostname”,而无需 DNS 服务器。在 C:\windows 目录中有一个名为HOSTS.SAM的示例。


4.2. 配置 Windows NT

  1. 如果您尚未安装网卡和适配器驱动程序,请立即执行此操作。执行此任务的说明超出了本文档的范围。

  2. 转到“控制面板” --> “网络” --> “协议”

  3. 如果您尚未安装 TCP/IP 服务,请从“添加软件”菜单中添加 TCP/IP 协议和相关组件。

  4. “网络软件和适配器卡”部分下,在“已安装的网络软件”选择框中突出显示“TCP/IP 协议”

  5. “TCP/IP 配置”中,选择适当的适配器,例如[1]Intel EtherExpress Pro/100+。然后将 IP 地址设置为 192.168.0.x (1 < x < 255),然后将子网掩码设置为 255.255.255.0,默认网关设置为 192.168.0.1。

  6. 不要启用以下任何选项(除非您知道自己在做什么)

    • “自动 DHCP 配置”:除非您的网络上运行了 DHCP 服务器。

    • “WINS 服务器” 输入区域中输入任何内容:除非您已设置一个或多个 WINS 服务器。

    • 启用 IP 转发:除非您在您的 NT 机器上进行路由,并且真的 - 真的 - 确切地知道自己在做什么。

  7. 单击“DNS”,填写您的 Linux 主机使用的适当信息(通常在 /etc/resolv.conf 中找到),然后在完成后单击“确定”

  8. 单击“高级”,务必禁用“Windows 名称解析的 DNS”“启用 LMHOSTS 查找”,除非您知道这些选项的作用。如果您想使用 LMHOSTS 文件,它存储在 C:\winnt\system32\drivers\etc 中。

  9. 在所有对话框中单击“确定”并重启系统。

  10. 作为初始测试,pingLinux MASQ 服务器以测试网络连接:“文件/运行”,键入ping 192.168.0.1(这只是一个内部 LAN 连接测试,您可能还无法ping外部世界。)如果您没有看到对您的 PING 的任何 “回复”,请验证您的网络配置。


4.3. 配置 Windows for Workgroup 3.11

  1. 如果您尚未安装网卡和适配器驱动程序,请立即执行此操作。执行此任务的说明超出了本文档的范围。

  2. 如果您尚未安装 TCP/IP 32b 软件包,请安装它。

  3. “主程序”/“Windows 设置”/“网络设置”中,单击“驱动程序”

  4. “网络驱动程序”部分中突出显示 “Microsoft TCP/IP-32 3.11b”,单击“设置”

  5. 将 IP 地址设置为 192.168.0.x (1 < x < 255),然后将子网掩码设置为 255.255.255.0,默认网关设置为 192.168.0.1

  6. 不要启用以下任何选项(除非您知道自己在做什么)

    • “自动 DHCP 配置”:除非您的网络上运行了 DHCP 服务器。

    • “WINS 服务器” 输入区域中输入任何内容:除非您已设置一个或多个 WINS 服务器。

  7. 单击“DNS”,填写您的 Linux 主机使用的适当信息(通常在 /etc/resolv.conf 中找到)。然后在完成后单击“确定”

  8. 单击“高级”,选中 “Windows 名称解析的 DNS”“启用 LMHOSTS 查找”,它们位于 c:\windows 中。

  9. 在所有对话框中单击“确定”并重启系统。

  10. 作为初始测试,pinglinux 机器以测试网络连接:“文件/运行”,键入ping 192.168.0.1(这只是一个内部 LAN 连接测试,因此您可能还无法ping外部世界。)如果您没有看到对您的 PING 的 “回复”,请验证您的网络配置。


4.4. 配置基于 UNIX 的系统

  1. 如果您尚未安装网卡,并且尚未重新配置网络子系统或使用适当的适配器驱动程序重新编译内核,请立即执行此操作。执行此任务的说明超出了本文档的范围,但在 Networking HOWTO 中对此进行了介绍。

  2. 如果您还没有安装 TCP/IP 网络,请安装它,例如 net-tools 软件包。

  3. IPADDR 设置为 192.168.0.x (1 < x < 255),然后将 NETMASK 设置为 255.255.255.0,GATEWAY 设置为 192.168.0.1,BROADCAST 设置为 192.168.0.255。

    • Redhat (Mandrake / TurboLinux / etc):您可以编辑/etc/sysconfig/network-scripts/ifcfg-eth0文件,或者直接通过控制面板 (Linuxconf) 执行此操作。

    • Slackware:您需要编辑 /etc/rc.d/rc.inet1 文件来配置网络子系统。

    • 要添加:Debian、Suse、Caldera 等。如果您能告诉我哪个发行版使用哪些文件来配置网络子系统,请发送电子邮件至 dranch@trinnet.net。

    除此之外,大多数 Linux 发行版都使用差异很大的网络配置机制,更不用说其他 UNIX 系统(如 SunOS、BSDi、Solaris、AIX、TruUnix、FreeBSD 等)。有关更多详细信息,请参阅您的特定 UNIX 文档。

  4. /etc/resolv.conf中添加您的域名服务 (DNS) 和域搜索后缀,对于适当的 UNIX 版本,编辑 /etc/nsswitch.conf 文件以启用 DNS 服务。

  5. 您可能还需要更新您的/etc/networks文件,具体取决于您的 UNIX 版本和系统的设置。

  6. 重启适当的服务,或者直接重启您的系统。

  7. 作为初始测试,运行ping命令ping 192.168.0.1以测试与您的网关机器的连接。(这只是一个内部 LAN 连接测试,因此您可能还无法ping外部世界。)如果您没有看到对您的 PING 的 “回复”,请验证您的网络配置。


4.5. 使用 NCSA Telnet 软件包配置 DOS

  1. 如果您尚未安装网卡,请立即执行此操作。执行此任务的说明超出了本文档的范围。

  2. 加载适当的数据包驱动程序。例如:设置为 I/O 端口 300 和 IRQ 10 的 NE2000 以太网卡需要发出nwpd 0x60 10 0x300

  3. 创建一个新目录,然后解压 NCSA Telnet 软件包pkunzip tel2308b.zip

  4. 使用文本编辑器打开config.tel文件

  5. 设置myip=192.168.0.x(1 < x < 255) 和 netmask=255.255.255.0

  6. 在此示例中,您应设置hardware=packet, interrupt=10, ioaddr=60

  7. 您应该至少有一台单独的机器指定为网关,即 Linux 主机

         name=default
         host=yourlinuxhostname
         hostip=192.168.0.1
         gateway=1

  8. 另有一台指定为域名服务

         name=dns.domain.com ; hostip=123.123.123.123; nameserver=1

    注意:根据您的 Linux 主机使用的内容替换有关 DNS 的适当信息

  9. 保存您的config.tel文件

  10. 作为初始测试,pingLinux MASQ 服务器以测试网络连接ping 192.168.0.1如果您没有收到任何回复,请验证您的网络配置。


4.6. 配置运行 MacTCP 的基于 MacOS 的系统

  1. 如果您尚未安装以太网适配器的适当驱动程序软件,请立即执行此操作。执行此任务的说明超出了本文档的范围。

  2. 打开 MacTCP 控制面板。选择适当的网络驱动程序(以太网,而不是 EtherTalk),然后单击 “更多...” 按钮。

  3. “获取地址:” 下,单击 “手动”

  4. “IP 地址:” 下,从弹出菜单中选择 class C。忽略对话框窗口的其余部分。

  5. “域名服务器信息:” 下填写适当的信息。

  6. “网关地址:” 下,输入 192.168.0.1

  7. 单击 “确定” 以保存设置。在 MacTCP 控制面板的主窗口中,在 “IP 地址:” 框中输入您的 Mac 的 IP 地址(192.168.0.x,1 < x < 255)。

  8. 关闭 MacTCP 控制面板。如果弹出对话框,通知您这样做,则重启系统。

  9. 您可以选择 ping Linux 机器以测试网络连接。如果您有免费程序 MacTCP Watcher,请单击 “Ping” 按钮,然后在弹出的对话框窗口中输入您的 Linux 机器的地址 (192.168.0.1)。(这只是一个内部 LAN 连接测试,您还无法 ping 外部世界。)如果您没有看到对您的 PING 的 “回复”,请验证您的网络配置。

  10. 您可以选择创建一个主机将文件放入您的系统文件夹,以便您可以使用局域网内机器的主机名。该文件应该已经存在于您的系统文件夹中,并且应该包含一些(注释掉的)示例条目,您可以根据自己的需要进行修改。


4.7. 配置运行 Open Transport 的 MacOS 系统

  1. 如果您尚未安装以太网适配器的适当驱动程序软件,请立即执行此操作。执行此任务的说明超出了本文档的范围。

  2. 打开 TCP/IP 控制面板,并从 编辑 菜单中选择 “用户模式...”。确保用户模式至少设置为 “高级”,然后单击 “确定” 按钮。

  3. 文件 菜单中选择 “配置...”。选择您的 “默认” 配置,然后单击 “复制...” 按钮。在 “复制配置” 对话框中输入 “IP Masq”(或其他可以提醒您这是一个特殊配置的名称),它可能会显示类似 “默认副本” 的名称。然后单击 “确定” 按钮和 “设为活动” 按钮。

  4. “通过以下方式连接:” 弹出菜单中选择 “以太网”

  5. “配置:” 弹出菜单中选择合适的项目。如果您不知道选择哪个选项,您可能应该重新选择您的 “默认” 配置并退出。我使用 “手动”

  6. “IP 地址:” 框中输入您的 Mac 的 IP 地址 (192.168.0.x,1 < x < 255)。

  7. “子网掩码:” 框中输入 255.255.255.0。

  8. “路由器地址:” 框中输入 192.168.0.1。

  9. “名称服务器地址:” 框中输入您的域名服务器的 IP 地址。

  10. “隐式搜索路径:” 下的 “起始域名” 框中输入您的 Internet 域名(例如 “microsoft.com”)。

  11. 以下步骤是可选的。不正确的值可能会导致不稳定的行为。如果您不确定,最好将它们留空、取消选中和/或取消选择。如有必要,请删除这些字段中的任何信息。据我所知,没有办法使用 TCP/IP 对话框来告诉系统不要使用以前选择的备用 “Hosts” 文件。如果您知道,我将很感兴趣。

    如果您的网络需要 802.3 帧类型,请选中 “802.3”

  12. 单击 “选项...” 按钮以确保 TCP/IP 处于活动状态。我使用 “仅在需要时加载” 选项。如果您连续运行并退出 TCP/IP 应用程序而不重启计算机,您可能会发现取消选中 “仅在需要时加载” 选项将防止/减少对计算机内存管理的影响。如果取消选中该项,TCP/IP 协议栈将始终加载并可供使用。如果选中,TCP/IP 协议栈将在需要时自动加载,不需要时自动卸载。正是加载和卸载过程可能会导致计算机内存碎片化。

  13. 您可以 ping Linux box 以测试网络连接。如果您有免费软件 MacTCP Watcher,请单击 “Ping” 按钮,并在弹出的对话框中输入您的 Linux box 的地址 (192.168.0.1)。(这只是一个内部局域网连接测试,您还不能 ping 外部世界。)如果您没有看到 PING 的 “回复”,请验证您的网络配置。

  14. 您可以选择创建一个主机文件放入您的系统文件夹,以便您可以使用局域网内机器的主机名。该文件可能已经存在于您的系统文件夹中,也可能不存在。如果存在,它应该包含一些(注释掉的)示例条目,您可以根据自己的需要进行修改。如果不存在,您可以从运行 MacTCP 的系统获取该文件的副本,或者自己创建一个(它遵循 Unix 的一个子集/etc/hosts文件格式,在 RFC1035 中描述)。创建文件后,打开 TCP/IP 控制面板,单击 “选择 Hosts 文件...” 按钮,然后打开主机文件。

  15. 单击关闭框或从 文件 菜单中选择 “关闭”“退出”,然后单击 “保存” 按钮以保存您所做的更改。

  16. 更改会立即生效,但重启系统也没有坏处。


4.8. 使用 DNS 配置 Novell 网络

  1. 如果您尚未安装以太网适配器的适当驱动程序软件,请立即执行此操作。执行此任务的说明超出了本文档的范围。

  2. Novell LanWorkPlace 页面 下载 tcpip16.exe

  3. edit c:\nwclient\startnet.bat: (here is a copy of mine)
    SET NWLANGUAGE=ENGLISH
    LH LSL.COM
    LH KTC2000.COM
    LH IPXODI.COM
    LH tcpip
    LH VLM.EXE
    F:

  4. edit c:\nwclient\net.cfg: (change link driver to yours i.e. NE2000)
    Link Driver KTC2000
            Protocol IPX 0 ETHERNET_802.3    
            Frame ETHERNET_802.3     
            Frame Ethernet_II        
            FRAME Ethernet_802.2
    
    NetWare DOS Requester
               FIRST NETWORK DRIVE = F
               USE DEFAULTS = OFF
               VLM = CONN.VLM
               VLM = IPXNCP.VLM
               VLM = TRAN.VLM
               VLM = SECURITY.VLM
               VLM = NDS.VLM
               VLM = BIND.VLM
               VLM = NWP.VLM
               VLM = FIO.VLM
               VLM = GENERAL.VLM
               VLM = REDIR.VLM
               VLM = PRINT.VLM
               VLM = NETX.VLM
    
    Link Support
            Buffers 8 1500
            MemPool 4096
    
    Protocol TCPIP
            PATH SCRIPT     C:\NET\SCRIPT
            PATH PROFILE    C:\NET\PROFILE
            PATH LWP_CFG    C:\NET\HSTACC
            PATH TCP_CFG    C:\NET\TCP
            ip_address      192.168.0.xxx
            ip_router       192.168.0.1
    
    
    Change the IP address in the above "ip_address" field (192.168.0.x, 1 < x 
    < 255) and finally create c:\bin\resolv.cfg:
    
    SEARCH DNS HOSTS SEQUENTIAL
    NAMESERVER xxx.xxx.xxx.xxx
    NAMESERVER yyy.yyy.yyy.yyy

  5. 现在编辑上面的 “NAMESERVER” 条目,并将它们替换为您本地 DNS 服务器的正确 IP 地址。

  6. 发出一个ping命令ping 192.168.0.1来测试与您的网关机器的连接。(这只是一个内部局域网连接测试,您不能ping外部世界。)如果您没有看到对您的 PING 的 “回复”,请验证您的网络配置。


4.9. 配置 OS/2 Warp

  1. 如果您尚未安装以太网适配器的适当驱动程序软件,请立即执行此操作。执行此任务的说明超出了本文档的范围。

  2. 如果您尚未安装 TCP/IP 协议,请安装它。

  3. 转到 程序/TCP/IP (LAN) / TCP/IP 设置

  4. “网络” 中,添加您的 TCP/IP 地址 (192.168.0.x) 并设置您的网络掩码 (255.255.255.0)

  5. “路由” 下,按 “添加”。将 类型 设置为 “默认”,并在字段 “路由器地址” 中键入您的 Linux Box 的 IP 地址。(192.168.0.1)。

  6. “主机” 中设置与您的 Linux 主机相同的 DNS(名称服务器)地址。

  7. 关闭 TCP/IP 控制面板。对以下问题回答“是”。

  8. 重启您的系统

  9. 您可以 ping Linux box 以测试网络配置。键入“ping 192.168.0.1”在 “OS/2 命令提示符窗口” 中。当收到 ping 数据包时,一切正常。


4.10. 在 IBM AS/400 上配置 OS/400

关于在 AS/400 上运行的 OS/400 V4R1M0 版本上配置 TCP/IP 的描述超出了本文档的范围。

1) 要在您的 AS/400 上执行任何通信配置任务,您必须在您的用户配置文件中定义 *IOSYSCFG(I/O 系统配置)的特殊权限。您可以使用 DSPUSRPRF 命令检查您的用户配置文件的特征。

2) 键入 GO CFGTCP 命令以进入“配置 TCP/IP”菜单。

3) 选择选项 2 - “处理 TCP/IP 路由”。

4) 在 Opt 字段中输入 1 以添加路由。* 在“路由目标”中键入 *DFTROUTE * 在“子网掩码”中键入 *NONE * 在“服务类型”中键入 *NORMAL * 在“下一跳”中键入您的网关地址(Linux box)


4.11. 配置其他系统

相同的逻辑应适用于设置其他平台。请参考以上章节。如果您有兴趣撰写有关尚未涵盖的任何系统的文章,请将详细的设置说明发送至 ambrose@writeme.comdranch@trinnet.net


第 5 章. 测试 IP Masquerade

最后,经过所有这些辛苦的工作,是时候正式尝试 IP Masquerading 了。如果您还没有重启您的 Linux box,请重启它以确保机器启动正常,执行 /etc/rc.d/rc.firewall-* 规则集等。接下来,确保内部局域网连接和您的 Linux 主机与 Internet 的连接都正常。

按照以下 -11- 个测试来确保您的 MASQ 设置的所有方面都运行正常


5.1. 加载 rc.firewall 规则集

第一步:通过命令 “/etc/rc.d/rc.firewall-[iptables / ipchains /ipfwadm]” 为您的机器运行正确的防火墙。例如,Linux 2.6 用户将运行 “/etc/rc.d/rc.firewall-iptables”

它加载时是否出现了一些奇怪的错误?以下是一些示例和帮助来修复它们

  • 问题 #1

    ip_tables, Using /lib/modules/2.4.2-2/kernel/net/ipv4/netfilter/ip_tables.o
    /lib/modules/2.4.2-2/kernel/net/ipv4/netfilter/ip_tables.o: init_module: Device
    or resource busy
    Hint: insmod errors can be caused by incorrect module parameters, including
    invalid IO or IRQ parameters
        

    运行命令 “/sbin/lsmod” 并确保未安装模块 “ipchains.o”。如果已安装,您的机器(很可能是基于 Redhat-7.x 的)可能正在尝试加载与 IPTABLES 不兼容的 IPCHAINS 规则集。

    要阻止将来发生这种情况,请运行命令

       chkconfig --level=2345 ipchains off
       

    要在不重启的情况下删除 “ipchains” 模块,请运行命令

       /sbin/rmmod ipchains
       
    然后重新尝试加载 rc.firewall-* 规则集。

  • 问题 #2

        .
        .
        Creating a DROP chain..
        iptables v1.2.3: log-level `info' ambiguous
        .
        .
        

    您的 IPTABLES 版本太旧。您需要通过更新的 RPM、DEB 或通过编译源代码来升级它。您可以从您的 Linux 发行版制造商或 NetFilter WWW 站点获取更新的版本。所有这些都在 第 2.6 节 中介绍。

  • 问题 #3

        No such file: 
             

    您是否从 DOS 机器复制了此 rc.firewall-* 文件?在二进制编辑器(如 ViM (vim -b /etc/rc.d/rc.firewall-*))中加载 rc.firewall-* 文件,并确保每一行都没有以 ^M 结尾。


5.2. 测试内部 MASQ 客户端 PC 连接性

  • 第二步:测试内部 MASQ 客户端 PC 连接性

    从内部 MASQ 客户端计算机,尝试 ping 其本地 IP 地址(即 ping 192.168.0.10 )。这将验证 TCP/IP 在本地机器上是否正常工作。几乎所有现代操作系统都内置了对 “ping” 命令的支持。如果此 ping 不起作用,请确保已在 MASQ 客户端 PC 上正确配置 TCP/IP,如本 HOWTO 的 第 4 章 中所述。输出应如下所示(按 Control-C 中止 ping)

    ------------------------------------
    masq-client# ping 192.168.0.10 
    PING 192.168.0.10 (192.168.0.10): 56 data bytes
    64 bytes from 192.168.0.10: icmp_seq=0 ttl=255 time=0.8 ms
    64 bytes from 192.168.0.10: icmp_seq=1 ttl=255 time=0.4 ms
    64 bytes from 192.168.0.10: icmp_seq=2 ttl=255 time=0.4 ms
    64 bytes from 192.168.0.10: icmp_seq=3 ttl=255 time=0.5 ms
    ^C
    
    --- 192.168.0.10 ping statistics ---
    4 packets transmitted, 4 packets received, 0% packet loss
    round-trip min/avg/max = 0.4/0.5/0.8 ms
    ------------------------------------


5.3. 测试内部 MASQ 客户端到 MASQ 服务器的连接性

  • 第三步:测试内部 MASQ 客户端到 MASQ 服务器的连接性

    接下来,从同一内部 MASQ 客户端计算机,尝试 ping Linux MASQ 服务器的内部接口的 IP 地址(即 ping 192.168.0.1 )。这将验证 TCP/IP 在本地机器和 Linux MASQ 机器上是否正常工作。几乎所有现代操作系统都内置了对 “ping” 命令的支持。如果此 ping 不起作用,请确保已在 MASQ 服务器上正确配置 TCP/IP,如各种网络 HOWTO(URL 可以在 第 2.6 节 中针对您的 2.4.x 内核、在 第 2.7 节 中针对 2.2.x 内核或在 第 2.8 节 中针对 2.0.x 内核的要求部分找到)所述。输出应如下所示(按 Control-C 中止 ping)

    ------------------------------------
    masq-client# ping 192.168.0.1 
    PING 192.168.0.1 (192.168.0.1): 56 data bytes
    64 bytes from 192.168.0.1: icmp_seq=0 ttl=255 time=0.8 ms
    64 bytes from 192.168.0.1: icmp_seq=1 ttl=255 time=0.4 ms
    64 bytes from 192.168.0.1: icmp_seq=2 ttl=255 time=0.4 ms
    64 bytes from 192.168.0.1: icmp_seq=3 ttl=255 time=0.5 ms
    ^C
    
    --- 192.168.0.1 ping statistics ---
    4 packets transmitted, 4 packets received, 0% packet loss
    round-trip min/avg/max = 0.4/0.5/0.8 ms
    ------------------------------------

    如果 ping 失败,请检查 MASQ 服务器和 PC 之间的网络连接。如果是直接以太网连接(没有集线器或交换机),您必须使用 “以太网交叉电缆”。这些电缆很常见,可以在任何计算机商店找到。没有这条电缆,NIC(网卡)将不会给您 “LINK” 指示灯。如果您正在使用集线器或交换机,请确保连接到 MASQ 服务器和 MASQ 客户端机器的端口有 LINK 指示灯。如果它们有指示灯,但 ping 仍然不起作用或数据包丢失严重,请尝试集线器/交换机上的不同端口(集线器/交换机端口坏掉并非不常见)。最后,如果一切仍然无法完美工作,请尝试更换机器中的每个 NIC。您会惊讶于我帮助过的多少人发现他们的网卡即将损坏,并给他们带来了各种各样的麻烦。


5.4. 测试内部 MASQ 服务器连接性

  • 第四步:测试内部 MASQ 服务器连接性

    在 MASQ 服务器上,ping MASQ 服务器网卡的内部 IP 地址(即 ping 192.168.0.1)。如果此 ping 不起作用,请确保已在 MASQ 服务器上正确配置 TCP/IP,如各种网络 HOWTO(URL 可以在 第 2.6 节 中针对您的 2.4.x 内核、在 第 2.7 节 中针对 2.2.x 内核或在 第 2.8 节 中针对 2.0.x 内核的要求部分找到)所述。输出应如下所示(按 Control-C 中止 ping)

    --------------------------------------
    masq-server# ping 192.168.0.1
    PING 192.168.0.1 (192.168.0.1): 56 data bytes
    64 bytes from 192.168.0.1: icmp_seq=0 ttl=255 time=0.8 ms
    64 bytes from 192.168.0.1: icmp_seq=1 ttl=255 time=0.4 ms
    64 bytes from 192.168.0.1: icmp_seq=2 ttl=255 time=0.4 ms
    64 bytes from 192.168.0.1: icmp_seq=3 ttl=255 time=0.5 ms
    ^C
    
    --- 192.168.0.1 ping statistics ---
    4 packets transmitted, 4 packets received, 0% packet loss
    round-trip min/avg/max = 0.4/0.5/0.8 ms
    ---------------------------------------


5.5. 测试内部 MASQ 服务器到 MASQ 客户端的连接性

  • 第五步:测试内部 MASQ 服务器到 MASQ 客户端的连接性

    接下来,从 MASQ 服务器,尝试 ping 其中一台内部 MASQ 客户端计算机的 IP 地址(即 ping 192.168.0.10 )。这将验证 TCP/IP 在本地服务器机器和 MASQ 客户端机器上是否正常工作。如果此 ping 不起作用,请确保已在 MASQ 客户端 PC 上正确配置 TCP/IP,如本 HOWTO 的 第 4 章 中所述。还要确保布线正确(以太网:连接内部 MASQ PC 和 MASQ 服务器的 NIC 的 “link” 指示灯亮起)。如果 ping 起作用,输出应如下所示(按 Control-C 中止 ping)

    ------------------------------------
    masq-server# ping 192.168.0.10 
    PING 192.168.0.10 (192.168.0.10): 56 data bytes
    64 bytes from 192.168.0.10: icmp_seq=0 ttl=255 time=0.8 ms
    64 bytes from 192.168.0.10: icmp_seq=1 ttl=255 time=0.4 ms
    64 bytes from 192.168.0.10: icmp_seq=2 ttl=255 time=0.4 ms
    64 bytes from 192.168.0.10: icmp_seq=3 ttl=255 time=0.5 ms
    ^C
    
    --- 192.168.0.10 ping statistics ---
    4 packets transmitted, 4 packets received, 0% packet loss
    round-trip min/avg/max = 0.4/0.5/0.8 ms
    ------------------------------------


5.6. 测试外部 MASQ 服务器 Internet 连接性

  • 第六步:测试外部 MASQ 服务器到 Internet 的连接性

    从 MASQ 服务器,ping 连接到 Internet 的 MASQ 服务器外部网络接口的外部 IP 地址。此地址可能是以太网接口、PPP 接口等与您的 ISP 的连接。如果您不知道此外部 IP 地址是什么,请在 MASQ 服务器本身上运行 Linux 命令 “/sbin/ifconfig” 以获取 Internet 地址。输出应如下所示(我们正在查找 eth0 的 IP 地址)

    ------------------------------------
    eth0      Link encap:Ethernet  HWaddr 00:08:C7:A4:CC:5B  
              inet addr:12.13.14.15  Bcast:12.13.14.255  Mask:255.255.255.0
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:6108459 errors:0 dropped:0 overruns:0 frame:0
              TX packets:5422798 errors:8 dropped:0 overruns:0 carrier:8
              collisions:4675 txqueuelen:100 
              Interrupt:11 Base address:0xfcf0
    ------------------------------------   

    从上面可以看出,此示例的外部 IP 地址是 “12.13.14.15”。因此,现在您在运行 “ipconfig” 命令后获得了您的 IP 地址,请 ping 您的外部 IP 地址。这将确认 MASQ 服务器具有完整的网络连接。输出应如下所示(按 Control-C 中止 ping)

    -------------------------------------
    masq-server# ping 12.13.14.15
    PING 12.13.14.15 (12.13.14.15): 56 data bytes
    64 bytes from 12.13.14.15: icmp_seq=0 ttl=255 time=0.8 ms
    64 bytes from 12.13.14.15: icmp_seq=1 ttl=255 time=0.4 ms
    64 bytes from 12.13.14.15: icmp_seq=2 ttl=255 time=0.4 ms
    64 bytes from 12.13.14.15: icmp_seq=3 ttl=255 time=0.5 ms
    ^C
    
    --- 12.13.14.15 ping statistics ---
    4 packets transmitted, 4 packets received, 0% packet loss
    round-trip min/avg/max = 0.4/0.5/0.8 ms
    -------------------------------------

    如果这些测试中的任何一个不起作用,您需要返回并仔细检查您的网络布线,并验证 “dmesg” 中是否可以看到 MASQ 服务器上的两个网络接口。此输出的示例将是 “dmesg” 命令末尾附近的以下内容

    -------------------------------------
    .
    .
    PPP: version 2.3.7 (demand dialling)
    TCP compression code copyright 1989 Regents of the University of California
    PPP line discipline registered.
    3c59x.c:v0.99H 11/17/98 Donald Becker
    http://cesdis.gsfc.nasa.gov/linux/drivers/
    vortex.html
    eth0: 3Com 3c905 Boomerang 100baseTx at 0xfe80,  00:60:08:a7:4e:0e, IRQ 9
      8K word-wide RAM 3:5 Rx:Tx split, autoselect/MII interface.
      MII transceiver found at address 24, status 786f.
      Enabling bus-master transmits and whole-frame receives.
    eth1: 3Com 3c905 Boomerang 100baseTx at 0xfd80,  00:60:97:92:69:f8, IRQ 9
      8K word-wide RAM 3:5 Rx:Tx split, autoselect/MII interface.
      MII transceiver found at address 24, status 7849.
      Enabling bus-master transmits and whole-frame receives.
    Partition check:
     sda: sda1 sda2 < sda5 sda6 sda7 sda8 >
     sdb:
    .
    .
    -------------------------------------

    还要确保布线正确(以太网:连接外部 MASQ 服务器到您的 ISP 的 NIC 的 “link” 指示灯亮起)。最后,确保已在 MASQ 服务器上正确配置 TCP/IP,如各种网络 HOWTO(URL 可以在 第 2.6 节 中针对您的 2.4.x 内核、在 第 2.7 节 中针对 2.2.x 内核或在 第 2.8 节 中针对 2.0.x 内核的要求部分找到)所述。


5.7. 测试内部 MASQ 客户端到外部 MASQ 服务器的连接性

  • 第七步:测试内部 MASQ 客户端到外部 MASQ 服务器的连接性

    从内部 MASQ 客户端计算机,ping 在上面的第五步中获得的 MASQ 服务器的外部 TCP/IP 地址的 IP 地址。此地址可能来自您的以太网、PPP 等接口,最终是连接到您的 ISP 的地址。此 ping 测试将证明 Linux masquerading(特别是 ICMP Masquerading)和 IP 转发正在工作。

    如果一切正常,输出应如下所示(按 Control-C 中止 ping)

    -------------------------------------
    masq-client# ping 12.13.14.15
    PING 12.13.14.15 (12.13.14.15): 56 data bytes
    64 bytes from 12.13.14.15: icmp_seq=0 ttl=255 time=0.8 ms
    64 bytes from 12.13.14.15: icmp_seq=1 ttl=255 time=0.4 ms
    64 bytes from 12.13.14.15: icmp_seq=2 ttl=255 time=0.4 ms
    64 bytes from 12.13.14.15: icmp_seq=3 ttl=255 time=0.5 ms
    ^C
    
    --- 12.13.14.15 ping statistics ---
    4 packets transmitted, 4 packets received, 0% packet loss
    round-trip min/avg/max = 0.4/0.5/0.8 ms
    -------------------------------------

    如果此测试不起作用,首先请确保 MASQ 客户端 PC 上的 “默认网关” 指向 MASQ -SERVERs- 内部 NIC 上的 IP 地址。还要仔细检查 /etc/rc.d/rc.firewall-* 脚本是否在没有任何错误的情况下运行。作为测试,现在尝试重新运行 /etc/rc.d/rc.firewall-* 脚本,看看它是否运行正常。此外,尽管大多数内核默认支持它,但请确保您在内核配置中启用了 “ICMP Masquerading”,并在您的 /etc/rc.d/rc.firewall-* 脚本中启用了 “IP 转发”。

    如果您仍然无法使其工作,请查看在 Linux MASQ SERVER 上运行的以下命令的输出

    • ifconfig”:确保您的 Internet 连接接口(无论是 ppp0、eth0 等)已启动,并且您具有 Internet 连接的正确 IP 地址。上面的第五步中显示了此输出的示例。

    • netstat -rn”:确保您的默认网关(“网关”列中带有 IP 地址的列)已设置。此输出的示例可能如下所示

      -------------------------------------
      masq-server# netstat -rn
      Kernel IP routing table
      Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
      192.168.0.1     0.0.0.0         255.255.255.255 UH        0 16384      0 eth1
      12.13.14.15     0.0.0.0         255.255.255.255 UH        0 16384      0 eth0
      12.13.14.0      0.0.0.0         255.255.255.0   U         0 0          0 eth0
      192.168.0.0     0.0.0.0         255.255.255.0   U         0 0          0 eth1
      127.0.0.0       0.0.0.0         255.0.0.0       U         0 16384      0 lo
      0.0.0.0         12.13.14.1      0.0.0.0         UG        0 16384      0 eth0 
      -------------------------------------  
      注意以 0.0.0.0 开头的最后一行?注意它在 “网关” 字段中也有一个 IP 地址吗?您应该在该字段中为您的特定设置指定一个 IP 地址(这通常在启用您的 Internet 连接时自动完成)。

    • cat /proc/sys/net/ipv4/ip_forward”:确保它显示 “1”,以便启用 Linux 转发

    • 对于 2.2.x 用户运行命令 “/sbin/ipchains -n -L”,对于 2.0.x 用户运行命令 “/sbin/ipfwadm -F -l”。具体来说,查找 FORWARDing 部分以确保您已启用 MASQ。对于使用 SIMPLE rc.firewall-* 规则集的用户,IPCHAINS 输出的示例可能如下所示

      ------------------------------------
      .
      .
      Chain forward (policy REJECT):
      target     prot opt     source                destination           ports
      MASQ       all  ------  192.168.0.0/24       0.0.0.0/0             n/a
      ACCEPT     all  ----l-  0.0.0.0/0            0.0.0.0/0             n/a
      .
      .  
      ------------------------------------  
         


5.8. 测试外部 MASQ ICMP 转发

  • 第八步:测试外部 MASQ ICMP 转发

    从内部 MASQ 客户端计算机,ping Internet 上的静态 TCP/IP 地址(不是通过 DNS 名称的机器)(即 ping 152.2.210.80(这在技术上是 DNS 名称 “metalab.unc.edu”,它是 MetaLabs' Linux Archive 的所在地)。如果这有效,它应如下面的结果所示,并且最终表明 ICMP Masquerading 正在正常工作。(按 Control-C 中止 ping)

    -------------------------------------
    masq-client# ping 152.2.210.80
    
    PING 12.13.14.15 (152.2.210.80): 56 data bytes
    64 bytes from 152.2.210.80: icmp_seq=0 ttl=255 time=133.4 ms
    64 bytes from 152.2.210.80: icmp_seq=1 ttl=255 time=132.5 ms
    64 bytes from 152.2.210.80: icmp_seq=2 ttl=255 time=128.8 ms
    64 bytes from 152.2.210.80: icmp_seq=3 ttl=255 time=132.2 ms
    ^C
    
    --- 152.2.210.80 ping statistics ---
    4 packets transmitted, 4 packets received, 0% packet loss
    round-trip min/avg/max = 128.8/131.7/133.4 ms  
    -------------------------------------

    如果这不起作用,请再次检查您的 Internet 连接。确保 MASQ 服务器本身可以 ping 此地址。如果从 MASQ 服务器可以正常 ping 通,请确保您正在使用简单的 rc.firewall-* 规则集,并且您已将 ICMP Masqurading 编译到 Linux 内核中。

    最后,确保启用 IP MASQ 的规则集指向正确的外部接口。PPPoE 用户应使用 MASQ 服务器的逻辑 PPP 接口(如 “ppp0”),而不是物理外部接口(如 “eth0”)。


5.9. 在没有 DNS 的情况下测试 MASQ 功能

  • 第九步:在没有 DNS 的情况下测试 MASQ 功能

    现在尝试 TELNET 到远程 IP 地址(即 telnet 152.2.210.81(这在技术上是 DNS 名称 “metalab.unc.edu”)。由于这是一个非常繁忙的服务器,因此可能需要几秒钟才能获得登录提示。您是否获得了如下所示的登录提示?如果是,则表示 TCP Masquerading 运行正常。如果不是,请尝试 TELNET 到您认为会支持 TELNET 的其他主机,例如 198.182.196.55 (www.linux.org)。如果仍然不起作用,请确保您正在为此测试使用简单的 rc.firewall-* 规则集。此输出的示例可能如下所示(按 Control-D 退出 TELNET)

    --------------------------------
    masq-client# telnet 152.2.210.80
    Trying 152.2.210.80...
    Connected to 152.2.210.80.
    Escape character is '^]'.
    
    
    SunOS 5.7
    
    
    ******************** Welcome to MetaLab.unc.edu *******************
    
     To login to MetaLab as a user, connect to login.metalab.unc.edu.
               This machine does not allow public telnet logins.
    
    login: Connection closed by foreign host.
    --------------------------------


5.10. 使用 DNS 解析测试 MASQ 功能

  • 第十步:使用 DNS 解析测试 MASQ 功能

    现在尝试通过 DNS 名称 TELNET 到远程计算机(即 “telnet metalab.unc.edu”(IP 地址 152.2.210.81)。如果这有效,输出应如下所示。通过此测试,表明基于 UDP 的 DNS 工作正常。

    --------------------------------
    masq-client# telnet MetaLab.unc.edu
    Trying 152.2.210.80...
    Connected to 152.2.210.80.
    Escape character is '^]'.
    
    
    SunOS 5.7
    
    
    ******************** Welcome to MetaLab.unc.edu *******************
    
     To login to MetaLab as a user, connect to login.metalab.unc.edu.
               This machine does not allow public telnet logins.
    
    login: Connection closed by foreign host.
    --------------------------------

    如果这不起作用,但第八步有效,请确保您在每个 MASQ 客户端计算机上配置了一个或多个有效的 DNS 服务器,如 第 4 章 所示。请注意,这些 DNS 服务器通常将是您的 ISP 的 DNS 服务器,而不是您的本地 MASQ 服务器。有些人可能稍后选择设置自己的 DNS 服务器,但这超出了本 HOWTO 的范围。


5.11. 使用 DNS 测试更多 MASQ 功能

  • 第十一步:使用 DNS 测试更多 MASQ 功能

    作为最后一个测试,尝试在您的其中一台 MASQ 客户端 机器上浏览一些 “INTERNET” WWW 站点,看看您是否可以访问它们。例如,访问 Linux 文档项目站点 http://www.tldp.org。如果您成功打开该页面,您可以相当肯定一切都工作正常!如果某些 WWW 或 FTP 站点有问题,而其他站点似乎工作正常,请参阅下一步以获取更多想法。

    如果您看到 Linux 文档项目主页,那么 恭喜您!它正在工作! 如果 WWW 站点正确显示,那么所有其他标准网络工具(如 PING、TELNET、SSH)以及加载了相关 IP MASQ 模块的工具:FTP、Real Audio、IRC DCC、Quake I/II/III、CuSeeme、VDOLive 等也应该可以正常工作!如果 FTP、IRC、RealAudio、Quake I/II/III 等无法工作或性能不佳,请通过运行 “lsmod” 验证其关联的 Masquerading 模块是否已加载,并确保您正在加载带有任何非默认服务器端口的模块。如果您没有看到您需要的模块,请确保您的 /etc/rc.d/rc.firewall-* 脚本正在加载它们(即,删除给定 IP MASQ 模块的 # 字符)。


5.12. 任何剩余的功能、性能等问题...

  • 第十二步:任何剩余的功能、性能等问题...

    如果您的系统通过了以上所有测试,但 WWW 浏览、FTP 和其他类型的流量等功能测试不可靠或速度缓慢,我建议您阅读本 HOWTO 的 FAQ 部分。特别是 第 7.15 节 FAQ 条目。FAQ 部分可能还有其他项目可以帮助您,因为它们过去曾帮助过许多其他用户。


第 6 章. 其他 IP Masquerade 问题和软件支持

6.1. IP Masquerade 的问题

某些 TCP/IP 应用程序协议当前无法与 Linux IP Masquerading 一起工作,因为它们要么对端口号做出假设,要么在其数据流中编码 TCP/IP 地址和/或端口号。后一种协议需要特定的代理或内置在 masquerading 代码中的 IP MASQ 模块才能使其工作。


6.2. 入站服务

默认情况下,Linux IP Masquerading 根本无法处理入站服务,但有一些方法可以实现这一点。

如果您不需要高安全级别,那么您可以简单地转发或重定向 IP 端口。有多种方法可以执行此操作,但最稳定的方法是使用 IPPORTFW。有关更多信息,请参阅 第 6.7 节

如果您希望对入站连接进行某种程度的授权,那么您将需要配置 TCP-wrappers 或 Xinetd 以仅允许特定的 IP 地址通过。TIS Firewall Toolkit 是查找工具和信息的好地方。

有关入站安全性的更多详细信息,请参阅 TrinityOS 文档和 IP Masquerade 资源


6.3. 支持的客户端软件和其他设置说明

** Linux Masquerade 应用程序列表 包含许多关于可以通过 Linux IP masquerading 工作的应用程序的良好信息。该站点最近被 Steve Grevemeyer 接管,他使用完整的数据库后端实现了它。这是一个很棒的资源!

通常,任何使用标准 TCP 和 UDP 的应用程序都应该可以工作。如果您有任何建议、提示等,请参阅 IP Masquerade 资源 以获取更多详细信息。


6.3.1. 与 IP Masquerade -工作- 的网络客户端

通用客户端

Archie

所有支持的平台,文件搜索客户端(并非所有 archie 客户端都受支持)

FTP

所有支持的平台,对于主动 FTP 连接,需要 ip_masq_ftp.o 内核模块。

Gopher 客户端

所有支持的平台

HTTP

所有支持的平台,WWW 冲浪

IRC

各种支持平台上的所有 IRC 客户端,DCC 通过 ip_masq_irc.o 模块支持

NNTP (USENET)

所有支持的平台,USENET 新闻客户端

PING

所有平台,带有 ICMP Masquerading 内核选项

POP3

所有支持的平台,电子邮件客户端

SSH

所有支持的平台,安全 TELNET/FTP 客户端

SMTP

所有支持的平台,电子邮件服务器,如 Sendmail、Qmail、PostFix 等。

TELNET

所有支持的平台,远程会话

TRACEROUTE

UNIX 和 Windows 平台,某些变体可能无法工作

VRML

Windows(可能所有支持的平台),虚拟现实冲浪

WAIS 客户端

所有支持的平台

多媒体和通信客户端

所有 H.323 程序

- MS Netmeeting、Intel Internet Phone Beta 和其他 H.323 应用程序 - 现在有两种解决方案可以通过 IPMASQed 连接实现此目的

MASQ WWW 站点http://www.coritel.it/projects/nat/implementation.htm 上提供了稳定的 BETA 2.2.x 内核模块,可与 2.2.x 内核上的 Microsoft Netmeeting v3.x 代码一起使用。MASQ WWW 站点上还有另一个模块版本,专门用于 2.0.x 内核的 Netmeeting 2.x,但这不支持 Netmeeting v3.x。

另一个商业解决方案是 Equivalence's PhonePatch H.323 网关。

Alpha Worlds

Windows,客户端-服务器 3D 聊天程序

CU-SeeMe

所有支持的平台,加载 ip_masq_cuseeme 模块,请参阅 第 6.8 节 以获取更多详细信息。

ICQ

所有支持的客户端。需要 Linux 内核编译时具有 PORTFW 支持,或者具有 ip_masq_icq 模块(仅限 2.2.x 和 2.0.x),或者运行 SOCKS 代理。此配置的完整描述在 第 6.9 节 中。

Internet Phone 3.2

Windows,点对点音频通信,用户只能在您发起呼叫时联系您,但如果没有特定的端口转发设置,这些用户无法呼叫您。有关更多详细信息,请参阅 第 6.7 节

Internet Wave Player

Windows,网络流媒体音频

Powwow

Windows,点对点文本音频白板通信,用户只能在您发起呼叫时联系您,但如果没有特定的端口转发设置,这些用户无法呼叫您。有关更多详细信息,请参阅 第 6.7 节

Real Audio Player

Windows,网络流媒体音频,使用 ip_masq_raudio UDP 模块可获得更高的质量

True Speech Player 1.1b

Windows,网络流媒体音频

VDOLive

Windows,带有 ip_masq_vdolive 补丁

Worlds Chat 0.9a

Windows,客户端-服务器 3D 聊天程序

游戏 - 有关 LooseUDP 补丁的更多详细信息,请参阅 第 6.10 节

Battle.net

可以工作,但需要将 TCP 端口 116、118 和 UDP 端口 6112 IPPORTFWed 到客户端游戏机器。有关更多详细信息,请参阅 第 6.7 节。请注意,FSGS 和 Bnetd 服务器仍然需要 IPPORTFW,因为它们尚未重新编写为 NAT 友好型。

BattleZone 1.4

使用 LooseUDP 补丁和新的 NAT 友好型 -- 发送电子邮件给 David Ranch 以获取 Activision 的 .DLL

Dark Reign 1.4

使用 LooseUDP 补丁或需要将 TCP 端口 116 和 118 以及 UDP 端口 6112 IPPORTFWed 到游戏机器。有关更多详细信息,请参阅 第 6.7 节

Diablo

使用 LooseUDP 补丁或需要将 TCP 端口 116 和 118 以及 UDP 端口 6112 IPPORTFWed 到游戏机器。较新版本的 Diablo 仅使用 TCP 端口 6112 和 UDP 端口 6112。有关更多详细信息,请参阅 第 6.7 节

Heavy Gear 2

使用 LooseUDP 补丁或需要将 TCP 端口 116 和 118 以及 UDP 端口 6112 IPPORTFWed 到游戏机器。有关更多详细信息,请参阅 第 6.7 节

Quake I/II/III

开箱即用,但如果 MASQ box 后面有多个 Quake I/II/III 玩家,则需要 ip_masq_quake 模块。此外,此模块默认仅支持 Quake I 和 QuakeWorld。如果您需要支持 Quake II 或非默认服务器端口,请参阅 第 3.4.3 节第 3.4.2 节 规则集的模块安装部分。

StarCraft

使用 LooseUDP 补丁,IPPORTFWing TCP 和 UDP 端口 6112 到内部 MASQed 游戏机器。有关更多详细信息,请参阅 第 6.7 节

WorldCraft

使用 LooseUDP 补丁

其他客户端

Linux net-acct 包

Linux,网络管理-帐户包

NCSA Telnet 2.3.08

DOS,包含 telnet、ftp、ping 等的套件

PC-anywhere for Windows

MS-Windows 通过 TCP/IP 远程控制 PC,但仅在作为客户端时有效,如果不是客户端,则需要在没有特定端口转发设置的情况下才能工作。 详见第 6.7 节了解更多详情。

Socket Watch

使用 NTP - 网络时间协议


6.3.2. 在 IP MASQ 中没有完全支持的客户端

Intel Streaming Media Viewer Beta 1

无法连接到服务器

Netscape CoolTalk

无法连接到对方

WebPhone

目前无法工作(它对地址做出了无效的假设)。


6.4. 用于初始测试后运行的更强的防火墙规则集

6.4.1. 更强的 IP 防火墙 (IPTABLES) 规则集

<rc.firewall-iptables-stronger START>

#!/bin/sh
#
# rc.firewall-iptables-stronger
#
FWVER=0.88s

#          An example of a stronger IPTABLES firewall with IP Masquerade 
#          support for 2.4.x kernels.  
#
# Log:
#
#   0.88s - Updated the commands for dynamically addresses machines and
#           to point to an expanded FAQ section for more information
#
#   0.87s - Removed the unused drop-and-logit chain as it was only later
#           being deleted anyway
#   0.86s - Fixed a typo that had a preceeding ; instead of a #
#   0.85s - renamed from rc.firewall-2.4-stronger to rc.firewall-iptables-
#           stronger to reflect this script works for all IPTABLES enabled
#           platforms including 2.6.x kernels
#         - fixed an incorrect /24 netmask for the INTIP variable
#         - removed the unneeded SED variable
#   0.84s - Changed the defaults from 192.168.1.0 to 192.168.0.x to align
#           with the rest of the IPMASQ howto
#   0.83s - Added additional comments to make PORTFW configs more obvious
#   0.82s - Added a special ICMP filter to work around a Netfilter security
#           issue
#         - renamed the drop-and-log-it rule to reject-and-log-it
#   0.81s - Added an additional comment in the INPUT section for NOT 
#           allowing all traffic in, but only select traffic
#   0.80s - Added a DISABLED ip_nat_irc kernel module section, changed the
#           default of the ip_conntrack_irc to NOT load by default, and 
#           added additional kernel module comments
#   0.79s - ruleset now uses modprobe instead of insmod
#   0.78s - REJECT is not a legal policy yet; back to DROP
#   0.77s - Changed the default block behavior to REJECT not DROP
#   0.76s - Added a comment about the OPTIONAL WWW ruleset and a comment
#           where to put optional PORTFW commands
#   0.75s - Added clarification that PPPoE users need to use
#           "ppp0" instead of "eth0" for their external interface
#   0.74s - Changed the EXTIP command to work on NON-English distros
#   0.73s - Added comments in the output section that DHCPd is optional
#           and changed the default settings to disabled
#   0.72s - Changed the filter from the INTNET to the INTIP to be
#           stateful; moved the command VARs to the top and made the
#           rest of the script to use them
#   0.70s - Added a disabled examples for allowing internal DHCP  
#           and external WWW access to the server
#   0.63s - Added support for the IRC module
#   0.62s - Initial version based upon the basic 2.4.x rc.firewall


echo -e "\nLoading rc.firewall-iptables-STRONGER - version $FWVER..\n"


# The location of various iptables and other shell programs
#
#   If your Linux distribution came with a copy of iptables, most
#   likely it is located in /sbin.  If you manually compiled 
#   iptables, the default location is in /usr/local/sbin
#
# ** Please use the "whereis iptables" command to figure out 
# ** where your copy is and change the path below to reflect 
# ** your setup
#
#IPTABLES=/sbin/iptables
IPTABLES=/usr/local/sbin/iptables
#
LSMOD=/sbin/lsmod
DEPMOD=/sbin/depmod
MODPROBE=/sbin/modprobe
GREP=/bin/grep
AWK=/bin/awk
IFCONFIG=/sbin/ifconfig


#Setting the EXTERNAL and INTERNAL interfaces for the network
#
#  Each IP Masquerade network needs to have at least one
#  external and one internal network.  The external network
#  is where the natting will occur and the internal network
#  should preferably be addressed with a RFC1918 private address
#  scheme.
#
#  For this example, "eth0" is external and "eth1" is internal"
#
#  NOTE:  If this doesnt EXACTLY fit your configuration, you must 
#         change the EXTIF or INTIF variables above. For example: 
#
#            If you are a PPPoE or analog modem user:
#
#               EXTIF="ppp0" 
#
EXTIF="eth0"
INTIF="eth1"
echo "  External Interface:  $EXTIF"
echo "  Internal Interface:  $INTIF"
echo "  ---"

# Specify your Static IP address here or let the script take care of it 
# for you.
#
#   If you prefer to use STATIC addresses in your firewalls, un-# out the
#   static example below and # out the dynamic line.  If you don't care,
#   just leave this section alone.
#
#   If you have a DYNAMIC IP address, the ruleset already takes care of
#   this for you.  Please note that the different single and double quote 
#   characters and the script MATTER.
#
#
#   PPP and DHCP (Cablemodem and DSL ) users:
#   -----------------------------------------
#   PPP: If you get your TCP/IP address via DHCP, **you will need ** to 
#   enable the #   #ed out command below underneath the PPP section AND 
#   replace the word "eth0" with the name of your EXTERNAL Internet 
#   connection (ppp0, ippp0, etc) on the lines for "ppp-ip" and "extip".  
#
#   DHCP and PPP users:  The remote DHCP or PPP server can and will change 
#   IP addresses on you over time.  To deal with this, users should configure 
#   their DHCP or PPP client to re-run the rc.firewall-* ruleset everytime 
#   the IP address is changed.  Please see the "masq-and-dyn-addr" FAQ entry 
#   in the IPMASQ howto for full details on how to do this.
#
#
# Determine the external IP automatically:
# ----------------------------------------
#
#  The following line will determine your external IP address.  This
#  line is somewhat complex and confusing but it will also work for
#  all NON-English Linux distributions:
#
EXTIP="`$IFCONFIG $EXTIF | $AWK \
 /$EXTIF/'{next}//{split($0,a,":");split(a[2],a," ");print a[1];exit}'`"


# For users who wish to use STATIC IP addresses:
#
#  # out the EXTIP line above and un-# out the EXTIP line below
#
#EXTIP="your.static.PPP.address"
echo "  External IP: $EXTIP"
echo "  ---"


# Assign the internal TCP/IP network and IP address
INTNET="192.168.0.0/24"
INTIP="192.168.0.1/32"
echo "  Internal Network: $INTNET"
echo "  Internal IP:      $INTIP"
echo "  ---"




# Setting a few other local variables
#
UNIVERSE="0.0.0.0/0"

#======================================================================
#== No editing beyond this line is required for initial MASQ testing ==

# Need to verify that all modules have all required dependencies
#
echo "  - Verifying that all kernel modules are ok"
$DEPMOD -a

echo -en "    Loading kernel modules: "

# With the new IPTABLES code, the core MASQ functionality is now either
# modular or compiled into the kernel.  This HOWTO shows ALL IPTABLES
# options as MODULES.  If your kernel is compiled correctly, there is
# NO need to load the kernel modules manually.  
#
#  NOTE: The following items are listed ONLY for informational reasons.
#        There is no reason to manual load these modules unless your
#        kernel is either mis-configured or you intentionally disabled
#        the kernel module autoloader.
#

# Upon the commands of starting up IP Masq on the server, the
# following kernel modules will be automatically loaded:
#
# NOTE:  Only load the IP MASQ modules you need.  All current IP MASQ 
#        modules are shown below but are commented out from loading.
# ===============================================================

#Load the main body of the IPTABLES module - "ip_tables"
#  - Loaded automatically when the "iptables" command is invoked
#
#  - Loaded manually to clean up kernel auto-loading timing issues
#
echo -en "ip_tables, "
#
#Verify the module isn't loaded.  If it is, skip it
#
if [ -z "` $LSMOD | $GREP ip_tables | $AWK {'print $1'} `" ]; then
   $MODPROBE ip_tables
fi


#Load the IPTABLES filtering module - "iptable_filter" 
#
#  - Loaded automatically when filter policies are activated


#Load the stateful connection tracking framework - "ip_conntrack"
#
# The conntrack  module in itself does nothing without other specific 
# conntrack modules being loaded afterwards such as the "ip_conntrack_ftp"
# module
#
#  - This module is loaded automatically when MASQ functionality is 
#    enabled 
#
#  - Loaded manually to clean up kernel auto-loading timing issues
#
echo -en "ip_conntrack, "
#
#Verify the module isn't loaded.  If it is, skip it
#
if [ -z "` $LSMOD | $GREP ip_conntrack | $AWK {'print $1'} `" ]; then
   $MODPROBE ip_conntrack
fi


#Load the FTP tracking mechanism for full FTP tracking
#
# Enabled by default -- insert a "#" on the next line to deactivate
#
echo -e "ip_conntrack_ftp, "
#
#Verify the module isn't loaded.  If it is, skip it
#
if [ -z "` $LSMOD | $GREP ip_conntrack_ftp | $AWK {'print $1'} `" ]; then
   $MODPROBE ip_conntrack_ftp
fi


#Load the IRC tracking mechanism for full IRC tracking
#
# Disabled by default -- insert a "#" on the next few lines to activate
#
# echo -en "                             ip_conntrack_irc, "
#
#Verify the module isn't loaded.  If it is, skip it
#
# if [ -z "` $LSMOD | $GREP ip_conntrack_irc | $AWK {'print $1'} `" ]; then
#    $MODPROBE ip_conntrack_irc
# fi


#Load the general IPTABLES NAT code - "iptable_nat"
#  - Loaded automatically when MASQ functionality is turned on
# 
#  - Loaded manually to clean up kernel auto-loading timing issues
#
echo -en "iptable_nat, "
#
#Verify the module isn't loaded.  If it is, skip it
#
if [ -z "` $LSMOD | $GREP iptable_nat | $AWK {'print $1'} `" ]; then
   $MODPROBE iptable_nat
fi


#Loads the FTP NAT functionality into the core IPTABLES code
# Required to support non-PASV FTP.
#
# Enabled by default -- insert a "#" on the next line to deactivate
#
echo -e "ip_nat_ftp"
#
#Verify the module isn't loaded.  If it is, skip it
#
if [ -z "` $LSMOD | $GREP ip_nat_ftp | $AWK {'print $1'} `" ]; then
   $MODPROBE ip_nat_ftp
fi


#Loads the IRC NAT functionality (for DCC) into the core IPTABLES code
#
# DISABLED by default -- delete the "#" on the next few lines to activate
#
# echo -e "ip_nat_irc"
#
#Verify the module isn't loaded.  If it is, skip it
#
# if [ -z "` $LSMOD | $GREP ip_nat_irc | $AWK {'print $1'} `" ]; then
#    $MODPROBE ip_nat_irc
# fi


echo "  ---"

# Just to be complete, here is a partial list of some of the other  
# IPTABLES kernel modules and their function.  Please note that most 
# of these modules (the ipt ones) are automatically loaded by the 
# master kernel module for proper operation and don't need to be 
# manually loaded.
# --------------------------------------------------------------------
#
#    ip_nat_snmp_basic - this module allows for proper NATing of some 
#                        SNMP traffic
#
#    iptable_mangle    - this target allows for packets to be 
#                        manipulated for things like the TCPMSS 
#                        option, etc.
#
# --
#
#    ipt_mark       - this target marks a given packet for future action.
#                     This automatically loads the ipt_MARK module
#
#    ipt_tcpmss     - this target allows to manipulate the TCP MSS
#                     option for braindead remote firewalls.
#                     This automatically loads the ipt_TCPMSS module
#
#    ipt_limit      - this target allows for packets to be limited to
#                     to many hits per sec/min/hr
#
#    ipt_multiport  - this match allows for targets within a range
#                     of port numbers vs. listing each port individually
#
#    ipt_state      - this match allows to catch packets with various
#                     IP and TCP flags set/unset
#
#    ipt_unclean    - this match allows to catch packets that have invalid
#                     IP/TCP flags set
#
#    iptable_filter - this module allows for packets to be DROPped, 
#                     REJECTed, or LOGged.  This module automatically 
#                     loads the following modules:
#
#                     ipt_LOG - this target allows for packets to be 
#                               logged
#
#                     ipt_REJECT - this target DROPs the packet and returns 
#                                  a configurable ICMP packet back to the 
#                                  sender.


#CRITICAL:  Enable IP forwarding since it is disabled by default since
#
#           Redhat Users:  you may try changing the options in
#                          /etc/sysconfig/network from:
#
#                       FORWARD_IPV4=false
#                             to
#                       FORWARD_IPV4=true
#
echo "  Enabling forwarding.."
echo "1" > /proc/sys/net/ipv4/ip_forward


# Dynamic IP users:
#
#   If you get your IP address dynamically from SLIP, PPP, or DHCP, 
#   enable the following option.  This enables dynamic-address hacking
#   which makes the life with Diald and similar programs much easier.
#
echo "  Enabling DynamicAddr.."
echo "1" > /proc/sys/net/ipv4/ip_dynaddr

echo "  ---"

#############################################################################
#
# Enable Stronger IP forwarding and Masquerading
#
#  NOTE:  In IPTABLES speak, IP Masquerading is a form of SourceNAT or SNAT.
#
#  NOTE #2:  The following is an example for an internal LAN address in the
#            192.168.0.x network with a 255.255.255.0 or a "24" bit subnet 
#            mask connecting to the Internet on external interface "eth0".  
#            This example will MASQ internal traffic out to the Internet 
#            but not allow non-initiated traffic into your internal network.
#
#            
#         ** Please change the above network numbers, subnet mask, and your 
#         

#Clearing any previous configuration
#
#  Unless specified, the defaults for INPUT, OUTPUT, and FORWARD to DROP
#
#    You CANNOT change this to REJECT as it isn't a vaild policy setting.
#    If you want REJECT, you must explictly REJECT at the end of a giving 
#    INPUT, OUTPUT, or FORWARD chain
#
echo "  Clearing any existing rules and setting default policy to DROP.."
$IPTABLES -P INPUT DROP
$IPTABLES -F INPUT 
$IPTABLES -P OUTPUT DROP
$IPTABLES -F OUTPUT 
$IPTABLES -P FORWARD DROP
$IPTABLES -F FORWARD 
$IPTABLES -F -t nat

#Not needed and it will only load the unneeded kernel module
#
#$IPTABLES -F -t mangle


# Delete all User-specified chains
$IPTABLES -X


# Reset all IPTABLES counters
$IPTABLES -Z


#Configuring specific CHAINS for later use in the ruleset
#
#  NOTE:  Some users prefer to have their firewall silently
#         "DROP" packets while others prefer to use "REJECT"
#         to send ICMP error messages back to the remote 
#         machine.  The default is "REJECT" but feel free to
#         change this below.
#
# NOTE: Without the --log-level set to "info", every single
#       firewall hit will goto ALL vtys.  This is a very big
#       pain.
#
echo "  Creating a DROP chain.."
$IPTABLES -N reject-and-log-it
$IPTABLES -A reject-and-log-it -j LOG --log-level info 
$IPTABLES -A reject-and-log-it -j REJECT

echo -e "\n   - Loading INPUT rulesets"


#######################################################################
# INPUT: Incoming traffic from various interfaces.  All rulesets are 
#        already flushed and set to a default policy of DROP. 
#

# loopback interfaces are valid.
#
$IPTABLES -A INPUT -i lo -s $UNIVERSE -d $UNIVERSE -j ACCEPT


# local interface, local machines, going anywhere is valid
#
$IPTABLES -A INPUT -i $INTIF -s $INTNET -d $UNIVERSE -j ACCEPT


# remote interface, claiming to be local machines, IP spoofing, get lost
#
$IPTABLES -A INPUT -i $EXTIF -s $INTNET -d $UNIVERSE -j reject-and-log-it


# external interface, from any source, for ICMP traffic is valid
#
#  If you would like your machine to "ping" from the Internet, 
#  enable this next line
#
#$IPTABLES -A INPUT -i $EXTIF -p ICMP -s $UNIVERSE -d $EXTIP -j ACCEPT


# remote interface, any source, going to the MASQ servers IP address is valid
#
#  ENABLE this line if you want ALL Internet traffic to connect to your
#  the various servers running on the MASQ server.  This includes 
#  web servers, ssh servers, dns servers, etc.  
#
#  I DON'T recommend you enable this rule.  Instead, only enable specific
#  access to select server ports under the "OPTIONAL INPUT Section".
#  An example of enabling HTTP (WWW) has been given below:
#
#
#$IPTABLES -A INPUT -i $EXTIF -s $UNIVERSE -d $EXTIP -j ACCEPT


# Allow any related traffic coming back to the MASQ server in.
#
#  STATEFULLY TRACKED
#
$IPTABLES -A INPUT -i $EXTIF -s $UNIVERSE -d $EXTIP -m state --state \
 ESTABLISHED,RELATED -j ACCEPT


# ----- Begin OPTIONAL INPUT Section -----
#

# DHCPd - Enable the following lines if you run an INTERNAL DHCPd server
#
#$IPTABLES -A INPUT -i $INTIF -p tcp --sport 68 --dport 67 -j ACCEPT
#$IPTABLES -A INPUT -i $INTIF -p udp --sport 68 --dport 67 -j ACCEPT

# HTTPd - Enable the following lines if you run an EXTERNAL WWW server
#
#    NOTE:  This is NOT needed for simply enabling PORTFW.  This is ONLY 
#           for users that plan on running Apache on the MASQ server itself
#
#echo -e "      - Allowing EXTERNAL access to the WWW server"
#$IPTABLES -A INPUT -i $EXTIF -m state --state NEW,ESTABLISHED,RELATED \
# -p tcp -s $UNIVERSE -d $EXTIP --dport 80 -j ACCEPT

#
# ----- End OPTIONAL INPUT Section -----


# Catch all rule, all other incoming is denied and logged. 
#
$IPTABLES -A INPUT -s $UNIVERSE -d $UNIVERSE -j reject-and-log-it


# ---------------------------------------------------------------------

echo -e "   - Loading OUTPUT rulesets"

#######################################################################
# OUTPUT: Outgoing traffic from various interfaces.  All rulesets are 
#         already flushed and set to a default policy of DROP. 
#

# Workaround bug in netfilter
# See http://www.netfilter.org/security/2002-04-02-icmp-dnat.html
#
$IPTABLES -A OUTPUT -m state -p icmp --state INVALID -j DROP

# loopback interface is valid.
#
$IPTABLES -A OUTPUT -o lo -s $UNIVERSE -d $UNIVERSE -j ACCEPT


# local interfaces, any source going to local net is valid
#
$IPTABLES -A OUTPUT -o $INTIF -s $EXTIP -d $INTNET -j ACCEPT


# local interface, MASQ server source going to the local net is valid
#
$IPTABLES -A OUTPUT -o $INTIF -s $INTIP -d $INTNET -j ACCEPT


# outgoing to local net on remote interface, stuffed routing, deny
#
$IPTABLES -A OUTPUT -o $EXTIF -s $UNIVERSE -d $INTNET -j reject-and-log-it


# anything else outgoing on remote interface is valid
#
$IPTABLES -A OUTPUT -o $EXTIF -s $EXTIP -d $UNIVERSE -j ACCEPT


# ----- Begin OPTIONAL OUTPUT Section -----
#

# DHCPd - Enable the following lines if you run an INTERNAL DHCPd server
#         - Remove BOTH #s all the #s if you need this functionality.
#
#$IPTABLES -A OUTPUT -o $INTIF -p tcp -s $INTIP --sport 67 \
# -d 255.255.255.255 --dport 68 -j ACCEPT
#$IPTABLES -A OUTPUT -o $INTIF -p udp -s $INTIP --sport 67 \
# -d 255.255.255.255 --dport 68 -j ACCEPT

#
# ----- End OPTIONAL OUTPUT Section -----


# Catch all rule, all other outgoing is denied and logged. 
#
$IPTABLES -A OUTPUT -s $UNIVERSE -d $UNIVERSE -j reject-and-log-it


echo -e "   - Loading FORWARD rulesets"

#######################################################################
# FORWARD: Enable Forwarding and thus IPMASQ
#

# ----- Begin OPTIONAL FORWARD Section -----
#
#  Put PORTFW commands here
#
# ----- End OPTIONAL FORWARD Section -----


echo "     - FWD: Allow all connections OUT and only existing/related IN"
$IPTABLES -A FORWARD -i $EXTIF -o $INTIF -m state --state ESTABLISHED,RELATED \
 -j ACCEPT
$IPTABLES -A FORWARD -i $INTIF -o $EXTIF -j ACCEPT

# Catch all rule, all other forwarding is denied and logged. 
#
$IPTABLES -A FORWARD -j reject-and-log-it


echo "     - NAT: Enabling SNAT (MASQUERADE) functionality on $EXTIF"
#
#More liberal form
#$IPTABLES -t nat -A POSTROUTING -o $EXTIF -j MASQUERADE
#
#Stricter form
$IPTABLES -t nat -A POSTROUTING -o $EXTIF -j SNAT --to $EXTIP


#######################################################################
echo -e "\nrc.firewall-iptables-stronger $FWVER done.\n"
<rc.firewall-iptables-stronger STOP>

要在此更强的防火墙规则集在适当的时间自动启动,请参阅第 3.4.2 节末尾了解完整详情。请确保您进行了正确的“rc.firewall-iptables”到“rc.firewall-iptables-stronger”的替换!!


6.4.2. 更强的 IP 防火墙 (IPCHAINS) 规则集

本节提供了更深入的关于使用 2.2.x 防火墙工具 IPCHAINS 的指南。有关 IPFWADM 规则集,请参见以上章节。

此示例适用于 PPP 链路后方的防火墙/地址伪装系统,该链路具有静态 PPP 地址(包含动态 PPP 说明但已禁用)。受信任的接口是 192.168.0.1,并且 PPP 接口 IP 地址已更改以保护责任人 :-)。 我已单独列出每个传入和传出接口,以捕获 IP 欺骗以及伪造的路由和/或地址伪装。 任何未明确允许的内容都是禁止的(实际上是拒绝)。 如果您的 IP MASQ 盒在实施此 rc.firewall-ipchains-stronger 脚本后出现故障,请务必根据您的配置对其进行编辑,并检查您的 /var/log/messages 或 /var/adm/messages SYSLOG 文件中是否有任何防火墙错误。

有关 PPP、有线调制解调器用户等强大的 IP 地址伪装 IPFWADM 规则集的更全面的示例,请参阅TrinityOS - 第 10 节GreatCircle 的防火墙 WWW 页面

注意 #1:--- 更新您的内核 --- 低于 2.2.20 版本的 Linux 2.2.x 内核包含多个不同的安全漏洞(有些是 MASQ 特有的)。 低于 2.2.20 的内核存在一些本地漏洞。 低于 2.2.16 的内核具有 TCP 根利用漏洞,低于 2.2.11 的版本具有 IPCHAINS 分片错误。 由于这些问题,运行具有强大 IPCHAINS 规则集的防火墙的用户可能会受到入侵。 请将您的内核升级到已修复的版本。

注意 #2: 如果您从 ISP 获得动态分配的 TCP/IP 地址(PPP、DSL、有线调制解调器等),您无法在启动时加载此强规则集。 您要么需要每次获得新的 IP 地址时重新加载此防火墙规则集,要么使您的 /etc/rc.d/rc.firewall-ipchains-stronger 规则集更智能。 要为 PPP 或 DHCP 用户等各种类型的连接执行此操作,请参阅第 7.8 节 FAQ 条目以获取所有详细信息。

另请注意,还有一些 GUI 防火墙创建工具可用。 请参阅第 7 章了解完整详情。

最后,如果您使用的是静态 PPP IP 地址,请更改“EXTIF="your.static.PPP.address"”行以反映您的地址。

----------------------------------------------------------------

<rc.firewall-ipchains-stronger START>

#!/bin/sh
#
# /etc/rc.d/rc.firewall-ipchains-stronger: An example of a Stronger IPCHAINS 
#                                          firewall ruleset for 2.2 kernels
#
FWVER=0.75s
#
# Log:
#  0.75s - Updated the commands for dynamically addresses machines and
#           to point to an expanded FAQ section for more information
#
#  0.74s - renamed from rc.firewall-2.2-stronger to
#          rc.firewall-ipchains-stronger to better reflect that this ruleset can 
#          can run on different major kernel versions
#        - removed unused SED variable
#  0.73s - Added additional comments to make PORTFW configs more obvious
#  0.72s - #ed out the rule that would allow all traffic destined for the
#          MASQ server itself to be accepted.  Use the OPTIONAL INPUT 
#          section to only allow explicit services.
#        - Fixed an INTLAN rule that was allowing traffic from ANY IP address
#          instead of the proper INTIP IP address only.  This aligns the 
#          IPCHAINS ruleset with the IPTABLES and IPFWADM ruleset examples
#  0.71s - ruleset now uses modprobe instead of insmod
#  0.70s - Added missing execution variables
#        - fixed a missing -p tcp for the commented HTTPd section
#  0.65s - Added comments HTTPd rules to the INPUT and OUTPUT section
#        - Added a comment where to insert IPPORTFW commands
#  0.60s - Changed the EXTIP command to work on NON-English distros
#        - Updated the CASE of some of the script variables
#

echo -e "\nLoading rc.firewall-ipchains-stronger : version $FWVER..\n"


# The location of various iptables and other shell programs
#
#   If your Linux distribution came with a copy of iptables, most
#   likely it is located in /sbin.  If you manually compiled 
#   iptables, the default location is in /usr/local/sbin
#
# ** Please use the "whereis iptables" command to figure out 
# ** where your copy is and change the path below to reflect 
# ** your setup
#
IPCHAINS=/sbin/ipchains
LSMOD=/sbin/lsmod
DEPMOD=/sbin/depmod
MODPROBE=/sbin/modprobe
GREP=/bin/grep
AWK=/bin/awk
IFCONFIG=/sbin/ifconfig

PATH=/sbin:/bin:/usr/sbin:/usr/bin


# Global variables
# ----------------

# ALL PPP and DHCP users must set this for the correct EXTERNAL and
#  INTERNAL interfaces names.  Examples:  eth0, ppp0, ippp0, etc.
#  See more info about this below.
#
EXTIF="ppp0"
INTIF="eth0"

# The INTERNAL IP address
#
INTIP="192.168.0.1/32"
INTNET="192.168.0.0/24"
echo "  Internal IP:      $INTIP"
echo "  Internal Network: $INTNET"



# Load all required IP MASQ modules
#
#   NOTE:  Only load the IP MASQ modules you need.  All current IP MASQ modules
#          are shown below but are commented from loading.

# Needed to initially load modules
#
$DEPMOD -a

# Supports the proper masquerading of FTP file transfers using the PORT method
#
$MODPROBE ip_masq_ftp

# Supports the masquerading of RealAudio over UDP.  Without this module,
#       RealAudio WILL function but in TCP mode.  This can cause a reduction
#       in sound quality
#
$MODPROBE ip_masq_raudio

# Supports the masquerading of IRC DCC file transfers
#
#$MODPROBE ip_masq_irc


# Supports the masquerading of Quake and QuakeWorld by default.  These modules are
#   for multiple users behind the Linux MASQ server.  If you are going to 
#   play Quake I, II, and III, use the second example.
#
#   NOTE:  If you get ERRORs loading the QUAKE module, you are running an old
#   -----  kernel that has bugs in it.  Please upgrade to the newest kernel.
#
#Quake I / QuakeWorld (ports 26000 and 27000)
#$MODPROBE ip_masq_quake
#
#Quake I/II/III / QuakeWorld (ports 26000, 27000, 27910, 27960)
#$MODPROBE ip_masq_quake 26000,27000,27910,27960


# Supports the masquerading of the CuSeeme video conferencing software
#
#$MODPROBE ip_masq_cuseeme

#Supports the masquerading of the VDO-live video conferencing software
#
#$MODPROBE ip_masq_vdolive


#CRITICAL:  Enable IP forwarding since it is disabled by default
#
#           Redhat Users:  you may try changing the options in 
#                          /etc/sysconfig/network from:
#
#                       FORWARD_IPV4=false
#                             to
#                       FORWARD_IPV4=true
#
echo "1" > /proc/sys/net/ipv4/ip_forward


#CRITICAL:  Enable automatic IP defragmentation since it is disabled by default 
#           in 2.2.x kernels 
#
#           This used as a compile-time option but the behavior was changed 
#           in 2.2.12.  It should also be noted that some distributions have
#           removed this option from the /proc table.  If this entry isn't
#           present in your /proc, don't worry about it.
#
echo "1" > /proc/sys/net/ipv4/ip_always_defrag


# Dynamic IP users:
#
#   If you get your IP address dynamically from SLIP, PPP, or DHCP, enable this 
#   following option.  This enables dynamic-ip address hacking in IP MASQ, 
#   making life with Diald and similar programs much easier.
#
#echo "1" > /proc/sys/net/ipv4/ip_dynaddr


# Enable the LooseUDP patch which some Internet-based games require
#
#  If you are trying to get an Internet game to work through your IP MASQ box,
#  and you configured it to the best of your ability without it working, try
#  enabling this option (delete the "#" character).  This option is disabled
#  by default due to possible internal machine UDP port scanning
#  vulnerabilities.
#
#echo "1" > /proc/sys/net/ipv4/ip_masq_udp_dloose


# Specify your Static IP address here.
#
#   If you have a DYNAMIC IP address, you need to make this ruleset recognize 
#   your IP address everytime you get a new IP.  To do this, enable the 
#   following one-line script.  (Please note that the different single and 
#   double quote characters MATTER).
#
#
#   DHCP users (Cablemodem and DSL ) users:
#   ---------------------------------------
#   If you get your TCP/IP address via DHCP, **you will need ** to enable the 
#   #ed out command below underneath the PPP section AND replace the word 
#   "ppp0" with the name of your EXTERNAL Internet connection (eth0, eth1, etc) 
#   on the lines for "ppp-ip" and "EXTIP".  
#
#   DHCP and PPP users:  The remote DHCP or PPP server can and will change
#   IP addresses on you over time.  To deal with this, users should configure
#   their DHCP or PPP client to re-run the rc.firewall-* ruleset everytime
#   the IP address is changed.  Please see the "masq-and-dyn-addr" FAQ entry
#   in the IPMASQ howto for full details on how to do this.
#
#
# Determine the external IP automatically:
# ----------------------------------------
#
#  The following line will determine your external IP address.  This
#  line is somewhat complex and confusing but it will also work for
#  all NON-English Linux distributions.
#
#   Make sure the EXTIF variable above is set to reflect the name
#   of your Internet connection
#
EXTIP="`$IFCONFIG $EXTIF | $AWK \
 /$EXTIF/'{next}//{split($0,a,":");split(a[2],a," ");print a[1];exit}'`"



# MASQ timeouts
#
#   2 hrs timeout for TCP session timeouts
#  10 sec timeout for traffic after the TCP/IP "FIN" packet is received
#  60 sec timeout for UDP traffic (MASQ'ed ICQ users must enable a 30sec 
#     firewall timeout in ICQ itself)
#
$IPCHAINS -M -S 7200 10 60

#############################################################################
# Incoming, flush and set default policy of reject. Actually the default policy
# is irrelevant because there is a catch all rule with deny and log.
#
$IPCHAINS -F input
$IPCHAINS -P input REJECT

# local interface, local machines, going anywhere is valid
#
$IPCHAINS -A input -i $INTIF -s $INTNET -d 0.0.0.0/0 -j ACCEPT

# remote interface, claiming to be local machines, IP spoofing, get lost
#
$IPCHAINS -A input -i $EXTIF -s $INTNET -d 0.0.0.0/0 -l -j REJECT


# remote interface, any source, going to the MASQ servers IP address is valid
#
#  ENABLE this line if you want ALL Internet traffic to connect to your
#  the various servers running on the MASQ server.  This includes 
#  web servers, ssh servers, dns servers, etc.  
#
#  I DON'T recommend you enable this rule.  Instead, only enable specific
#  access to select server ports under the "OPTIONAL INPUT Section".
#  An example of enabling HTTP (WWW) has been given below:
#
#
#$IPCHAINS -A input -i $EXTIF -s 0.0.0.0/0 -d $EXTIP/32 -j ACCEPT


# loopback interface is valid.
#
$IPCHAINS -A input -i lo -s 0.0.0.0/0 -d 0.0.0.0/0 -j ACCEPT


# ----- Begin OPTIONAL INPUT Section -----
#

# HTTPd - Enable the following lines if you either run a WWW server on
#         the IPMASQ server -OR- plan on PORTFW'ing HTTP traffic to
#         an internal WWW server
#
#$IPCHAINS -A input -i $EXTIF -p tcp -s 0.0.0.0/0 -d $EXTIP 80 -j ACCEPT

#
# ----- End OPTIONAL INPUT Section -----


# catch all rule, all other incoming is denied and logged. pity there is no
# log option on the policy but this does the job instead.
#
$IPCHAINS -A input -s 0.0.0.0/0 -d 0.0.0.0/0 -l -j REJECT

#############################################################################
# Outgoing, flush and set default policy of reject. Actually the default policy
# is irrelevant because there is a catch all rule with deny and log.
#
$IPCHAINS -F output
$IPCHAINS -P output REJECT

# local interface, MASQ server source going to the local net is valid
#
$IPCHAINS -A output -i $INTIF -s $INTIP -d $INTNET -j ACCEPT

# outgoing to local net on remote interface, stuffed routing, deny
#
$IPCHAINS -A output -i $EXTIF -s 0.0.0.0/0 -d $INTNET -l -j REJECT

# outgoing from local net on remote interface, stuffed masquerading, deny
#
$IPCHAINS -A output -i $EXTIF -s $INTNET -d 0.0.0.0/0 -l -j REJECT

# anything else outgoing on remote interface is valid
#
$IPCHAINS -A output -i $EXTIF -s $EXTIP/32 -d 0.0.0.0/0 -j ACCEPT

# loopback interface is valid.
#
$IPCHAINS -A output -i lo -s 0.0.0.0/0 -d 0.0.0.0/0 -j ACCEPT


# ----- Begin OPTIONAL OUTPUT Section -----
#

# HTTPd - Enable the following lines if you either run a WWW server on
#         the IPMASQ server -OR- plan on PORTFW'ing HTTP traffic to
#         an internal WWW server
#
#$IPCHAINS -A output -i $EXTIF -p tcp -s $EXTIP 80 -d 0.0.0.0/0 -j ACCEPT

#
# ----- End OPTIONAL OUTPUT Section -----

# catch all rule, all other outgoing is denied and logged. pity there is no
# log option on the policy but this does the job instead.
#
$IPCHAINS -A output -s 0.0.0.0/0 -d 0.0.0.0/0 -l -j REJECT

#############################################################################
# Forwarding, flush and set default policy of deny. Actually the default policy
# is irrelevant because there is a catch all rule with deny and log.
#
$IPCHAINS -F forward
$IPCHAINS -P forward DENY


# ----- Begin OPTIONAL FORWARD Section -----
#
#   Put PORTFW commands here
#
# ----- End OPTIONAL FORWARD Section -----


# Masquerade from local net on local interface to anywhere.
#
$IPCHAINS -A forward -i $EXTIF -s $INTNET -d 0.0.0.0/0 -j MASQ
#
# catch all rule, all other forwarding is denied and logged. pity there is no
# log option on the policy but this does the job instead.
#
$IPCHAINS -A forward -s 0.0.0.0/0 -d 0.0.0.0/0 -l -j REJECT

#End of file.
<rc.firewall-ipchains-stronger STOP>

要在此更强的防火墙规则集在适当的时间自动启动,请参阅第 3.4.2 节末尾了解完整详情。请确保您进行了正确的“rc.firewall-ipchains”到“rc.firewall-ipchains-stronger”的替换!!

使用 IPCHAINS,您可以使用“input”、“output”和/或“forward”规则阻止到特定站点的流量。 请记住,规则集从上到下扫描,“-A”告诉 IPCHIANS 将此新规则“附加”到现有规则集。 因此,考虑到这一点,任何特定限制都需要在任何全局规则之前出现。 例如

使用“input”规则

可能是阻止流量最快、最有效的方法,但此方法仅阻止经过 MASQ 的机器,而不阻止防火墙机器本身。 当然,您可能希望允许这种组合。

无论如何,要阻止 204.50.10.13

In the /etc/rc.d/rc.firewall-ipchains-stronger ruleset:
... start of "input" rules ...

# reject and log local interface, local machines going to 204.50.10.13
#
ipchains -A input -s 192.168.0.0/24 -d 204.50.10.13/32 -l -j REJECT


# local interface, local machines, going anywhere is valid
#
ipchains -A input -s 192.168.0.0/24 -d 0.0.0.0/0 -l -j ACCEPT


... end of "input" rules ...

使用“output”规则

这是阻止流量的较慢方法,因为数据包必须先经过地址伪装,然后才能被丢弃。 然而,此规则甚至阻止防火墙机器访问被禁止的站点。

... “output”规则的开始 ... # 拒绝并记录到 204.50.10.13 的传出 # ipchains -A output -s $ppp_ip/32 -d 204.50.10.13/32 -l -j REJECT # 远程接口上的任何其他传出都是有效的 # ipchains -A output -s $ppp_ip/32 -d 0.0.0.0/0 -l -j ACCEPT ... “output”规则的结束 ...

使用“forward”规则

可能比用于阻止流量的“input”规则慢,这仅阻止经过地址伪装的机器(例如,内部机器)。 防火墙机器仍然可以访问被禁止的站点。

... “forward”规则的开始 ... # 拒绝并记录从 PPP 接口上的本地网络到 204.50.10.13 的流量。 # ipchains -A forward -i ppp0 -s 192.168.0.0/24 -d 204.50.10.13/32 -l -j REJECT # 从本地接口上的本地网络到任何地方的地址伪装。 # ipchains -A forward -i ppp0 -s 192.168.0.0/24 -d 0.0.0.0/0 -j MASQ ... “forward”规则的结束 ...

无需特殊规则来允许 192.168.0.0/24 网络上的机器访问 204.50.11.0。 为什么? 它已包含在全局 MASQ 规则中。

注意:与 IPFWADM 不同,IPCHIANS 只有一种编码接口名称的方式。 IPCHAINS 使用“-i eth0”选项,而 IPFWADM 同时具有用于接口名称的“-W”和用于接口 IP 地址的“-V”。


6.4.3. 更强的 IP 防火墙 (IPFWADM) 规则集

本节提供了更深入的关于使用 2.0.x 防火墙工具 IPFWADM 的指南。 有关 IPCHAINS 规则集,请参见下文

此示例适用于 PPP 链路后方的防火墙/地址伪装系统,该链路具有静态 PPP 地址(包含动态 PPP 说明但已禁用)。受信任的接口是 192.168.0.1,并且 PPP 接口 IP 地址已更改以保护责任人 :)。 我已单独列出每个传入和传出接口,以捕获 IP 欺骗以及伪造的路由和/或地址伪装。 任何未明确允许的内容都是禁止的(实际上是拒绝)。 如果您的 IP MASQ 盒在实施此 rc.firewall-ipfwadm-stronger 脚本后出现故障,请务必根据您的配置对其进行编辑,并检查您的 /var/log/messages 或 /var/adm/messages SYSLOG 文件中是否有任何防火墙错误。

有关 PPP、有线调制解调器用户等强大的 IP 地址伪装 IPFWADM 规则集的更全面的示例,请参阅TrinityOS - 第 10 节GreatCircle 的防火墙 WWW 页面

注意 #2: 如果您从 ISP 获得动态分配的 TCP/IP 地址(PPP、DSL、有线调制解调器等),您无法在启动时加载此强规则集。 您要么需要每次获得新的 IP 地址时重新加载此防火墙规则集,要么使您的 /etc/rc.d/rc.firewall-ipchains-stronger 规则集更智能。 要为 PPP 或 DHCP 用户等各种类型的连接执行此操作,请参阅第 7.8 节 FAQ 条目以获取所有详细信息。

另请注意,还有一些 GUI 防火墙创建工具可用。 请参阅第 7 章了解完整详情。

最后,如果您使用的是静态 PPP IP 地址,请更改“ppp_ip="your.static.PPP.address"”行以反映您的地址。

----------------------------------------------------------------

<rc.firewall-ipfwadm-stronger START>

#!/bin/sh
#
# /etc/rc.d/rc.firewall-ipfwadm-stronger: An example of a semi-STRONG 
#                                         IPFWADM firewall ruleset for 2.0 kernels
#
FWVER=0.74s
#
# Log:
#  0.74s - Updated the commands for dynamically addresses machines and
#           to point to an expanded FAQ section for more information
#
#  0.73s - renamed from rc.firewall-2.0-stronger to
#          rc.firewall-ipfwadm-stronger
#
#  0.72s - #ed out the rule that would allow all traffic destined for the
#          MASQ server itself to be accepted.  Use the OPTIONAL INPUT 
#          section to only allow explicit services.


PATH=/sbin:/bin:/usr/sbin:/usr/bin

# testing, wait a bit then clear all firewall rules.
# uncomment the following lines if you want the firewall to automatically
# disable after 10 minutes.
#
# Disabled by default
#
# (sleep 600; \
# ipfwadm -I -f; \
# ipfwadm -I -p accept; \
# ipfwadm -O -f; \
# ipfwadm -O -p accept; \
# ipfwadm -F -f; \
# ipfwadm -F -p accept; \
# ) &


# Load all required IP MASQ modules
#
#   NOTE:  Only load the IP MASQ modules you need.  All current IP MASQ modules
#          are shown below but are commented from loading.

# Needed to initially load modules
#
/sbin/depmod -a

# Supports the proper masquerading of FTP file transfers using the PORT method
#
/sbin/modprobe ip_masq_ftp

# Supports the masquerading of RealAudio over UDP.  Without this module,
#       RealAudio WILL function but in TCP mode.  This can cause a reduction
#       in sound quality
#
#/sbin/modprobe ip_masq_raudio

# Supports the masquerading of IRC DCC file transfers
#
#/sbin/modprobe ip_masq_irc


# Supports the masquerading of Quake and QuakeWorld by default.  This modules is
#   for multiple users behind the Linux MASQ server.  If you are going to 
#   play Quake I, II, and III, use the second example.
#
#   NOTE:  If you get ERRORs loading the QUAKE module, you are running an old
#   -----  kernel that has bugs in it.  Please upgrade to the newest kernel.
#
#Quake I / QuakeWorld (ports 26000 and 27000)
#/sbin/modprobe ip_masq_quake
#
#Quake I/II/III / QuakeWorld (ports 26000, 27000, 27910, 27960)
#/sbin/modprobe ip_masq_quake 26000,27000,27910,27960


# Supports the masquerading of the CuSeeme video conferencing software
#
#/sbin/modprobe ip_masq_cuseeme

#Supports the masquerading of the VDO-live video conferencing software
#
#/sbin/modprobe ip_masq_vdolive


#CRITICAL:  Enable IP forwarding, since it is disabled by default
#
#           Redhat Users:  you may try changing the options in /etc/sysconfig/network 
#                          from:
#
#                       FORWARD_IPV4=false
#                             to
#                       FORWARD_IPV4=true
#
echo "1" > /proc/sys/net/ipv4/ip_forward


#CRITICAL:  Enable automatic IP defragmenting since it is disabled by default 
#           in 2.2.x kernels
#
#           This used to be a compile-time option but the behavior was changed 
#           in 2.2.12
#
echo "1" > /proc/sys/net/ipv4/ip_always_defrag


# Dynamic IP users:
#
#   If you get your IP address dynamically from SLIP, PPP, or DHCP, enable this 
#   following option.  This allows dynamic-ip address hacking in IP MASQ, 
#   making the life with Diald and similar programs much easier.
#
#echo "1" > /proc/sys/net/ipv4/ip_dynaddr


# Specify your Static IP address here.  
#
#   If you have a DYNAMIC IP address, you need to make this ruleset understand 
#   your IP address everytime you get a new IP.  To do this, enable the 
#   following one-line script.  (Please note that the different single and 
#   double quote characters MATTER).  
#
#
#   DHCP (Cablemodem and DSL) and PPP users:  
#   ----------------------------------------
#   If you get your TCP/IP address a dynamic IP address **you will need ** to 
#   enable the #ed out command below underneath the PPP section AND replace the word 
#   "ppp0" with the name of your EXTERNAL Internet connection (eth0, eth1, 
#   etc).  
#
#   DHCP and PPP users:  The remote DHCP or PPP server can and will change
#   IP addresses on you over time.  To deal with this, users should configure
#   their DHCP or PPP client to re-run the rc.firewall-* ruleset everytime
#   the IP address is changed.  Please see the "masq-and-dyn-addr" FAQ entry
#   in the IPMASQ howto for full details on how to do this.
#
#
# PPP and DHCP Users: 
# -------------------
# Remove the # on the line below and place a # in front of the line after that.
#
#ppp_ip="`/sbin/ifconfig ppp0 | grep 'inet addr' | awk '{print $2}' | sed -e 's/.*://'`"
#
ppp_ip="your.static.PPP.address"


# MASQ timeouts 
#
#   2 hrs timeout for TCP session timeouts
#  10 sec timeout for traffic after the TCP/IP "FIN" packet is received
#  60 sec timeout for UDP traffic (MASQ'ed ICQ users must enable a 30sec 
#     firewall timeout in ICQ itself) 
#
/sbin/ipfwadm -M -s 7200 10 60


#############################################################################
# Incoming, flush and set default policy of reject. Actually the default policy
# is irrelevant because there is a catch all rule with deny and log.
#
/sbin/ipfwadm -I -f
/sbin/ipfwadm -I -p reject

# local interface, local machines, going anywhere is valid
#
/sbin/ipfwadm -I -a accept -V 192.168.0.1 -S 192.168.0.0/24 -D 0.0.0.0/0

# remote interface, claiming to be local machines, IP spoofing, get lost
#
/sbin/ipfwadm -I -a reject -V $ppp_ip -S 192.168.0.0/24 -D 0.0.0.0/0 -o


# remote interface, any source, going to the MASQ servers IP address is valid
#
#  ENABLE this line if you want ALL Internet traffic to connect to your
#  the various servers running on the MASQ server.  This includes 
#  web servers, ssh servers, dns servers, etc.  
#
#  I DON'T recommend you enable this rule.  Instead, only enable specific
#  access to select server ports under the "OPTIONAL INPUT Section".
#  An example of enabling HTTP (WWW) has been given below:
#
#
#/sbin/ipfwadm -I -a accept -V $ppp_ip -S 0.0.0.0/0 -D $ppp_ip/32


# loopback interface is valid.
#
/sbin/ipfwadm -I -a accept -V 127.0.0.1 -S 0.0.0.0/0 -D 0.0.0.0/0


# catch all rule, all other incoming is denied and logged. pity there is no
# log option on the policy but this does the job instead.
#
/sbin/ipfwadm -I -a reject -S 0.0.0.0/0 -D 0.0.0.0/0 -o


#############################################################################
# Outgoing, flush and set default policy of reject. Actually the default policy
# is irrelevant because there is a catch all rule with deny and log.
#
/sbin/ipfwadm -O -f
/sbin/ipfwadm -O -p reject

# local interface, MASQ server source going to the local net is valid
#
/sbin/ipfwadm -O -a accept -V 192.168.0.1 -S 0.0.0.0/0 -D 192.168.0.0/24

# outgoing to local net on remote interface, stuffed routing, deny
#
/sbin/ipfwadm -O -a reject -V $ppp_ip -S 0.0.0.0/0 -D 192.168.0.0/24 -o

# outgoing from local net on remote interface, stuffed masquerading, deny
#
/sbin/ipfwadm -O -a reject -V $ppp_ip -S 192.168.0.0/24 -D 0.0.0.0/0 -o

# outgoing from local net on remote interface, stuffed masquerading, deny
#
/sbin/ipfwadm -O -a reject -V $ppp_ip -S 0.0.0.0/0 -D 192.168.0.0/24 -o

# anything else outgoing on remote interface is valid
#
/sbin/ipfwadm -O -a accept -V $ppp_ip -S $ppp_ip/32 -D 0.0.0.0/0

# loopback interface is valid.
#
/sbin/ipfwadm -O -a accept -V 127.0.0.1 -S 0.0.0.0/0 -D 0.0.0.0/0

# catch all rule, all other outgoing is denied and logged. pity there is no
# log option on the policy but this does the job instead.
#
/sbin/ipfwadm -O -a reject -S 0.0.0.0/0 -D 0.0.0.0/0 -o


#############################################################################
# Forwarding, flush and set default policy of deny. Actually the default policy
# is irrelevant because there is a catch all rule with deny and log.
#
/sbin/ipfwadm -F -f
/sbin/ipfwadm -F -p reject

# Masquerade from local net on local interface to anywhere.
#
/sbin/ipfwadm -F -a masquerade -W ppp0 -S 192.168.0.0/24 -D 0.0.0.0/0
#
# catch all rule, all other forwarding is denied and logged.  Pity there is no
# log option on the policy but this does the job instead.
#
/sbin/ipfwadm -F -a reject -S 0.0.0.0/0 -D 0.0.0.0/0 -o

#End of file.
<rc.firewall-ipfwadm-stronger STOP>

要在此更强的防火墙规则集在适当的时间自动启动,请参阅第 3.4.3 节末尾了解完整详情。请确保您进行了正确的“rc.firewall-ipfwadm”到“rc.firewall-ipfwadm-stronger”的替换!!

使用 IPFWADM,您可以使用 -I、-O 或 -F 规则阻止到特定站点的流量。 请记住,规则集从上到下扫描,“-a”告诉 IPFWADM 将此新规则“附加”到现有规则集。 因此,考虑到这一点,任何特定限制都需要在全局规则之前出现。 例如

使用 -I(输入)规则

可能是阻止流量最快、最有效的方法,但它仅阻止经过 MASQ 的机器,而不阻止防火墙机器本身。 当然,您可能希望允许这种组合。

无论如何,要阻止 204.50.10.13

在 /etc/rc.d/rc.firewall-ipfwadm-stronger 规则集中:... -I 规则的开始 ... # 拒绝并记录本地接口,本地机器访问 204.50.10.13 # /sbin/ipfwadm -I -a reject -V 192.168.0.1 -S 192.168.0.0/24 -D 204.50.10.13/32 -o # 本地接口,本地机器,访问任何地方都是有效的 # /sbin/ipfwadm -I -a accept -V 192.168.0.1 -S 192.168.0.0/24 -D 0.0.0.0/0 ... -I 规则的结束 ...

使用 -O(输出)规则

这是阻止流量的较慢方法,因为数据包在被丢弃之前首先要经过地址伪装。 然而,此规则甚至阻止防火墙机器访问被禁止的站点。

... -O 规则的开始 ... # 拒绝并记录到 204.50.10.13 的传出 # /sbin/ipfwadm -O -a reject -V $ppp_ip -S $ppp_ip/32 -D 204.50.10.13/32 -o # 远程接口上的任何其他传出都是有效的 # /sbin/ipfwadm -O -a accept -V $ppp_ip -S $ppp_ip/32 -D 0.0.0.0/0 ... -O 规则的结束 ...

使用 -F(转发)规则

可能比 -I(输入)规则更慢,用于阻止流量,这仍然仅阻止经过地址伪装的机器(例如,内部机器)。 防火墙机器仍然可以访问被禁止的站点。

... -F 规则的开始 ... # 拒绝并记录从 PPP 接口上的本地网络到 204.50.10.13 的流量。 # /sbin/ipfwadm -F -a reject -W ppp0 -S 192.168.0.0/24 -D 204.50.10.13/32 -o # 从本地接口上的本地网络到任何地方的地址伪装。 # /sbin/ipfwadm -F -a masquerade -W ppp0 -S 192.168.0.0/24 -D 0.0.0.0/0 ... -F 规则的结束 ...

无需特殊规则来允许 192.168.0.0/24 网络上的机器访问 204.50.11.0。 为什么? 它已包含在全局 MASQ 规则中。

注意:在上述规则中,编码接口的方式不止一种。 例如,可以使用“-W eth0”代替“-V 192.168.255.1”,可以使用“-W ppp0”代替“-V $ppp_ip”。 “-V”方法已随着迁移到 IPCHAINS 而逐步淘汰,但对于 IPFWADM 用户来说,这更多的是个人选择和文档。


6.5. IP 地址伪装多个内部网络

地址伪装多个内部网络相当简单。 您首先需要确保所有网络都运行正常(内部和外部)。 然后,您需要启用流量以传递到其他内部接口并被地址伪装到 Internet。

接下来,您需要在内部接口上启用地址伪装。 此示例总共使用三个接口:EXTIF 代表 eth0 接口,它是到 Internet 的外部连接。 INTIF 代表 eth1 接口,是 192.168.0.0 网络。 最后,INTIF2 代表 eth2 接口,是 192.168.1.0 网络。 INTIF 和 INTIF2 都将从接口 eth0 或 EXTIF 地址伪装出去。 在您的 rc.firewall-* 规则集中,紧邻现有 MASQ 的规则集末尾,添加以下内容


6.5.1. iptables 支持多个内部局域网

  • # 2.6.x and 2.4.x kernels with IPTABLES
    #
    # The following rules build upon the rc.firewall-iptables-stronger ruleset.
    # Please see that ruleset in Section 6 for how all variables get set, etc.
    
    
      #Enable internal interfaces to communication between each other
      #
      $IPTABLES -A FORWARD -i $EXTIF -o $INTIF2 -m state --state ESTABLISHED,RELATED \
     -j ACCEPT
      $IPTABLES -A FORWARD -i $INTIF -o $INTIF2 -m state --state ESTABLISHED,RELATED \
     -j ACCEPT
      $IPTABLES -A FORWARD -i $INTIF2 -o $INTIF -m state --state ESTABLISHED,RELATED \
     -j ACCEPT
    
      $IPTABLES -t nat -A POSTROUTING -o $EXTIF -j SNAT --to $EXTIP
         


6.5.2. ipchains 支持多个内部局域网

  • # 2.2.x kernels with IPCHAINS
    #
    # The following rules build upon the rc.firewall-ipchains-stronger ruleset.
    # Please see that ruleset in Section 6 for how all variables get set, etc.
    
      #Enable internal interfaces to communication between each other
      $IPCHAINS -A forward -i eth1 -d 192.168.0.0/24 -j ACCEPT
      $IPCHAINS -A forward -i eth2 -d 192.168.1.0/24 -j ACCEPT
    
      #Enable internal interfaces to MASQ out to the Internet
      $IPCHAINS -A forward -j MASQ -i eth0 -s 192.168.0.0/24 -d 0.0.0.0/0
      $IPCHAINS -A forward -j MASQ -i eth0 -s 192.168.1.0/24 -d 0.0.0.0/0
         


6.5.3. ipfwadm 支持多个内部局域网

  • # 2.0.x kernels with IPFWADM
    #
    # The following rules build upon the rc.firewall-ipfwadm-stronger ruleset.
    # Please see that ruleset in Section 6 for how all variables get set, etc.
    
      #Enable internal interfaces to communication between each other
      /sbin/ipfwadm -F -a accept -V 192.168.0.1 -D 192.168.1.0/24
      /sbin/ipfwadm -F -a accept -V 192.168.1.1 -D 192.168.0.0/24
    
      #Enable internal interfaces to MASQ out to the Internet 
      /sbin/ipfwadm -F -a masq -W eth0 -S 192.168.0.0/24 -D 0.0.0.0/0
      /sbin/ipfwadm -F -a masq -W eth0 -S 192.168.1.0/24 -D 0.0.0.0/0
         

请注意,在上面显示的示例中多次指定“eth0”是正确的。 原因是 Linux 内核需要知道哪个接口用于传出流量。 由于在上面的示例中 eth0 是 Internet 连接,因此为每个内部接口列出它。


6.6. IP 地址伪装和按需拨号连接

  1. 如果您想设置您的网络以自动拨号连接 Internet,则 Diald 按需拨号或新版本的 PPPd 软件包将非常有用。 Diald 和 PPPd 在其配置灵活性方面都非常强大。

  2. 要设置用于按需拨号的 PPPd,请查看PPPd 主页

  3. 要设置 Diald,请查看Diald 主页TrinityOS - 第 23 节

  4. 一旦正确设置了按需拨号和 IP Masq,任何启动 web、telnet 或 ftp 会话的经过 MASQ 的客户端机器都将使 Linux 盒动态地建立其 Internet 链接。

  5. 第一个连接会出现超时。 如果您使用的是模拟调制解调器,这是不可避免的。 建立调制解调器链接和 PPP 连接所需的时间可能会导致您的客户端程序(WWW 浏览器等)停止。 但这并不常见。 如果确实发生这种情况,只需再次重试 Internet 流量请求(例如 WWW 页面),它应该可以正常工作。 您也可以尝试设置 echo "1" > /proc/sys/net/ipv4/ip_dynaddr 内核选项以帮助进行初始设置。


6.7. 使用 IPTABLES 或外部工具(如 IPPORTFW、IPMASQADM、IPAUTOFW、REDIR、UDPRED 和其他端口转发工具)进行端口转发

IPTABLES 以及 IPPORTFW、IPAUTOFW、REDIR、UDPRED 和其他程序为 Linux IP 地址伪装提供通用的 TCP 和/或 UDP 端口转发。 这些工具通常与特定的 IP MASQ 模块一起使用或作为其替代品,以使特定的网络流量通过 MASQ 服务器。

通过端口转发器,您可以将来自 Internet 的数据连接重定向到 IP MASQ 服务器后面的内部、私有寻址的机器。 此转发功能包括网络协议,例如 TELNET、WWW 和 SMTP。 FTP、旧版 ICQ 和其他协议需要通过内核模块进行特殊处理(见下文)。

注意:如果您只是想进行简单的端口转发,但不需要地址伪装支持,您别无选择。 您仍然需要在内核中启用 IP 地址伪装支持,并运行 IPTABLES、IPCHAINS 或 IPFWADM 规则集才能使用 Linux 的端口转发工具。

那么为什么有这么多不同的选择呢? IPTABLES、IPPORTFW、MARK (MFW)、IPMASQADM (PORTFW 或 AUTOFW)、IPAUTOFW、REDIR 和 UDPRED(所有 URL 都在第 3.2.3 节中)是 IP MASQ 用户可用的各种工具,可以根据他们的内核版本实现此类功能。 后来,随着 Linux IP 地址伪装功能的成熟,许多这些工具最终被 IPTABLES 或 PORTFW 和 MARK 系统取代,这些系统是更智能的解决方案。

对于较新的 2.2.x 内核,IPMASQADM 工具将旧版 IPAUTOFW 和 IPPORTFW 2.0.x 内核工具合并为一个二进制文件。 用于 2.2.x 内核的 IPMASQADM 工具以及用于 2.6.x 和 2.4.x 内核的 IPTABLES 也支持一种称为“MARK”或 MFW 的新机制,用于 PORTFW 功能。 MARK 系统的工作原理是,特定的 IPTABLES 或 IPCHAINS 规则集将匹配给定的数据包序列。 匹配后,该工具将“标记”这些数据包。 稍后,可以指示 IPMASQADM 工具或特定的 IPTABLE“表”根据需要更改这些数据包,并将它们转发到所需的内部目标。 目前,本 HOWTO 未涵盖 MARK 解决方案,但将来会涵盖。

无论如何,由于较新工具的可用性,*强烈建议*不要使用旧工具,例如 IPAUTOFW(甚至 IPMASQADM 中的 AUTOFW)和 REDIR,因为它们没有正确地通知 Linux 内核它们的存在,并且最终可能在极端使用情况下崩溃您的 Linux 服务器。

注意 #2:在任何 2.2/2.0 Linux 内核中启用 PORTFW 功能(2.6.x. 和 2.4.x 用户无论如何都不会使用这些特定工具),内部机器通常不能使用相同的“外部”PORTFWed IP 地址来访问给定的内部机器。 换句话说,PORTFW 仅旨在与 Internet 上的“外部”计算机一起使用。 如果这对您来说是一个问题,您也可以对旧的 2.2.x 和 2.0.x 内核使用 REDIR 工具,以使内部机器也被重定向到内部服务器。 运行 IPTABLES 的 2.6.x 和 2.4.x 内核用户一劳永逸地解决了这个问题,并在下面的第 7.19 节中的 FAQ 条目中得到了充分说明。 如果您想了解为什么这种内部/外部转发不起作用的技术解释,请向下翻页到 2.2.x PORTFW 部分的底部,以查看 Juan Jose Ciarlante 的注释。

注意 #3:将非 NAT 友好流量(例如 FTP 服务器流量)转发到内部 MASQed FTP 服务器,称为 PORTFW FTP,现在在 2.6.x 和 2.4.x 内核以及 2.2.x 内核中完全支持,通过 BETA 版本 FTP 内核模块(不随附 Linus 库存内核)。 还应该注意的是,您还可以使用外部 FTP 代理程序转发 FTP 流量(本 HOWTO 中未涵盖)。 应该注意的是,Beta 2.2.x FTP 内核模块代码仍处于实验阶段,并且与被动连接相比,有些人通过简单地使用主动 FTP 会话获得了更好的结果。 有趣的是,其他人看到了完全相反的行为。 请告知我们您的结果如何。 下面的 2.2.x 和 2.0.x 部分都对此进行了更多介绍,因为解决方案需要使用不同的补丁。

警告! 在立即开始安装这些工具中的任何一个之前,需要提到的是,网络安全可能是 ANY PORT FORWARD 工具的一个问题。 原因是这些工具基本上在强大的数据包防火墙中为所需的 TCP/UDP 端口创建了一个漏洞。 虽然这对您的 Linux 机器没有任何威胁,但对于 PORTFW'ed 内部机器来说可能是一个问题。 不过不用担心,这就是 Steven Clarke(IPPORTFW 的作者)对此的看法

   "Port Forwarding is only called within masquerading functions so it 
   fits inside the same IPFWADM/IPCHAINS rules. Masquerading is an extension to 
   IP forwarding. Therefore, ipportfw only sees a packet if it fits 
   both the input and masquerading ipfwadm rule sets."

用英语来说,这意味着如果您运行强大的数据包防火墙,PORTFW 不会直接绕过任何安全性。 如果您愿意,您仍然可以允许或拒绝特定的 IP 和/或域访问此新的 PORTFW'ed 资源。

话虽如此,拥有强大的防火墙规则集非常重要。 请参阅第 6.4.1 节第 6.4.2 节第 6.4.3 节,以了解有关获取强大规则集的更多详细信息。

  • 2.6.x 和 2.4.x 内核已内置 PORTFW 功能,使用 IPTABLES 工具。 2.2.x 和 2.0.x 内核用户将需要重新编译 Linux 内核以支持 PORTFW。 应该注意的是,某些 Linux 发行版内核可能已经为您完成了此操作。

  • 最新的 2.2.x 内核用户已经可以使用 PORTFW 内核选项,尽管您可能仍然需要通过正常的内核“make”过程重新编译内核。

  • 2.0.x 用户将需要应用一个简单的内核选项补丁才能访问,然后通过正常的内核“make”过程启用它。


6.7.1. 基于 IPTABLES 的 PORTFWD'ing:为 2.6.x 和 2.4.x 内核使用 IPTABLES 的 PREROUTING 选项

如前所述,端口转发或“PORTFW”允许将来自网络外部的单个或一系列 TCP/IP 端口转发到内部网络。

与所有以前的 Linux 内核不同,2.6.x 和 2.4.x 系列内核现在允许在“iptables”工具本身中实现完整的 PORTFW、PORTFW FTP 和 PORTFW REDIR 功能。

注意:一旦您在端口 80 上启用端口转发器(将 WWW 流量通过 MASQ 服务器转发到内部 WWW 服务器),Linux IP 地址伪装服务器本身将不再使用该端口。 更具体地说,如果您的 MASQ 服务器上已经运行了 WWW 服务器,则启用 PORTFW 现在将使所有 Internet 用户都可以访问来自 -INTERNAL- WWW 服务器的 WWW 页面,而不是您的 IP MASQ 服务器上的页面。

要在 IPTABLES(2.6.x 或 2.4.x 内核)上启用端口转发

  • 编辑 /etc/rc.d/rc.firewall-iptables 规则集,并将下面显示的行放在 "FWD:允许所有连接 OUT,仅允许现有和相关的连接 IN" 行(在“可选 FORWARD 部分”中)的上方。 请务必将单词“$EXTIP”替换为您的特定 Internet IP 地址。

  • 注意:与 2.2.x 和 2.0.x 内核不同,PORTFWed 流量 *不* 遍历 INPUT 或 OUTPUT 规则。 它仅遍历 FORWARD 规则。

  • 注意: 如果您从 ISP 获得动态分配的 TCP/IP 地址(PPP、DSL、有线调制解调器等),您无法在启动时加载此强规则集。 您要么需要每次获得新的 IP 地址时重新加载此防火墙规则集,要么使您的 /etc/rc.d/rc.firewall-ipchains-stronger 规则集更智能。 要为 PPP 或 DHCP 用户等各种类型的连接执行此操作,请参阅第 7.8 节 FAQ 条目以获取所有详细信息。

/etc/rc.d/rc.firewall-*

#echo "Enabling PORTFW Redirection on the external LAN.."
#
#   This will forward ALL port 80 traffic from the external IP address
#   to port 80 on the 192.168.0.10 machine
#
#   Be SURE that when you add these new rules to your rc.firewall-*, you
#   add them before a direct or implict DROP or REJECT.
#
PORTFWIP="192.168.0.10"


# NOTE:  If you are using the basic rc.firewall-iptables ruleset, you
#        will need to enable the following EXTIP option.  Users of the
#        rc.firewall-iptables-stronger ruleset already have this defined.
#
#  *PLEASE* look over the rc.firewall-iptables-stronger ruleset for more 
#            specific issues regarding dynamic vs. static IP addresses
#
#
# Determine the external IP automatically:
# ----------------------------------------
#
#  The following line will determine your external IP address.  This
#  line is somewhat complex and confusing but it will also work for
#  all NON-English Linux distributions:
#
# DISABLED by default -- to enable, REMOVE both the "#" characters below
#
#EXTIP="`$IFCONFIG $EXTIF | $AWK \
#/$EXTIF/'{next}//{split($0,a,":");split(a[2],a," ");print a[1];exit}'`"


# Allow forwarding of new and existing port 80 connections from the external
# interface.  This rule is required as our default FORWARD policy is DENY.
#
$IPTABLES -A FORWARD -i $EXTIF -o $INTIF -p tcp --dport 80 -m state \
 --state NEW,ESTABLISHED,RELATED -j ACCEPT


#Enable PORTFW of this port 80 traffic from the external interface
#
$IPTABLES -A PREROUTING -t nat -p tcp -d $EXTIP --dport 80 -m state \ 
 --state NEW,ESTABLISHED,RELATED -j DNAT --to $PORTFWIP:80 

就这样! 只需重新运行您的 /etc/rc.d/rc.firewall-iptables 规则集并进行测试! 如果您想了解更多信息,请参阅第 7.19 节

--------------------------------------------------------------------------

运行 rc.firewall-iptables-stronger 规则集? 对你来说很好! 要使用此规则集运行 PORTFW,这非常容易。 以下示例用于 HTTP (WWW) 流量 PORTFWed 到 $PORTFWIP 变量指示的 IP 地址

  • 获取上面显示的规则集行(用于通用 rc.firewall-* 规则集),并将它们放在 "#FORWARD 启用转发,从而启用 IPMASQ" 注释行之后。 还应该注意的是,对于基于 2.4 的内核,您不必在“可选 'INPUT' 部分”下启用“HTTPD”规则。 对于 2.4 内核,这些行仅在您要允许 HTTP 流量在 MASQ 服务器自己的本地 httpd 进程(通常是 Apache)上终止时使用。

PORTFW FTP:如果您已将“ip_conntrack_ftp”和“ip_nat_ftp”内核模块加载到内核空间(如 rc.firewall-iptables 脚本中已完成的那样),则只需将上面显示的简单 PREROUTING 命令更改为端口“21”即可。 这比旧版 IPCHAINS / IPFWADM 工具 для 2.2.x / 2.0.x 内核的配置容易得多!

请注意,如果您设置 PORTFW 以将流量重定向到在非标准 FTP 端口(例如端口 8021 而不是常用端口 21)上运行的内部 FTP 服务器,则必须告知“ip_conntrack_ftp”模块注意新的 FTP 端口。 进行此配置更改的原因是 FTP 不是 NAT 友好的协议。 通过告知 FTP NAT 模块有关此非标准 FTP 端口的信息,NAT 模块可以再次执行其工作。 要启用此功能,请编辑您的 rc.firewall-* 文件并将 FTP 模块的加载更改为如下所示

/sbin/insmod ip_conntrack_ftp ports=21,8021

内部请求的 PORTFW 重定向

过去,如果用户将外部 IP 地址上的端口 80 PORTFWed 到某些内部机器,则只有 Internet 上的机器才能正确访问此内部 WWW 服务器。 如果您尝试通过 MASQ 服务器的外部地址联系此内部 WWW 服务器,则会失败。 幸运的是,所有 Linux 内核都有解决方法。 用于 2.6.x 和 2.4.x 内核的 IPTABLES 本机支持此功能。 用于 2.2.x 内核的 IPCHAINS 支持和用于 2.0.x 内核的 IPFWADM 支持需要使用外部 REDIR 工具(当前未在本 HOWTO 中介绍)。 对于那些对 IPTABLES 相当了解的人来说,经验法则是 PREROUTING/DNAT 规则用于启用来自 *外部* 机器的 PORTFW,而 POSTROUTING/SNAT 规则用于启用来自 *内部* 机器的 PORTFW。

要支持来自内部主机的此类重定向,请在 rc.firewall-* 文件中“Catch all”FORWARDing 规则上方添加如下所示的规则。 以下示例会将所有外部和内部 WWW 流量重定向到标记为 PORTFWIP (192.168.0.10) 的内部机器。 此流量将具有 IP Masq 服务器的内部 IP 地址的源 IP 地址。 请更改 PORTFWIP 变量的 IP 地址以反映您的特定配置

#The following rule should be configured in *addition* to the above rule
# for enabling external to internal PORTFWing

$IPTABLES -t nat -A POSTROUTING -d $PORTFWIP -s $INTLAN -p tcp \
--dport 80 -m state --state NEW,ESTABLISHED,RELATED -j SNAT \
--to $INTIP


6.7.2. 基于 IPMASQADM 的 PORTFWD'ing:将 IPMASQADM 与 2.2.x 内核一起使用

首先,确保您已将最新的 2.2.x 内核解压缩到 /usr/src/kernel/linux 中。 如果您尚未执行此操作,请参阅第 3.2.2 节以获取完整详情。 接下来,从第 2.7 节将“ipmasqadm.c”程序下载到 /usr/src/kernel 目录中。

接下来,您需要按照第 3.2.2 节中所示编译 2.2.x 内核。 配置内核时,请务必对 IPPORTFW 选项说“YES”。 内核编译完成后并重新启动后,返回到本节。

现在,编译并安装 IPMASQADM 工具

        cd /usr/src
        tar xzvf ipmasqadm-x.tgz
        cd ipmasqadm-x
        make
        make install 

现在,对于此示例,我们将允许所有 WWW Internet 流量(端口 80)命中您的 Internet TCP/IP 地址,以转发到 IP 地址为 192.168.0.10 的内部地址伪装机器。

PORTFW FTP:如上所述,有两种解决方案可用于将 FTP 服务器流量转发到内部 MASQed PC。 第一个解决方案*是*用于 2.2.x 内核的 BETA 级别 IP_MASQ_FTP 模块,用于 PORT 转发 FTP 连接到内部 MASQed FTP 服务器。 另一种方法是使用 FTP 代理程序(URL 在第 2.7 节中)。 还应该注意的是,FTP 内核模块还支持动态添加其他 PORTFW FTP 端口,而无需卸载和重新加载 IP_MASQ_FTP 模块,从而避免中断任何现有的 FTP 传输。 您可以在 IPMASQ WWW 站点 http://ipmasq.webhop.net; 上找到有关此新代码的更多信息。 下面的 2.0.x. 内核部分还提供了有关 PORTFWed FTP 连接的示例和一些其他信息。

注意:一旦您在端口 80 上启用端口转发器,Linux IP 地址伪装服务器将不再使用该端口。 更具体地说,如果您的 MASQ 服务器上已经运行了 WWW 服务器,则端口转发现在将使所有 Internet 用户都可以访问来自 -INTERNAL- WWW 服务器的 WWW 页面,而不是您的 IP MASQ 服务器上的页面。

无论如何,要为 HTTPd 启用端口转发

  • 编辑 /etc/rc.d/rc.firewall-* 规则集,并在 INPUT 和 OUTPUT 子节中启用“可选”的“HTTP”部分。

  • 在下面显示的行中,紧贴 "ipchains -P forward DENY" 规则(在“可选 FORWARD 部分”中)的下方添加以下行。 务必将“$EXTIP”变量的内容替换为 IPMASQ 服务器上的外部 Internet IP 地址。

注意 #2: 如果您从 ISP 获得动态分配的 TCP/IP 地址(PPP、DSL、有线调制解调器等),您无法在启动时加载此强规则集。 您要么需要每次获得新的 IP 地址时重新加载此防火墙规则集,要么使您的 /etc/rc.d/rc.firewall-ipchains-stronger 规则集更智能。 要为 PPP 或 DHCP 用户等各种类型的连接执行此操作,请参阅第 7.8 节 FAQ 条目以获取所有详细信息。

/etc/rc.d/rc.firewall-*

#echo "Enabling IPPORTFW Redirection on the external LAN.."
#
#   This will forward ALL port 80 traffic from the external IP address
#   to port 80 on the 192.168.0.10 machine
#
PORTFWIP="192.168.0.10"

/usr/sbin/ipmasqadm portfw -f
/usr/sbin/ipmasqadm portfw -a -P tcp -L $EXTIP 80 -R $PORTFWIP 80

就这样! 只需重新运行您的 /etc/rc.d/rc.firewall-* 规则集并进行测试!

如果您收到错误消息“ipchains: setsockopt failed: Protocol not available”,则您没有运行新的启用 IPPORTFW 的内核。 确保您已将新内核移动过来,重新运行 LILO,然后再次重新启动。 如果您确定您正在运行新内核,请运行命令“ls /proc/net/ip_masq”并确保“portfw”文件存在。 如果不存在,则您在配置内核时一定犯了一个错误。 请重试。

内部请求的 PORTFW 重定向

应该提到的是,本 IPMASQ HOWTO 当前*不*提供关于如何使用 REDIR 工具的任何解释或示例。 如果您需要帮助为 2.2.x 内核设置它,请给我发送电子邮件。 对于那些想要了解为什么 PORTFW 无法重定向外部和内部接口的流量(REDIR 工具修复的内容)的人,以下是 Juanjo 的一封电子邮件,其中更好地解释了它。

From Juanjo Ciarlante
--

>If I use:
>
> ipmasqadm portfw -a -P tcp  -L 1.2.3.4 80 -R 192.168.2.3 80
>
>Everything works great from the outside but internal requests for the same
>1.2.3.4 address fail. Are there chains that will allow a machine on localnet 
>192.168.2.0 to accesss www.periapt.com without using a proxy? 

Actually not.

I usually setup a ipmasqadm rule for outside, *AND* a port
redirector for inside. This works because ipmasqadm hooks before
redir will get the eventual outside connection, _but_ leaves things
ok if not (stated by APPROPIATE rules).

The actual "conceptual" problem comes from the TRUE client (peer) IP
goal (thanks to masq) being in the same net as target server.

The failing scenario for "local masq" is :
   client: 192.168.2.100
   masq:   192.168.2.1
   serv:   192.168.2.10

1)client->server packet
 a) client:  192.168.2.100:1025  -> 192.168.2.1:80   [SYN]
 b) (masq):  192.168.2.100:1025  -> 192.168.2.10:80  [SYN]
            (and keep  192.168.2.1:61000 192.168.2.100:1025 related)
 c) serv:    gets masqed packet (1b)

2)server->client packet
 a) serv:    192.168.2.10:80     -> 192.168.2.100:1025  [SYN,ACK]
 b) client:  192.168.2.100:1025  -> 192.168.2.10:80     [RST]

Now take a moment to compare (1a) with (2a).
You see, the server replied DIRECTLY to client bypassing masq (not
letting masq to UNDO the packet hacking) because it is in SAME net, so
the client resets the connection.

hope I helped.

Warm regards
Juanjo


6.7.3. 基于 IPPORTFW 的 PORTFWD'ing:在 2.0.x 内核上使用 IPPORTFW

首先,确保您已将最新的 2.0.x 内核解压缩到 /usr/src/kernel 中。 如果您尚未执行此操作,请参阅第 3.2.3 节以获取完整详情。 接下来,从第 3.2.3 节将“ipportfw.c”程序和“subs-patch-x.gz”内核补丁下载到 /usr/src/ 目录中。

注意:请将“subs-patch-x.gz”文件名中的“x”替换为站点上可用的最新版本。

接下来,如果您计划将 FTP 流量端口转发到内部服务器,则必须应用一个额外的 IP_MASQ_FTP 模块补丁,该补丁可在第 3.2.3 节中找到。 有关此的更多详细信息将在本节后面介绍。 请注意,这与 2.2.x 内核的补丁不同,因此某些功能(例如动态 FTP PORT 功能)不存在。

现在,将 IPPORTFW 补丁 (subs-patch-x.gz) 复制到 Linux 目录中

        cp /usr/src/subs-patch-1.37.gz /usr/src/linux

接下来,应用内核补丁以创建 IPPORTFW 内核选项

        cd /usr/src/linux
        zcat subs-patch-1.3x.gz | patch -p1

好的,现在可以编译内核了,如第 3.2.3 节所示。在配置内核时,请务必选择“是”来启用 IPPORTFW 选项。编译完成后并重启系统,返回到本节。

现在,使用新编译的内核,请编译并安装实际的 "IPPORTFW" 程序

        cd /usr/src
        gcc ipportfw.c -o ipportfw
        mv ipportfw /usr/local/sbin

现在,对于这个例子,我们将允许所有访问您的 Internet TCP/IP 地址的 WWW 互联网流量(端口 80)转发到内部伪装机器,IP 地址为 192.168.0.10。

注意: 一旦您在端口 80 上启用端口转发器,Linux IP Masquerade 服务器将无法再使用该端口。更具体地说,如果您在 MASQ 服务器上已经运行了一个 WWW 服务器,然后您将端口 80 端口转发到内部 MASQ 计算机,所有互联网用户将看到来自 -内部- WWW 服务器的网页,而不是您的 IP MASQ 服务器上的网页。这只会将端口转发到其他端口,例如 8080,转发到您的内部 MASQ 机器。虽然这可以工作,但所有互联网用户都必须在 URL 中附加 :8080 才能联系到内部 MASQed WWW 服务器。

无论如何,要启用端口转发,请编辑 /etc/rc.d/rc.firewall-* 规则集。添加以下行,但请务必将单词 "$extip" 替换为您的互联网 IP 地址。

注意 #2: 如果您从 ISP 获得动态分配的 TCP/IP 地址(PPP、DSL、有线调制解调器等),您无法在启动时加载此强规则集。 您要么需要每次获得新的 IP 地址时重新加载此防火墙规则集,要么使您的 /etc/rc.d/rc.firewall-ipchains-stronger 规则集更智能。 要为 PPP 或 DHCP 用户等各种类型的连接执行此操作,请参阅第 7.8 节 FAQ 条目以获取所有详细信息。

/etc/rc.d/rc.firewall-*

#echo "Enabling IPPORTFW Redirection on the external LAN.."
#
#   This will forward ALL port 80 traffic from the external IP address
#   to port 80 on the 192.168.0.10 machine
#
/usr/local/sbin/ipportfw -C
/usr/local/sbin/ipportfw -A -t$extip/80 -R 192.168.0.10/80

就这样! 只需重新运行您的 /etc/rc.d/rc.firewall-* 规则集并进行测试!

如果您收到错误消息 "ipfwadm: setsockopt failed: Protocol not available",则说明您没有运行新的内核。请确保您已移动了新内核,重新运行 LILO,然后再次重启。

端口转发 FTP 服务器

如果您计划将 FTP 端口转发到内部机器,事情会变得更加复杂。原因是标准的 IP_MASQ_FTP 内核模块并非为此而编写,尽管一些用户报告说它可以正常工作,没有任何问题。就我个人而言,在没有补丁的情况下,我听说超过 30 分钟的扩展文件传输会失败,而其他用户则发誓它可以完美运行。无论如何,我建议您使用 STOCK ip_masq_ftp 模块尝试以下 PORTFW 指令,看看它是否对您有效。如果无效,请尝试使用修改后的 ip_masq_ftp 模块。

对于那些需要该模块的人,Fred Viles 编写了一个修改后的 IP_MASQ_FTP 模块,以使事情能够正常工作。如果您好奇到底有哪些问题,请下载以下存档,因为 Fred 对此进行了很好的文档记录。还要理解,这个补丁在某种程度上是实验性的,应该这样对待。应该注意的是,这个补丁仅适用于 2.0.x 内核,尽管有一个不同的补丁适用于 2.2.x 内核。

因此,要使 2.0.x 补丁工作,您需要

  • 首先,应用 IPPORTFW 内核补丁,如本节前面所示。

  • 从 Fred Viles 的 FTP 服务器下载 "msqsrv-patch-36"(在第 3.2.3 节中),并将其放入 /usr/src/linux。

  • 通过运行 "cat msqsrv-patch-36 | patch -p1" 使用这个新代码修补内核。

  • 接下来,用新的内核模块替换原始的 "ip_masq_ftp.c" 内核模块

    mv /usr/src/linux/net/ipv4/ip_masq_ftp.c /usr/src/linux/net/ipv4/ip_masq_ftp.c.orig

    mv /usr/src/linux/ip_masq_ftp.c /usr/src/linux/net/ipv4/ip_masq_ftp.c

  • 最后,构建并安装包含此新代码的内核。

完成后,编辑 /etc/rc.d/rc.firewall-* 规则集并添加以下行,但请务必将单词 "$extip" 替换为您的互联网 IP 地址。

这个例子,就像上面的例子一样,将允许所有访问您的 Internet TCP/IP 地址的 FTP 互联网流量(端口 21)转发到内部伪装机器,IP 地址为 192.168.0.10。

注意:一旦您在端口 21 上启用端口转发器,Linux IP Masquerade 服务器将无法再使用该端口。更具体地说,如果您在 MASQ 服务器上已经运行了一个 FTP 服务器,端口转发现在将使所有互联网用户获得来自 -内部- FTP 服务器的 FTP 文件,而不是您的 IP MASQ 服务器上的文件。

/etc/rc.d/rc.firewall-*

#echo "Enabling IPPORTFW Redirection on the external LAN.."
#
/usr/local/sbin/ipportfw -C
/usr/local/sbin/ipportfw -A -t$extip/21 -R 192.168.0.10/21

#NOTE: If you are using multiple local port numbers to PORTFW
#      to multuple internal FTP servers (say, 21, 2121, 2112,
#      etc, you need to configure the ip_masq_ftp nodule to
#      listen to these ports.  To do this, edit the 
#      /etc/rc.d/rc.firewall-* script as shown in this HOWTO
#      to look like:
#
# /sbin/modprobe ip_masq_ftp ports=21,2121,2112
#
# Re-run the /etc/rc.d/rc.firewall-* script for these changes to
# take effect.


#Please note that PORTFWing port 20 is probably NOT required 
#  for ACTIVE connections as the internal FTP server will 
#  initiate this port 20 connection and it will be properly 
#  handled by the classic MASQ mechanisms.

就这样! 只需重新运行您的 /etc/rc.d/rc.firewall-* 规则集并进行测试!

内部请求的 PORTFW 重定向

尚不清楚 REDIR 工具是否可以针对旧的 2.0.x 内核进行编译或工作。还应该提到的是,本 IPMASQ HOWTO 当前提供任何关于如何使用 REDIR 工具的解释或示例。如果您需要设置方面的帮助,请给我发送电子邮件。如果您想了解更多关于 REDIR 的信息,请参阅上面关于 2.2.x 内核的章节。


6.8. CU-SeeMe 和 Linux IP-Masquerade

Linux IP Masquerade 通过 "ip_masq_cuseeme" 内核模块支持 CuSeeme。此内核模块应加载到 /etc/rc.d/rc.firewall-* 脚本中。一旦安装了 "ip_masq_cuseeme" 模块,您应该能够发起和接收与远程反射器和/或用户的 CuSeeme 连接。

注意:建议使用 IPPORTFW 工具而不是旧的 IPAUTOFW 工具来运行 CuSeeme。

如果您需要关于配置 CuSeeme 的更明确的信息,请参阅 Michael Owings 的 CuSeeMe 页面,其中包含一个 Mini-HOWTO,或者 IP Masquerade 资源,其中包含 Mini-HOWTO 的镜像。


6.9. Mirabilis ICQ

ICQ,这个即时通讯客户端现在归 AOL 所有,多年来已经发生了变化。所有现代 ICQ 客户端都对 NAT 友好,因此需要任何特殊的 NAT 模块、PORTFW 技巧等。

如果出于某种原因,您想运行旧的 ICQ 客户端,您可以阅读本节。如果不是,请忽略所有这些信息。我将此信息保留在 HOWTO 中是为了展示一个大型的 PORTFW 示例。

有三种方法可以让 ICQ 在 Linux MASQ 服务器后面工作。这些解决方案包括使用 ICQ Masq 模块(适用于 2.2.x 和 2.0.x 内核)、使用 IPPORTFW 进行基本的 ICQ 功能,或设置 SOCKS 代理服务器。

模块:ICQ 模块是为旧一代 ICQ 客户端编写的,适用于 2.2.x 和 2.0.x 内核。该模块允许在 MASQ 服务器后面简单设置多个 ICQ 用户。它也不需要对 ICQ 客户端进行任何特殊更改。最近,AOL 更改了 ICQ 使用的协议和端口。因此,许多用户可能会发现 ip_masq_icq 模块不再对他们有帮助。对于旧 ICQ 客户端的用户,2.2.x 版本的模块支持文件传输和实时聊天。2.0.x 内核模块不支持文件传输,并且没有适用于 2.4.x 内核的模块。

PORTFW:您的下一个选择是使用端口转发。通过端口转发,基本的 ICQ 聊天将工作,但文件传输可能不是很可靠。请参阅下面关于如何配置 ICQ PORTFW 的示例。

SOCKS:最后,您的最后一个也是可能最好的选择是在您的 Linux 机器上设置 SOCKS 代理服务器。此服务可以与 MASQ 服务愉快地共存,并且无论您运行什么 Linux 内核版本,ICQ 都应该完全正常工作。使用 SOCKS 服务器将需要重新配置所有 ICQ 客户端以使用它,并且 SOCKS 服务器的安装和配置与 IP Masquerade 无关。因此,本 HOWTO 不涵盖 SOCKS。

如果您对 Andrew Deryabin 的 djsf@usa.net ICQ IP Masq 模块(适用于 2.2.x 和 2.0.x 内核)感兴趣,请参阅 第 2.7 节了解详情。

要使用端口转发 (PORFW) 用于 ICQ,您需要在 Linux 和 ICQ 客户端上进行一些更改,但所有 ICQ 消息、URL、聊天和一些文件传输都应该可以工作。

  • 首先,您需要运行启用 IPPPORTFW 的 Linux 内核。请参阅 第 6.7 节了解更多详情。

  • 接下来,您需要将以下行添加到您的 /etc/rc.d/rc.firewall-* 文件中。此示例假定 10.1.2.3 是您的外部互联网 IP 地址,而您的内部 MASQed ICQ 机器是 192.168.0.10

  • 以下示例适用于带有 IPCHAINS 的 2.2.x 内核

    我在此处为用户提供了两个示例:任何一个都可以正常工作

    示例 #1

    /usr/local/sbin/ipmasqadm portfw -a -P tcp -L 10.1.2.3 2000 -R 192.168.0.10 2000
    /usr/local/sbin/ipmasqadm portfw -a -P tcp -L 10.1.2.3 2001 -R 192.168.0.10 2001
    /usr/local/sbin/ipmasqadm portfw -a -P tcp -L 10.1.2.3 2002 -R 192.168.0.10 2002
    /usr/local/sbin/ipmasqadm portfw -a -P tcp -L 10.1.2.3 2003 -R 192.168.0.10 2003
    /usr/local/sbin/ipmasqadm portfw -a -P tcp -L 10.1.2.3 2004 -R 192.168.0.10 2004
    /usr/local/sbin/ipmasqadm portfw -a -P tcp -L 10.1.2.3 2005 -R 192.168.0.10 2005
    /usr/local/sbin/ipmasqadm portfw -a -P tcp -L 10.1.2.3 2006 -R 192.168.0.10 2006
    /usr/local/sbin/ipmasqadm portfw -a -P tcp -L 10.1.2.3 2007 -R 192.168.0.10 2007
    /usr/local/sbin/ipmasqadm portfw -a -P tcp -L 10.1.2.3 2008 -R 192.168.0.10 2008
    /usr/local/sbin/ipmasqadm portfw -a -P tcp -L 10.1.2.3 2009 -R 192.168.0.10 2009
    /usr/local/sbin/ipmasqadm portfw -a -P tcp -L 10.1.2.3 2010 -R 192.168.0.10 2010
    /usr/local/sbin/ipmasqadm portfw -a -P tcp -L 10.1.2.3 2011 -R 192.168.0.10 2011
    /usr/local/sbin/ipmasqadm portfw -a -P tcp -L 10.1.2.3 2012 -R 192.168.0.10 2012
    /usr/local/sbin/ipmasqadm portfw -a -P tcp -L 10.1.2.3 2013 -R 192.168.0.10 2013
    /usr/local/sbin/ipmasqadm portfw -a -P tcp -L 10.1.2.3 2014 -R 192.168.0.10 2014
    /usr/local/sbin/ipmasqadm portfw -a -P tcp -L 10.1.2.3 2015 -R 192.168.0.10 2015
    /usr/local/sbin/ipmasqadm portfw -a -P tcp -L 10.1.2.3 2016 -R 192.168.0.10 2016
    /usr/local/sbin/ipmasqadm portfw -a -P tcp -L 10.1.2.3 2017 -R 192.168.0.10 2017
    /usr/local/sbin/ipmasqadm portfw -a -P tcp -L 10.1.2.3 2018 -R 192.168.0.10 2018
    /usr/local/sbin/ipmasqadm portfw -a -P tcp -L 10.1.2.3 2019 -R 192.168.0.10 2019
    /usr/local/sbin/ipmasqadm portfw -a -P tcp -L 10.1.2.3 2020 -R 192.168.0.10 2020
         
    示例 #2
    port=2000
    while [ $port -le 2020 ]
      do
        /usr/local/sbin/ipmasqadm portfw -a -P tcp -L 10.1.2.3 $port -R 192.168.0.10 $port
        port=$((port+1))
    done
         

  • 以下示例适用于带有 IPFWADM 的 2.0.x 内核

    我在此处为用户提供了两个示例:任何一个都可以正常工作

    示例 #1

    /usr/local/sbin/ipportfw -A -t10.1.2.3/2000 -R 192.168.0.10/2000
    /usr/local/sbin/ipportfw -A -t10.1.2.3/2001 -R 192.168.0.10/2001
    /usr/local/sbin/ipportfw -A -t10.1.2.3/2002 -R 192.168.0.10/2002
    /usr/local/sbin/ipportfw -A -t10.1.2.3/2003 -R 192.168.0.10/2003
    /usr/local/sbin/ipportfw -A -t10.1.2.3/2004 -R 192.168.0.10/2004
    /usr/local/sbin/ipportfw -A -t10.1.2.3/2005 -R 192.168.0.10/2005
    /usr/local/sbin/ipportfw -A -t10.1.2.3/2006 -R 192.168.0.10/2006
    /usr/local/sbin/ipportfw -A -t10.1.2.3/2007 -R 192.168.0.10/2007
    /usr/local/sbin/ipportfw -A -t10.1.2.3/2008 -R 192.168.0.10/2008
    /usr/local/sbin/ipportfw -A -t10.1.2.3/2009 -R 192.168.0.10/2009
    /usr/local/sbin/ipportfw -A -t10.1.2.3/2010 -R 192.168.0.10/2010
    /usr/local/sbin/ipportfw -A -t10.1.2.3/2011 -R 192.168.0.10/2011
    /usr/local/sbin/ipportfw -A -t10.1.2.3/2012 -R 192.168.0.10/2012
    /usr/local/sbin/ipportfw -A -t10.1.2.3/2013 -R 192.168.0.10/2013
    /usr/local/sbin/ipportfw -A -t10.1.2.3/2014 -R 192.168.0.10/2014
    /usr/local/sbin/ipportfw -A -t10.1.2.3/2015 -R 192.168.0.10/2015
    /usr/local/sbin/ipportfw -A -t10.1.2.3/2016 -R 192.168.0.10/2016
    /usr/local/sbin/ipportfw -A -t10.1.2.3/2017 -R 192.168.0.10/2017
    /usr/local/sbin/ipportfw -A -t10.1.2.3/2018 -R 192.168.0.10/2018
    /usr/local/sbin/ipportfw -A -t10.1.2.3/2019 -R 192.168.0.10/2019
    /usr/local/sbin/ipportfw -A -t10.1.2.3/2020 -R 192.168.0.10/2020
         

    示例 #2

    port=2000
    while [ $port -le 2020 ]
      do
        /usr/local/sbin/ipportfw -A t10.1.2.3/$port -R 192.168.0.10/$port
        port=$((port+1))
    done
         

  • 一旦您的新 rc.firewall-* 准备就绪,重新加载规则集以确保一切正常,只需输入 "/etc/rc.d/rc.firewall-*" 即可。如果您收到任何错误,则说明您的内核中没有 IPPORTFW 支持,或者您在 rc.firewall 文件中输入了错误。

  • 现在,在 ICQ 的首选项-->连接中,将其配置为“在 LAN 后面”和“在防火墙或代理后面”。现在,单击“防火墙设置”,并将其配置为“我不使用 SOCK5 代理”。还要注意,之前建议将 ICQ 的“防火墙会话超时”更改为“30”秒,但许多用户发现 ICQ 变得不可靠。已经发现,ICQ 使用其默认超时设置(不要启用该 ICQ 选项)并且只需将 MASQ 的超时更改为 160 秒,ICQ 会更可靠。您可以在 第 3.4.3 节第 3.4.2 节规则集中看到如何更改此超时。最后,单击“下一步”,并将 ICQ 配置为“使用以下 TCP 侦听端口...”,从“2000”到“2020”。现在单击“完成”。

    现在 ICQ 会告诉您,您必须重启 ICQ 才能使更改生效。老实说,我必须重启 Windows9x 机器才能使一切正常工作,但一些用户可能会有不同的说法。所以... 两种方法都试试。

  • 一位用户曾经告诉我,只需将端口 4000 端口转发到他的 ICQ 机器,它就可以完美地工作。他报告说,一切都工作正常(甚至包括聊天、文件传输等),无需从其默认设置重新配置 ICQ。您的结果可能会因情况而异,但我认为您可能想了解一下这种替代配置。


6.10. 游戏玩家:LooseUDP 补丁

LooseUDP 补丁允许通常使用 UDP 连接的半 NAT 友好游戏在 Linux IP Masquerade 服务器后面工作

LooseUDP 补丁的作用是允许所有 UDP 数据包通过 MASQ 盒进行 NAT,而无需任何检查或过期。这种宽松的转发方法被许多人认为是不安全的,并在现代 2.2.x 内核中被禁用。具有 IPTABLES 状态检测 UDP 的 2.4.x 内核仅允许传入的 UDP 数据包进入机器(以及 MASQ),前提是状态检测表中已经存在发往同一主机的出站 UDP 数据包。如果 MASQ 主机在约 30 秒内没有向远程主机发送 UDP 数据包,则返回的 UDP 表条目将被删除。因此,IPTABLES 以更安全的方式完成了大部分 LooseUDP 补丁的需求。

目前,LooseUDP 可以作为 2.0.36+ 内核的补丁使用,并且已经内置到 2.2.3+ 内核中,尽管在 2.2.16+ 中它现在默认情况下是禁用的(请参阅示例 rc.firewal 规则集注释了解详情)。

要在 2.0.x 内核上运行 LooseUDP,请按照以下步骤操作

  • 将最新的 2.0.x 内核源代码解压缩到 /usr/src/linux 目录中

  • 对于 v2.0.x 绝对必要:从 第 3.2.3 节下载并安装 IPPORTFW 补丁,如 HOWTO 的 第 6.7 节中所述。

  • 第 3.2.3 节下载 LooseUDP 补丁

    现在,将 LooseUDP 补丁放入 /usr/src/linux 目录中。完成后,输入

    For a compressed patch file:  zcat loose-udp-2.0.36.patch.gz | patch -p1

    For a NON-compressed patch file:  cat loose-udp-2.0.36.patch | patch -p1

    现在,根据您的 "patch" 版本,您将看到以下文本

    patching file `CREDITS'
    patching file `Documentation/Configure.help'
    patching file `include/net/ip_masq.h'
    patching file `net/ipv4/Config.in'
    patching file `net/ipv4/ip_masq.c'

  • 如果您看到文本 "Hunk FAILED" 仅一次,并且仅在修补的开头出现一次,请不要惊慌。您可能有一个旧的补丁文件(这已被修复),但它仍然有效。如果完全失败,请确保您已首先应用 IPPORTFW 内核补丁。

    安装补丁后,如 第 3.2.3 节所示重新配置内核,并务必对“IP: loose UDP port managing (EXPERIMENTAL) (CONFIG_IP_MASQ_LOOSE_UDP) [Y/n/?]”选项选择“Y”。

要在 2.2.x 内核上运行 LooseUDP,请按照以下步骤操作

  • 在 /etc/rc.d/rc.firewall-* 脚本中,转到文件底部并找到 LooseUDP 部分。将行中的 "0" 更改为echo "0" > /proc/sys/net/ipv4/ip_masq_udp_dloose“1”,然后重新运行 rc.firewall-* 规则集。在 第 3.4.2 节示例和 第 6.4.3 节示例中都给出了示例。

注意:LooseUDP 代码对于 2.4.x 内核不可用(?必需?)

  • 请参阅本节开头了解所有详细信息。基本上,旧的 2.0.x / 2.2.x LooseUDP 代码被认为是安全问题。因此,它已从内核中删除。幸运的是,一些过去需要在 2.2.x IPCHAINS 系统上使用 LooseUDP 代码的游戏可能在 2.4.x IPTABLES 内核下也能正常工作。如果游戏无法工作,我不知道有什么解决方案可以帮助您。抱歉。

一旦您运行了新的启用 LooseUDP 的内核,对于大多数 NAT 友好游戏,您应该就可以开始了。已经提供了一些 URL,其中包含使 BattleZone 等游戏对 NAT 友好的补丁。请参阅 第 6.3.1 节了解更多详情。


第 7 章 常见问题解答

如果您能想到任何有用的常见问题解答建议,请发送至 dranch@trinnet.net。请清楚地说明问题和适当的答案(如果您有的话)。谢谢!


7.1. ( 发行版 ) - 哪些 Linux 发行版支持 IP Masquerading?

如果您的 Linux 发行版开箱即用不支持 IP MASQ,请不要担心。您要做的就是按照本 HOWTO 上面所示重新编译内核。

注意:如果您可以帮助我们填写此表,请发送电子邮件至 dranch@trinnet.net

  • Caldera < v1.2 : 否 - ?

  • Caldera v1.3 : 是 - 基于 2.0.35

  • Caldera v2.2 : 是 - 基于 2.2.5

  • Caldera eServer v2.3 : 是 - ? 基于

  • Debian v1.3 : 否 - ?

  • Debian v2.0 : 否 - ?

  • Debian v2.1 : 是 - 基于 2.2.1

  • Debian v2.2 : 是 - 基于 2.2.15

  • Debian v3.0 : 是 - 基于 2.4.18

  • DLX Linux v? : ? - ?

  • DOS Linux v? : ? - ?

  • FloppyFW v1.0.2 : ? - ?

  • Gentoo v1.4 : 是 - ? 基于

  • Hal91 Linux v? : ? - ?

  • Linux PPC vR4 : 否 - ?

  • Linux Pro v? : ? - ?

  • LinuxWare v? : ? - ?

  • Mandrake v5.3 : 是 - ?

  • Mandrake v6.0 : 是 - 2.2.5

  • Mandrake v6.1 : 是 - ?

  • Mandrake v7.0 : 是 - 2.2.14

  • Mandrake v7.1 : 是 - 2.2.15

  • Mandrake v7.2 : 是 - 2.2.17

  • Mandrake v8.0 : 是 - ?

  • Mandrake v8.1 : 是 - 2.4.8

  • Mandrake v8.2 : 是 - ?

  • Mandrake v9.0 : 是 - ?

  • Mandrake v9.1 : 是 - 2.4.21-pre

  • MkLinux v? : ? - ?

  • MuLinux v3rl : 是 - ?

  • Redhat < v4.x : 否 - ?

  • Redhat v5.0 : 是 - ?

  • Redhat v5.1 : 是 - 基于 2.0.34

  • Redhat v5.2 : 是 - 基于 2.0.36

  • Redhat v6.0 : 是 - 基于 2.2.5

  • Redhat v6.1 : 是 - 基于 2.2.12

  • Redhat v6.2 : 是 - 基于 2.2.14

  • Redhat v7.0 : 是 - 基于 2.2.16

  • Redhat v7.2 : 是 - 基于 2.4.7

  • Redhat v7.3 : 是 - 基于 2.4.?

  • Redhat v8.0 : 是 - 基于 2.4.18?

  • Redhat v9.0 : 是 - 基于 2.4.20

  • Slackware v3.0 : ? - ?

  • Slackware v3.1 : ? - ?

  • Slackware v3.2 : ? - ?

  • Slackware v3.3 : ? - 基于 2.0.34

  • Slackware v3.4 : ? - ?

  • Slackware v3.5 : ? - ?

  • Slackware v3.6 : ? - ?

  • Slackware v3.9 : ? - 基于 2.0.37pre10

  • Slackware v4.0 : 是 - 基于 2.2.6

  • Slackware v7.0 : 是 - 基于 2.2.13

  • Slackware v7.1 : 是 - 基于 2.2.16

  • Slackware v8.0 : 是 - 基于 2.4.17

  • Slackware v8.1 : 是 - ? 基于

  • Stampede Linux v? : ? - ?

  • SuSE v5.2 : 是 - 基于 2.0.32

  • SuSE v5.3 : 是 - ?

  • SuSE v6.0 : 是 - 基于 2.0.36

  • SuSE v6.1 : 是 - 基于 2.2.5

  • SuSE v6.3 : 是 - 基于 2.2.13

  • Tomsrbt Linux v? : ? - ?

  • TurboLinux Lite v4.0 : 是 - ?

  • TurboLinux v6.0 : 是 - 基于 2.2.12

  • TriLinux v? : ? - ?

  • Yggdrasil Linux v? : ? - ?


7.2. ( 要求 ) - IP Masquerade 的最低硬件要求和任何限制是什么?它的性能如何?

一台配备 16MB RAM 的 486/66 机器足以填满 1.54Mb/s T1 100%!MASQ 也被认为可以在配备 8MB RAM 的 386SX-16 上运行良好。但是,应该注意的是,当 MASQ 条目超过 500 个时,Linux IP Masquerade 就会开始对系统进行抖动。

据我所知,唯一可以暂时破坏 Linux IP Masquerade 的应用程序是 GameSpy。为什么?当它刷新列表时,它会在很短的时间内创建 10,000 多个快速连接。在这些会话超时之前,MASQ 表会“满”。有关更多详细信息,请参阅常见问题解答的 第 7.23 节

在我们继续之前

TCP 和 UDP 各自的并发连接数硬性限制为 4096 个。可以通过调整 /usr/src/linux/net/ipv4/ip_masq.h 中的值来更改此限制 - 最大限制 32000 应该可以。如果要更改限制 - 您需要更改 PORT_MASQ_BEGIN 和 PORT_MASQ_END 值,以获得适当大小的范围,该范围应高于 32K 且低于 64K。


7.3. ( 错误 ) - 当我运行特定的 rc.firewall-* 规则集时,出现 "command not found" 错误。为什么?

首先,当我说 rc.firewall-* 时,我真正的意思是使用各种类型的防火墙规则集之一,具体取决于您运行的内核版本。本 HOWTO 中的选项包括:rc.firewall-iptables 或 rc.firewall-iptables-stronger 或 rc.firewall-ipchains 或 rc.firewall-ipchains-stronger 或 rc.firewall-ipfwadm 或 rc.firewall-ipfwadm-stronger。

接下来,您是如何将 rc.firewall-* 放到您的机器上的?您是否将其剪切并粘贴到 TELNET 窗口中,从 Windows/DOS 机器 FTP 上传,等等?尝试这样做... 登录到您的 Linux 机器并运行 "vim -b /etc/rc.d/rc.firewall-*",看看您的所有行是否都以 ^M 结尾。如果是,请删除所有 ^M 并重试。


7.4. ( 仍然无法工作 ) - 我已经检查了所有配置,但仍然无法使 IP Masquerade 工作。我该怎么办?

  • 保持冷静。给自己泡一杯茶、咖啡、苏打水等,休息一下。一旦您的头脑清醒,请尝试下面提到的建议。设置 Linux IP Masquerading 难,但有一些概念对您来说可能是新的。

  • 再次,通读 第 5 章中的所有步骤。99% 的首次使用 Masquerade 并且遇到问题的用户都没有看过这里。

  • 查看 IP Masquerade 邮件列表存档,很可能您的问题或难题是一个常见问题,可以在简单的存档搜索中找到。

  • 查看 TrinityOS 文档。它涵盖了 2.0.x 和 2.2.x 内核的 IP Masquerading 以及许多其他主题,包括 PPPd、DialD、DHCP、DNS、Sendmail 等。

  • 确保您没有运行 ROUTED 或 GATED。要验证,请运行 "ps aux | grep -e routed -e gated"

  • 将您的问题发布到 IP Masquerade 邮件列表(有关详细信息,请参阅下一个常见问题解答部分)。仅当您无法从 IP Masquerading 存档中找到答案时才使用此方法。请务必在您的电子邮件中包含 第 5 章中请求的所有信息!!

  • 将您的问题发布到相关的 Linux NNTP 新闻组。

  • 发送电子邮件至 ambrose@writeme.comdranch@trinnet.net。您从 IP Masquerading 邮件列表获得回复的机会比我们任何一个人都大。

  • 再次检查您的配置 :-)


7.5. ( 邮件列表 ) - 如何加入或查看 IP Masquerade 和/或 IP Masqurade 开发人员邮件列表和存档?

有两种方法可以加入两个 Linux IP Masquerading 邮件列表。第一种方法是发送电子邮件至 masq-request@indyramp.com。要加入 Linux IP Masquerading 开发人员邮件列表,请发送电子邮件至 masq-dev-request@indyramp.com。请参阅下面的项目符号了解更多详情。

  • 通过电子邮件订阅:现在在电子邮件消息的主题或正文中输入单词 "subscribe"。如果您只想订阅主 MASQ 或 MASQ-DEV 列表的摘要版本(一周内给定列表上的所有电子邮件都以一封大型电子邮件发送给您),请在电子邮件消息的主题或正文中输入单词 "subscribe digest"。

    服务器收到您的请求后,它会将您订阅到您请求的列表,并给您一个密码。保存此密码,因为您稍后需要它来取消订阅列表或更改您的选项。

第二种方法是使用 WWW 浏览器,并通过 http://home.indyramp.net/mailman/listinfo/masq 的表单订阅主 MASQ 列表,或通过 http://home.indyramp.net/mailman/listinfo/masq-dev 的表单订阅 MASQ-DEV 列表。

订阅后,您将收到来自您订阅列表的电子邮件。还应该注意的是,订阅和订阅的用户都可以访问这两个列表的存档。为此,请参阅上面两个 WWW URL 了解更多详情。

最后,请注意,您只能从您用于订阅的原始帐户/地址发布到 MASQ 列表。

如果您对邮件列表或邮件列表存档有任何问题,请联系 Robert Novak


7.6. ( NAT vs. 代理 ) - IP Masquerade 与代理或 NAT 服务有何不同?

Proxy:  Proxy servers are available for: Win95, NT, Linux, Solaris, etc.

            Pro:    + (1) IP address ; cheap
                    + Optional caching for better performance (WWW, etc.)

            Con:    - All applications behind the proxy server must both SUPPORT 
                      proxy services (SOCKS) and be CONFIGURED to use the Proxy 
                      server
                    - Screws up WWW counters and WWW statistics

	 A proxy server uses only (1) public IP address, like IP MASQ, and acts  
	 as a translator to clients on the private LAN (WWW browser, etc.).
	 This proxy server receives requests like TELNET, FTP, WWW, 
	 etc. from the private network on one interface.  It would then in turn,
	 initiate these requests as if someone on the local box was making the
	 requests.   Once the remote Internet server sends back the requested
	 information, it would re-translate the TCP/IP addresses back to the 
	 internal MASQ client and send traffic to the internal requesting host.  
	 This is why it is called a PROXY server.  

		Note:  ANY applications that you might want to use on the 
			internal machines *MUST* have proxy server support 
			like Netscape and some of the better TELNET and FTP 
			clients.  Any clients that don't support proxy servers 
			won't work.

	 Another nice thing about proxy servers is that some of them
	 can also do caching (Squid for WWW).  So, imagine that you have 50 
	 proxied hosts all loading Netscape at once.  If they were installed 
	 with the default homepage URL, you would have 50 copies of the same 
	 Netscape WWW page coming over the WAN link for each respective computer.  
	 With a caching proxy server, only one copy would be downloaded by the 
         proxy server and then the proxied machines would get the WWW page from 
         the cache.  Not only does this save bandwidth on the Internet 
         connection, it will be MUCH MUCH faster for the internal proxied 
         machines.



MASQ:	 IP Masq is available on Linux and a few ISDN routers such
 or	 as the Zytel Prestige128, Cisco 770, NetGear ISDN routers, etc.
1:Many
 NAT	 
		Pro: 	+ Only (1) IP address needed (cheap)
			+ Doesn't require special application support
			+ Uses firewall software so your network can become
			  more secure

		Con:	- Requires a Linux box or special ISDN router
			  (though other products might have this..  )
			- Incoming traffic cannot access your internal LAN
			  unless the internal LAN initiates the traffic or
			  specific port forwarding software is installed.
			  Many NAT servers CANNOT provide this functionality.
			- Special protocols need to be uniquely handled by
			  firewall redirectors, etc.  Linux has full support
			  for this (FTP, IRC, etc.) capabilty but many routers
			  do NOT (NetGear DOES). 

	 Masq or 1:Many NAT is similar to a proxy server in the sense that the 
	 server will perform IP address translation and fake out the remote server 
	 (WWW for example) as if the MASQ server made the request instead of an 
	 internal machine.  
	
	 The major difference between a MASQ and PROXY server is that MASQ servers
	 don't need any configuration changes to all the client machines.  Just 
	 configure them to use the linux box as their default gateway and everything 
	 will work fine.  You WILL need to install special Linux modules for things 
	 like RealAudio, FTP, etc. to work)!  

	 Also, many users operate IP MASQ for TELNET, FTP, etc. *AND* also setup a 
	 caching proxy on the same Linux box for WWW traffic for the additional 
	 performance.


NAT:	 NAT servers are available on Windows 95/NT, Linux, Solaris, and some 
	 of the better ISDN routers (not Ascend)	 

		Pro: 	+ Very configurable
			+ No special application software needed

		Con:	- Requires a subnet from your ISP (expensive)

	 Network Address Translation is the name for a box that would have a pool of 
	 valid IP addresses on the Internet interface which it can use.  Whenever the
	 Internal network wanted to go to the Internet, it associates an available 
	 VALID IP address from the Internet interface to the original requesting 
	 PRIVATE IP address.  After that, all traffic is re-written from the NAT 
	 public IP address to the NAT private address.  Once the associated PUBLIC 
	 NAT address becomes idle for some pre-determined amount of time, the 
	 PUBLIC IP address is returned back into the public NAT pool.  

	 The major problem with NAT is, once all of the free public IP addresses are
	 used, any additional private users requesting Internet service are out of
	 luck until a public NAT address becomes free.

有关各种形式 NAT 的出色且非常全面的描述,请参阅

这里是另一个学习 NAT 的好网站,尽管许多 URL 已经过时,但仍然有效


7.7. ( GUI ) - 是否有任何 GUI 防火墙创建/管理工具?

是的!它们的用户界面类型、复杂性等各不相同,但它们都非常好,尽管到目前为止大多数工具仅适用于 IPFWADM 工具。以下是按字母顺序排列的可用工具的简短列表。如果您知道任何其他工具,或者对哪些工具好/坏/丑陋有任何想法,请发送电子邮件给 David。

  • John Hardin 的 IPFWADM Dot 文件生成器 - IPCHAINS 版本正在开发中

  • Sonny Parlin 的 fBuilder:来自 FWCONFIG 的作者,这个新的解决方案完全基于 WWW,并为 IPCHAINS 和 NetFilter 提供冗余选项等。

  • William Stearns 的 Mason - 一种动态构建规则集的系统


7.8. ( MASQ 和动态 IP ) - IP Masquerade 是否适用于动态分配的 IP 地址?

,它适用于通过 PPP 或 DHCP 服务器(有线调制解调器和 DSL 用户常见)由您的 ISP 分配的动态 IP 地址。只要您拥有有效的互联网 IP 地址,它就应该可以工作。当然,静态 IP 也可以工作。如果您计划实施强大的 IPTABLES、IPCHAINS 或 IPFWADM 规则集,和/或计划使用端口转发器,则每次您的 IP 地址更改时,都必须重新执行您的规则集。

因此,重新运行 rc-firewall-* 规则集实际上取决于您获取 IP 地址的方式

  • PPP:当 PPP 连接建立时,总是会运行 /etc/ppp/ip-up 脚本。因此,我们可以使 rc.firewall-* 获取新的 PPP IP 地址并更新防火墙规则集。如果 /etc/ppp/ip-up 文件不存在,或者如果存在,只需编辑该文件并在末尾添加一行,其中包含您选择的防火墙规则集的名称。例如,要运行简单的 IPTABLES 规则集

    /etc/rc.d/rc.firewall-iptables
       

  • DHCP:如果您通过 DHCP 获取 IP 地址,这对于有线调制解调器和 DSL 用户来说很常见,那么当您获得新的 IP 租约时,很容易使 rc.firewall-* 规则集运行。这如何发生取决于您的发行版使用的 DHCP 客户端

    • dhclient : 大多数现代 Linux 发行版都使用 ISC 的 dhclient。要在您的系统获得新 IP 地址时重新运行特定的 rc-firewall-* 脚本,请将以下行添加到 /etc/dhclient-exit-hooks 文件中。请注意,此示例正在记录简单的 IPTABLES 规则集。请为您的特定设置使用正确的 rc.firewall-* 名称

      /etc/rc.d/rc.firewall-iptables
          

    • pump : 许多较旧的 Redhat 发行版使用此 DHCP 客户端。要在您的系统获得新 IP 地址时重新运行 rc-firewall-* 脚本,请将以下行添加到 /etc/pump.conf 文件中。请注意,此示例正在加载简单的 IPTABLES 规则集。请为您的特定设置使用正确的 rc.firewall-* 名称

      script /etc/rc.d/rc.firewall-iptables
          

    • dhcpcd : 许多较旧的发行版使用此 DHCP 客户端。要在您的系统获得新 IP 地址时重新运行 rc-firewall-* 脚本,取决于您使用的 dhcpcd 版本。

      对于较新的 dhcpcd 客户端版本,请将以下行添加到 /etc/dhcpcd-[interface].exe 文件中。请注意,您必须将 [interface] 文本替换为连接到互联网的接口的名称。对于此示例,我们将通过编辑 /etc/dhcpc/dhcpcd-eth0.exe 文件,对 eth0 接口运行简单的 IPTABLES 规则集

      /etc/rc.d/rc.firewall-iptables
           

      对于旧的 dhcpcd 客户端版本,您需要弄清楚哪个脚本启动了 dhcpcd(取决于 Linux 发行版及其版本)。从那里,您需要使用以下行替换特定的 dhcpcd 行,并使用正确的面向互联网的接口名称。对于此示例,dhcpcd 将对 eth0 接口运行简单的 IPTABLES 规则集

      dhcpcd -c /etc/rc.d/rc.firewall eth0
          

另请参阅 TrinityOS - 第 10 节的顶部,以获取有关强大防火墙规则集和动态 IP 地址的更多帮助。


7.9. ( MASQ 和各种网络 ) - 我可以使用有线调制解调器(双向和带调制解调器回传)、DSL、卫星链路等连接到互联网并使用 IP Masquerade 吗?

,只要 Linux 支持该网络接口,它就应该可以工作。如果您收到动态 IP 地址,请参阅上面“IP Masquerade 是否适用于动态分配的 IP”常见问题解答项下的 URL。


7.10. ( 按需拨号 ) - 我可以将 Diald 或 PPPd 的按需拨号功能与 IP MASQ 一起使用吗?

当然可以!IP Masquerading 对于 Diald 或 PPP 完全透明。唯一可能成为问题的事情是,如果您将强大的防火墙规则集与动态 IP 地址一起使用。有关更多详细信息,请参阅上面的常见问题解答项“IP Masquerade 是否适用于动态分配的 IP 地址?”。


7.11. ( 应用程序 ) - IP Masquerade 支持哪些应用程序?

跟踪“正在工作的应用程序”列表非常困难。但是,大多数常见的互联网应用程序都受支持,例如 WWW 浏览 (Netscape, MSIE 等)、FTP (例如 WS_FTP)、TELNET、SSH、RealAudio、POP3 (接收邮件 - Pine, Eudora, Outlook)、SMTP (发送邮件) 等。有关 MASQ 兼容客户端的更完整列表,请参阅本 HOWTO 的 第 6.3 节

涉及更复杂协议或特殊连接方法的应用程序,例如视频会议软件,需要特殊的辅助工具。

有关更多详细信息,请参阅 Linux IP 伪装应用程序页面。


7.12. ( 发行版设置 ) - 如何在 Redhat、Debian、Slackware 等系统上运行 IP 伪装?

无论您使用哪个 Linux 发行版,本 HOWTO 中提到的 IP 伪装设置步骤都应适用。某些发行版可能具有 GUI 或特殊的配置文件,使设置更容易。我们已尽力使本 HOWTO 尽可能通用。


7.13. ( 超时 ) - 如果我不经常使用连接,连接似乎会断开。为什么会这样?

默认情况下,IP Masq 将 TCP 会话、TCP FIN 和 UDP 流量的计时器设置为 15 分钟。建议大多数用户使用以下设置(如本 HOWTO 的 /etc/rc.d/rc.firewall-* 规则集中已显示的那样)

使用 IPTABLES 的 Linux 2.4.x

IPMASQ timeouts are NOT adjustable under IPTABLES

使用 IPCHAINS 的 Linux 2.2.x

# MASQ timeouts
#
#   2 hrs timeout for TCP session timeouts
#  10 sec timeout for traffic after the TCP/IP "FIN" packet is received
#  60 sec timeout for UDP traffic (MASQ'ed ICQ users must enable a 30sec 
#     firewall timeout in ICQ itself)
#
/ipchains -M -S 7200 10 60

使用 IPFWADM 的 Linux 2.0.x

# MASQ timeouts 
#
#   2 hrs timeout for TCP session timeouts
#  10 sec timeout for traffic after the TCP/IP "FIN" packet is received
#  60 sec timeout for UDP traffic (MASQ'ed ICQ users must enable a 30sec 
#     firewall timeout in ICQ itself) 
#
/sbin/ipfwadm -M -s 7200 10 60


7.14. ( 异常行为 ) - 当我的互联网连接首次建立时,没有任何工作。如果我再次尝试,一切都正常了。这是为什么?

原因是您有一个动态 IP 地址,当您的互联网连接首次建立时,IP 伪装不知道其 IP 地址。有一个解决方案。在您的 /etc/rc.d/rc.firewall-* 规则集中,添加以下内容

# Dynamic IP users:
#
#   If you get your IP address dynamically from SLIP, PPP, or DHCP, enable this 
#   following option.  This enables dynamic-ip address hacking in IP MASQ, making 
#   the life with Diald and similar programs much easier.
#
echo "1" > /proc/sys/net/ipv4/ip_dynaddr


7.15. ( MTU ) - IP MASQ 似乎工作正常,但某些站点无法访问。这通常发生在 WWW 和一些 FTP 站点上。

根据您在 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 地址重写回原始的 MASQed 计算机。因此,这些关键数据包被丢弃。

不过不用担心。有很多非常好的方法可以解决这个棘手的 MTU 问题

  • 在 PPPoE 中启用 PMTU 钳制

    此解决方案主要适用于通过 PPPoE DSL 或有线调制解调器连接到互联网的现代 2.4.x 和 2.2.x 内核用户。此解决方案允许仅在 MASQ 服务器本身上进行更改,而不是在所有内部 MASQ 客户端上进行更改。

  • 通过 IPTABLES 启用 PMTU 钳制

    此解决方案仅适用于通过任何类型的互联网连接连接的现代 2.4.x 内核用户。此解决方案允许仅在 MASQ 服务器本身上进行更改,而不是在所有内部 MASQ 客户端上进行更改。

  • 更改您的 MASQ 服务器的互联网链路 MTU

    此解决方案适用于任何 Linux 内核版本,但如果您使用 PPPoE 连接进行 DSL 或有线调制解调器,则此解决方案不是一个解决方案。

    应该注意的是,一些用户会反对这个解决方案,因为它可能会损害一些延迟敏感的程序,如 TELNET 和互联网游戏,但影响只是轻微的。另一方面,大多数 HTTP 和 FTP 流量将加速!

  • 更改所有内部 MASQed 机器的 MTU

    此解决方案需要最多的工作,因为您必须对所有内部 IPMASQed 机器进行细微的更改。基本上,您会将所有内部机器上的 MTU 更改为与您的 MASQ 服务器的互联网连接的 MTU 匹配。幸运的是,此解决方案通常是万无一失的,而本节中提到的其他一些解决方案可能很少不起作用。


7.15.1. 为 PPPoE 和某些 PPP 用户启用 PMTU 钳制

对于使用 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
  


7.15.2. 通过 IPTABLES 钳制 MSS

如上文针对 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 模块。


7.15.3. 更改 MASQ 服务器的外部 MTU

此解决方案通常仅适用于拨号用户,因为 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* 设备系统已被弃用,并且它会以非常奇怪的方式破坏某些东西。


7.15.4. 更改各种操作系统的 MTU

如果您重新配置所有 MASQed PC 以使用与您的外部互联网链路的 MTU 相同的 MTU(例如,PPPoE 用户为 1492),一切都应该正常工作,并且这种方法有时是解决问题最有效的方法。这包括上面提到的所有解决方案。但是,如果有很多内部 MASQed 机器,或者如果您没有对所有内部 MASQed 机器的管理访问权限,则以这种方式做事可能会花费大量工作,甚至不可能。

按照以下针对您各自操作系统的简单步骤操作

以下示例利用 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 中。


7.15.4.1. 更改 Linux 上的 MTU

------------------------------------------
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 
------------------------------------------


7.15.4.2. 更改 MS Windows 2000 上的 MTU

------------------------------------------
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.
------------------------------------------


7.15.4.3. 更改 MS Windows NT 4.x 上的 MTU

------------------------------------------
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.
------------------------------------------


7.15.4.4. 更改 MS Windows 98 上的 MTU

------------------------------------------
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.
------------------------------------------


7.15.4.5. 更改 MS Windows 95 上的 MTU

------------------------------------------
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.
------------------------------------------


7.16. ( FTP ) - MASQed FTP 客户端无法工作。

检查“ip_masq_ftp”模块是否已加载。为此,登录到 MASQ 服务器并运行命令“/sbin/lsmod”。如果您没有看到加载“ip_masq_ftp”模块,请确保您遵循了 第 3.4 节 中找到的 BASIC /etc/rc.d/rc.firewall-* 建议。如果您正在实施自己的规则集,请确保包含 HOWTO 中的大部分示例,否则您将遇到许多后续问题。


7.17. ( 性能 ) - IP 伪装似乎很慢

可能有以下几个原因

  • 您可能对调制解调器线路上的可用带宽量不切实际。让我们对典型的 56k 调制解调器连接进行计算

    1. 56k 调制解调器 = 56,000 比特每秒。

    2. 根据美国 FCC 的限制,您实际上并没有 56k 调制解调器,而是 52k 调制解调器。

    3. 您几乎永远不会获得 52k,我曾经获得的最佳连接是约 48k

    4. 48,000 比特每秒是 4,800 字节每秒(每字节 8 比特 + 用于 START 和 STOP RS-232 串行位的 2 比特)

    5. 使用 1500 的 MTU,您将在一秒钟内获得 (3.2) 个数据包。由于这将涉及分片,因此您需要向下舍入为每秒 (3) 个数据包。

    6. 同样使用 1500 的 MTU,即 3.2 x 40 字节的 TCP/IP 开销 (8%)

    7. 因此,在没有压缩的情况下,您可以期望的最佳吞吐量是 4.68KB/s。压缩,无论是 v.42bis 硬件压缩、MNP5 还是 MS/Stac 压缩,在高度可压缩的内容(如 TEXT 文件)上都可以产生令人印象深刻的数字,但在传输预压缩文件(如 ZIP、MP3 等)时实际上会减慢速度。

以太网连接设置(DSL、有线调制解调器、LAN 等)

  • 确保您的内部和外部网络都没有在使用“IP 别名”功能的同一网卡上运行。如果您确实这样做,它可以工作,但由于高水平的冲突、IRQ 使用率等,它会非常慢。强烈建议您为内部和外部网络安装另一张网卡,以拥有自己的接口。

  • 确保您为速度和双工设置了正确的以太网设置。

  • 一些 10Mb/s 以太网卡和大多数 100Mb/s 网卡支持全双工连接。从以太网卡到 DSL 调制解调器(中间没有任何集线器)的直接连接 *可以* 设置为全双工,但前提是 DSL 调制解调器支持它。您还应确保您使用的以太网电缆使用了所有八根线,并且它们状况良好。

    使用集线器的内部网络 - 不能 - 使用全双工。您需要 10 或 100Mb.s 以太网交换机才能做到这一点。

    以太网卡上的自动 10/100Mb/s 速度协商和全/半双工协商都可能破坏网络。我建议尽可能将 NIC 速度和双工都硬编码到 NIC 中。这可以通过 Linux NIC 内核模块直接实现,但在单内核中无法直接实现。您将需要使用来自 第 8.1 节 的 MII 实用程序或硬编码内核源代码。

优化您的 MTU 并将 TCP 滑动窗口设置为至少 8192

  • 虽然这完全超出了本文档的范围,但这对于您拥有的任何网络链路(无论是内部还是外部 PPP、以太网、令牌环等链路)都有很大帮助。有关更多详细信息,请在上面的 第 7.15 节 中简要介绍了该主题。有关更多详细信息,请查看 TrinityOS - 第 16 节 的网络优化部分。

使用 PPP 的基于串行调制解调器的用户

  • 如果您有外部调制解调器,请确保您有一根良好的串行电缆。此外,许多 PC 都使用廉价的带状电缆将串行端口从主板或 I/O 卡连接到串行端口连接。如果您有其中一条,请确保其状况良好。就我个人而言,我在所有带状电缆周围都安装了铁氧体磁环(那些灰黑色的金属环)。

  • 确保您的 MTU 设置为 1500,如上面本 HOWTO 的 FAQ 部分所述

  • 确保您的串行端口是 16550A 或更好的 UART。运行“dmesg | more”进行验证

  • 为您的串行端口设置 IRQ-Tune。

    在大多数 PC 硬件上,使用 Craig Estey 的 IRQTUNE 工具可以显着提高串行端口性能,包括 SLIP 和 PPP 连接。

  • 确保您的 PPP 连接的串行端口以 115200 运行(或者更快,如果您的调制解调器和串行端口都可以处理它...也就是 ISDN 终端适配器)

    • 2.0.x 内核:2.0.x 内核有点奇怪,因为您无法直接告诉内核以 115200 的时钟频率运行串行端口。因此,在您的启动脚本之一(如 /etc/rc.d/rc.local 或 /etc/rc.d/rc.serial 文件)中,为 COM2 上的调制解调器执行以下命令

    • setserial /dev/ttyS1 spd_vhi

    • 在您的 PPPd 脚本中,编辑实际的 pppd 执行行以包含速度“38400”,详见 pppd 手册页。

    • 2.2.x 内核:与 2.0.x 内核不同,2.1.x 和 2.2.x 内核都没有这个“spd_vhi”问题。

      因此,在您的 PPPd 脚本中,编辑实际的 pppd 执行行以包含速度“115200”,详见 pppd 手册页。

所有接口类型


7.18. ( PORTFW ) - 使用 PORTFW 的 IP 伪装在我的线路空闲很长时间后似乎会中断

如果您有 DSL 或有线调制解调器,则此行为非常常见。基本上,您的 ISP 将您的连接放入一个非常低优先级的队列中,以便更好地服务于非空闲连接。问题是一些最终用户的连接实际上将被置于离线状态,直到来自用户 DSL/有线调制解调器连接的一些流量唤醒 ISP 的硬件。

  • 一些 DSL 安装可能会将空闲连接置于离线状态,并且大约每 30 秒才检查一次活动。

  • 一些有线调制解调器设置可以将空闲连接设置为低优先级队列,并且大约每分钟检查一次活动。

我建议怎么做? 每 30 秒 ping 一次您的默认网关。为此,请编辑 /etc/rc.d/rc.local 文件并将以下内容添加到文件末尾

         ping -i 30 100.200.212.121 > /dev/null &

将 100.200.212.121 替换为您的默认路由器(上游路由器)。


7.19. ( PORTFW - 本地 ) - 我无法从内部 LAN 访问我的 PORTFWed 服务器

基本上,假设您的域名 acme.com 的外部 IP 地址为 1.2.3.4,并且您将所有 WWW 流量 PORTFW 到内部机器,例如 192.168.0.20/24。然后,192.169.0.x 网络上的 /内部/ 用户尝试联系 http://www.acme.com 并期望一切正常工作。好吧,使用基本配置,这不会发生。让我解释一下。基本上,http://www.acme.com 正在被您选择的 DNS 服务器解析为 http://1.2.3.4 的 IP。真正应该发生的是,Web 请求应该将该请求解析为 http://192.168.0.20。

看到区别了吗?

对此的正确解决方案是设置一个拆分 DNS 服务器。内部用户将被配置为使用 /内部/ DNS 服务器,当请求 www.acme.com 时,该服务器将使用 192.168.0.20 地址解析此类请求。所有外部用户都应由 /外部/ DNS 服务器提供服务,该服务器会将请求解析为 1.2.3.4 IP 地址。从那里,IPTABLES/IPCHAINS/IPFWADM 然后将像往常一样将流量 PORTFW 到 192.168.0.20 服务器。

但您可能认为您不想设置拆分 DNS 服务器,并且必须有另一种方法。有几种替代方案!第一种替代方案是,如果您只有少数内部机器。在这里,您可以在 *所有* 内部机器上设置“hosts”文件条目。该静态 hosts 条目基本上看起来像

www.acme.com    192.168.0.20

明白了吗? 这样设置后,机器将在转到 DNS 服务器以解析主机之前查阅 hosts 表。这效果很好,但是如果您更改该内部 Web 服务器上的 IP 地址,您将需要手动更新所有这些内部机器上的 hosts 文件。如果您有兴趣采用更具可扩展性的拆分 DNS 方法,TrinityOS 完全涵盖了拆分和 chrooted DNS 服务器。TrinityOS - 第 24 节 http://www.ecst.csuchico.edu/~dranch/LINUX/index-linux.html#trinityos

现在,如果拆分 DNS 和 hosts 文件方法都不能让您感兴趣,您仍然有一个简单但有效的替代方案来使事情正常工作。您可以做的是向您的 rc.firewall-* 规则集添加一些特定规则。请参阅 第 6.7 节 章节下的“内部请求的 PORTFW 重定向”部分。

为什么我没有首先提到这种替代解决方案? 主要原因是它不是理想的解决方案。此方法的主要问题是每个数据包都将从内部 MASQed 客户端发送到 MASQ 服务器。在那里,MASQ 服务器会将每个数据包 SNAT 到内部 MASQed WWW 服务器的 IP,然后将其转发到内部 Web 服务器。一旦 Web 服务器收到并响应数据包,该响应必须再次通过所有这些处理返回到原始客户端机器。此过程在网络带宽和 MASQ 服务器 CPU 周期上都过度浪费!


7.20. ( 日志 ) - 既然我已经启动了 IP 伪装,我在 SYSLOG 日志文件中收到了各种奇怪的通知和错误。我该如何读取 IPTABLES/IPCHAINS/IPFWADM 防火墙错误?

您可能会看到一些常见的事情

  • MASQ: 失败的 TCP 校验和错误: 当来自互联网的数据包在数据部分损坏,但其余部分“看起来”正常时,您可能会看到此错误。当 Linux 盒子收到此数据包时,它将计算数据包的 CRC 并确定其已损坏。在大多数运行 Microsoft Windows 等操作系统的机器上,它们只是静默地丢弃数据包,但 Linux IP MASQ 会报告它。如果您通过 PPP 链路获得大量此类错误,请首先按照上面关于“(性能) - Masq 似乎很慢”的 FAQ 条目进行操作。

    如果(性能)FAQ 提示没有帮助,并且您通过拨号或 PPPoE 运行 PPP,您可以尝试将行“-vj”(禁用 VanJacobson 标头压缩)添加到您的 /etc/ppp/options 文件并重新启动 PPPd 连接。

  • 防火墙命中:因为您在互联网上使用了不错的防火墙,所以您会惊讶于有多少用户试图渗透您的 Linux 盒子!那么所有这些防火墙日志意味着什么?

    更重要的是,如果它们正在填满您的日志,请参阅下一个 FAQ 条目,了解如何减少所有这些日志条目的想法。

  • 以下详细信息来自 TrinityOS - 第 10 节 文档,我也是作者

        With the use of various firewall rulesets, a given ruleset can either 
        DENY (silently drop) or REJECT traffic (sends back a ICMP error).  If 
        firewall logging is enabled, the errors will show up in the SYSLOG
        "messages" file found at:
    
            Redhat: 	/var/log
            Slackware:	/var/adm
    
        If you take a look at one of these firewall logs, you would see something 
        like:
    
        ---------------------------------------------------------------------
        IPTABLES:
        ---------
        Feb 23 07:37:01 Roadrunner kernel: IPTABLES IN=eth0 OUT= 
          MAC=00:50:da:2e:e5:fb:00:03:47:73:c9:d2:08:00 SRC=12.75.147.174 
          DST=100.200.0.212 LEN=44 TOS=0x00 PREC=0x00 TTL=64 ID=39034 DF PROTO=TCP 
          SPT=4313 DPT=23 WINDOW=32120 RES=0x00 SYN URGP=0
    
     
        IPCHAINS:
        ---------
        Feb 23 07:37:01 Roadrunner kernel: input REJECT eth0 PROTO=6 
          12.75.147.174:1633 100.200.0.212:23 L=44 S=0x00 I=54054 F=0x0040 T=64
    
    
        IPFWADM:
        --------
        Feb 23 07:37:01 Roadrunner kernel: IP fw-in rej eth0 TCP 12.75.147.174:1633 
          100.200.0.212:23 L=44 S=0x00 I=54054 F=0x0040 T=64
    
        ---------------------------------------------------------------------
    
    There is a LOT of information in just this one line of SYSLOG.  Lets break
    out this example.  You should refer back to the original firewall hit as you 
    read this.  
    
    --------------
    
        1. ===================================================================
    
    	- This packet firewall "hit" occurred on "Feb 23 07:37:01"
    
        2. ===================================================================
    
    	- This packet was logged on the "RoadRunner" computer via the kernel
    
        3. ===================================================================
    
    	- IPTABLES: the SYSLOG prepend string is "iptables" for information purposes
    
        - IPCHAINS: the packet was stopped on the INPUT chain
    
        - IPFWADM:  the packet was an IP packet
    
        4. ===================================================================
    
        - IPTABLES: the packet came IN on interface "eth0"
    
        - IPCHAINS: the packet was REJECTED (vs. dropped or accepted)
    
        - IPFWADM:  the packet was stopped on INPUT (vs. "fw-out" for OUT or 
           "fw-fwd" for FORWARD)
    
        5. ===================================================================
    
        - IPTABLES: the packet had NO output interface
    
        - IPCHAINS: the packet came in on the "eth0" interface
    
        - IPFWADM:  the packet was REJECTED "rej" (vs. "deny" or "accept")
    
        6. ===================================================================
    
        - IPTABLES: this display's the MAC address of the source and destination
                    Ethetnet MAC address (only relivant for Ethernet networks)
    
        - IPCHAINS: the packet was IP protocol 6 or TCP
    		        * If you don't know that protocol 6 is for TCP, look at 
                      your /etc/protocols file to see what other protocol numbers
                      are used for.
    
        - IPFWADM:  the packet on the "eth0" interface 
    
        7. ===================================================================
    
        - IPTABLES: the packet's source IP address was 12.75.147.174
    
    	- IPCHAINS: the packet's source IP address was 12.75.147.174
    
        - IPFWADM:  the packet was a "TCP" packet 
    
        8. ===================================================================
    
    	- IPTABLES: the packet's destination IP address was 100.200.0.212
    
        - IPCHAINS: the packet's source PORT was 1633 
    
        - IPFWADM:  the packet's source IP address was 12.75.147.174
    
        9. ===================================================================
    
        - IPTABLES: the packet's length was 44 bytes
    
    	- IPCHAINS: the packet's destination IP address was 100.200.0.212
    
        - IPFWADM:  the packet's source PORT was 1633
    
        10. ===================================================================
    
        - IPTABLES: the packet's TOS markings (type of service which basically
                    means class of service) was 0x00 or zero.
    
        - IPCHAINS: the packet's destination PORT was 23 (telnet)
    		        * If you don't know that port 23 is for TELNETing, look at 
                      your /etc/services file to see what other ports are used 
                      for.
    
        - IPFWADM:  the packet's destination IP address was 100.200.0.212 
    
        11. ===================================================================
    
        - IPTABLES: the packet's precedense markings (class of service) was 
                    0x00 or zero.
    
        - IPCHAINS: the packet's length was 44 bytes
    
        - IPFWADM:  the packet's destination PORT was 23 (telnet)
    		        * If you don't know that port 23 is for TELNETing, look at 
                      your /etc/services file to see what other ports are used 
                      for.
    
        12. ==================================================================
    
        - IPTABLES: the packet's TTL or Time to Live was 64 or 64 router hops
    		        * Every router hop over the Internet will subtract (1) from 
                      this number.  Usually, packets will start with a number of 
                      255 (depends on the operating system) and if that number 
                      ever reaches (0), it means that realistically, the packet 
                      was lost in a network loop and should be deleted. 
    
        - IPCHAINS: the packet's TOS markings (type of service which basically
                    means class of service) was 0x00 or zero.
    		        * divide this by 4 to get the Type of Service (presidence) 
    
        - IPFWADM:  the packet was 44 bytes long
    
        13. ==================================================================
    
    	- IPTABLES: the packet had various TCP flags set such as SYN, SYN+ACK,
                    etc. (shown in HEX)
    
        - IPCHAINS: the packet had various TCP flags set (shown in hex)
    
        - IPFWADM:  the packet's TOS markings (type of service which basically
                    means class of service) was 0x00 or zero.
    
        14. ==================================================================
    
    	- IPTABLES: the packet's "don't fragment" or DF bit was set from the 
                    source computer
    
        - IPCHAINS: the packet had a fragmentation offset of 40 (shown in HEX)
    
    		        --Don't worry if you don't understand this.. 
    		        * A value that started with "0x2..." or "0x3..." means the 
                      "More Fragments" bit was set so more fragmented packets 
                      will be coming in to complete this one BIG packet.
    		        * A value which started with "0x4..." or "0x5..." means that 
                      the "Don't Fragment" bit was set  
    		        * Any other values are the Fragment offset (divided by 8) to 
                      be later used to recombine into the original LARGE packet
    
    	- IPFWADM:  the packet had various TCP flags set such as SYN, SYN+ACK,
                    etc. (shown in HEX)
    
        15. ==================================================================
    
    	- IPTABLES: the packet was a TCP packet
    
        - IPCHAINS: the packet's TTL or Time to Live was 64 or 64 router hops
    		        * Every router hop over the Internet will subtract (1) from 
                      this number.  Usually, packets will start with a number of 
                      255 (depends on the operating system) and if that number 
                      ever reaches (0), it means that realistically, the packet 
                      was lost in a network loop and should be deleted. 
    
        - IPFWADM:  the packet had a fragmentation offset of 40 (shown in HEX)
    
    		        --Don't worry if you don't understand this.. 
    		        * A value that started with "0x2..." or "0x3..." means the 
                      "More Fragments" bit was set so more fragmented packets 
                      will be coming in to complete this one BIG packet.
    		        * A value which started with "0x4..." or "0x5..." means that 
                      the "Don't Fragment" bit was set  
    		        * Any other values are the Fragment offset (divided by 8) to 
                      be later used to recombine into the original LARGE packet
    
        16. ==================================================================
    
        - IPTABLES: the packet's soure PORT was 4313
    
        - IPCHAINS: 
    
        - IPFWADM:  the packet's TTL or Time to Live was 64 or 64 router hops
    		        * Every router hop over the Internet will subtract (1) from 
                      this number.  Usually, packets will start with a number of 
                      255 (depends on the operating system) and if that number 
                      ever reaches (0), it means that realistically, the packet 
                      was lost in a network loop and should be deleted. 
    
        17. ==================================================================
    
        - IPTABLES: the packet's destination PORT was 23 (telnet)
    		        * If you don't know that port 23 is for TELNETing, look at 
                      your /etc/services file to see what other ports are used 
                      for.
    
        - IPCHAINS:
    
        - IPFWADM: 
    
        18. ==================================================================
    
        - IPTABLES: the packet's TCP window (sliding or selective TCP ack)
                    was 32120 bytes
    
        - IPCHAINS:
    
        - IPFWADM:
    
        19. ==================================================================
    
        - IPTABLES: the packet's TCP reserved bits were 0x00 (HEX) - unused
    
        - IPCHAINS:
    
        - IPFWADM:
    
        20. ==================================================================
    
        - IPTABLES: the packet's TCP header SYN bit was set
                    * IPTABLES displays all the TCP header bits by name and not
                      by a HEX dump
    
        - IPCHAINS:
    
        - IPFWADM:
    
        21. ==================================================================
    
        - IPTABLES: the packet's TCP header URGENT bit was set - rarely used
    
        - IPCHAINS:
    
        - IPFWADM:
    


7.21. ( 日志减少 ) - 由于新的“更强”的规则集,我的日志被数据包命中填满了。我该如何解决这个问题?

因此,您意识到一个好的防火墙正在捕获大量不良的互联网流量。这是一件好事,但它也正在填满您的日志,以至于您不会阅读它们;这是一件坏事。该怎么办?

您需要弄清楚您不想要记录哪些流量,在防火墙中显式匹配这些数据包,并在丢弃数据包时记录它们。

例如,第 10.7 节中的 TrinityOS 防火墙规则集(在 IPMASQ 术语中,这将是“最强”的规则集)提供了一些想法:TrinityOS - 第 10.7 节

我建议过滤的东西

  • 所有 RFC1918 地址空间(TCP/IP 地址范围:10.x.y.z/8、172.16-31.y.z/12 和 192.168.y.x/16)。您应该永远不会从互联网连接收到这些数据包。如果您收到,它们很可能是欺骗数据包

  • Windows 文件和打印共享(Samba 或 CIFS):端口 137、138、139 和 445。Windows 机器喜欢说很多话,尽管大多数计算机并不关心它们在说什么。

  • D 类多播地址(如果您不使用多播):224.0.0.0/4

  • E 类和 F 类“未来”地址:240.0.0.0/5 和 248.0.0.0/5

在较小程度上,您可能想要过滤其他数据包。我建议您在过滤掉这些特定数据包类型之前,先验证您是否正在接收它们。

  • RIP(路由协议):端口 520

  • 某些特定形式的 ICMP 数据包 - 不是所有数据包(这将破坏您的机器和一般的 IPMASQ)

最后,您可能会发现互联网上的某些单独的 TCP/IP 地址似乎总是在攻击您的 IP。因此,除了像上面那样过滤各种端口之外,您可能还想按特定的源 IP 地址进行过滤。毕竟,它是 *您的* 防火墙。


7.22. ( MASQ 安全性 ) - 我可以配置 IP MASQ 以允许互联网用户直接联系内部 MASQed 服务器吗?

是的! 使用 IPPORTFW,您可以允许所有或仅选择少数互联网主机联系您的任何内部 MASQed 计算机。本主题在本 HOWTO 的 第 6.7 节 中完全涵盖。


7.23. ( 空闲端口 ) - 我在 SYSLOG 文件中收到“kernel: ip_masq_new(proto=UDP): no free ports.”。这是怎么回事?

您的一个内部 MASQed 机器正在创建异常大量的目标为互联网的数据包。当 IP Masq 服务器构建 MASQ 表并将这些数据包转发到互联网上时,该表正在快速填充。一旦表被填满,它将给您这个错误。

我知道的唯一会暂时造成这种情况的应用程序是一个名为“GameSpy”的游戏程序。为什么? Gamespy 构建一个服务器列表,然后 ping 列表中的所有服务器(数千个游戏服务器)。通过创建所有这些 ping,它在很短的时间内创建了数千个快速连接。在这些会话通过 IP MASQ 超时之前,MASQ 表变得“已满”。

那么您能对此做些什么呢? 实际上,不要使用执行此类操作的程序。如果您在日志中收到此错误,请找到它并停止使用它。如果您真的喜欢 GameSpy,只是不要太频繁地刷新服务器。无论如何,一旦您停止运行此 MASQed 程序,此 MASQ 错误就会消失,因为这些连接最终将在 MASQ 表中超时。


7.24. ( SETSOCKOPT ) - 当我尝试使用 IPPORTFW 时,我收到“ipfwadm: setsockopt failed: Protocol not available”!

如果您收到错误消息 "ipfwadm: setsockopt failed: Protocol not available",则说明您没有运行新的内核。请确保您已移动了新内核,重新运行 LILO,然后再次重启。

请参阅 第 6.7 节 的末尾以获取完整详细信息。


7.25. ( SAMBA ) - Microsoft 文件和打印共享以及 Microsoft 域客户端无法通过 IP Masq 工作!

为了正确支持 Microsoft 的 SMB 协议,需要编写一个 IP Masq 模块,但有三种可行的解决方法。有关更多详细信息,请参阅 这篇 Microsoft 知识库文章

解决此问题的第一个方法是从 第 6.7 节 配置 IPPORTFW,并将 TCP 端口 137、138 和 139 portfw 到内部 Windows 机器的 IP 地址。虽然此解决方案有效,但它仅适用于一台内部机器。

第二个解决方案是在 Linux MASQ 服务器上安装和配置 Samba。在 Samba 运行的情况下,您可以将内部 Windows 文件和打印共享映射到 Samba 服务器上。然后,您可以将这些新挂载的 SMB 共享挂载到您的所有外部客户端。Linux 文档项目和 TrinityOS 文档中找到的 HOWTO 中完全涵盖了 Samba 的配置。

第三个解决方案是在两台 Windows 机器之间或两个网络之间配置 VPN(虚拟专用网络)。这可以通过 PPTP 或 IPSEC VPN 解决方案来完成。Linux 有一个 第 7.35 节 补丁,并且 2.0.x 和 2.2.x 内核都提供了完整的 IPSEC 实现。此解决方案可能是所有三种解决方案中最可靠和最安全的方法。

所有这些解决方案都不在本 HOWTO 的涵盖范围内。我建议您查看 TrinityOS 文档以获取 IPSEC 帮助,并查看 John Hardin 的 PPTP 页面以获取更多信息。

另请理解,Microsoft 的 SMB 协议非常不安全。因此,在没有任何加密的情况下通过互联网运行 Microsoft 文件和打印共享或 Windows 域登录流量是一个非常糟糕的主意。


7.26. ( IDENT ) - MASQed IRC 用户的 IRC 无法正常工作。为什么?

主要可能的原因是,大多数常见的 Linux 发行版的 IDENT 或“身份”服务器无法处理 IP 伪装链接。不过不用担心,有一些 IDENT 可以工作。

安装此软件超出了本 HOWTO 的范围,但每个工具都有自己的文档。以下是一些 URL

请注意,即使某些 Internet IRC 服务器获得了 Ident 信息并且用户不同,它们仍然不允许来自同一主机的多个连接。向远程系统管理员投诉。 :-)


7.27. ( IRC DCC ) - mIRC 无法使用 DCC 发送

这是您的 mIRC 副本上的配置问题。要解决此问题,首先断开 mIRC 与 IRC 服务器的连接。现在在 mIRC 中,转到文件 --> 设置,然后单击“IRC 服务器选项卡”。确保它设置为端口 6667。如果您需要其他端口,请参见下文。接下来,转到文件 --> 设置 --> 本地信息,然后清除本地主机和 IP 地址的字段。现在选中“本地主机”和“IP 地址”的复选框(IP 地址可能已选中但已禁用)。接下来在“查找方法”下,将其配置为“正常”。如果选择“服务器”,则它将不起作用。就这样。再次尝试连接到 IRC 服务器。

如果您需要 6667 以外的 IRC 服务器端口(例如,6969),您需要编辑 /etc/rc.d/rc.firewall-* 启动文件,您在该文件中加载 IRC MASQ 模块。编辑此文件和“modprobe ip_masq_irc”行,并将“ports=6667,6969”添加到此行。您可以添加其他端口,只要它们用逗号分隔即可。

最后,关闭任何 MASQed 机器上的任何 IRC 客户端,并重新加载 IRC MASQ 模块

/sbin/rmmod ip_masq_irc /etc/rc.d/rc.firewall-*


7.28. ( IP 别名 ) - IP 伪装可以使用只有一个以太网网卡工作吗?

是也不是。使用“IP 别名”内核功能,用户可以设置多个别名接口,例如 eth0:1、eth0:2 等,但不建议将别名接口用于 IP 伪装。为什么?使用单个 NIC 卡,提供安全的防火墙变得非常困难。除此之外,您将在此链路上体验到异常大量的错误,因为传入的数据包几乎同时被发送出去。由于所有这些原因,并且 NIC 卡现在的价格低于 10 美元,我强烈建议为每个 MASQed 网段购买一张 NIC 卡。

用户还应该理解,IP 伪装 (IP Masquerading) 只能用于物理接口,例如 eth0、eth1 等。对别名接口(如 "eth0:1, eth1:1, 等等")进行伪装将不起作用。换句话说,以下操作将无法可靠地工作:

  • 有传言说,您可以简单地使用目标 IP 地址(与别名接口如 eth0:1 等关联的 IP 地址)来代替指定接口 (eth0:1)。这个解决方案未经测试 -- 如果您有任何正面或负面的结果,请发送电子邮件至 dranch@trinnet.net

  • /sbin/ipchains -A forward -i eth0:1 -s 192.168.0.0/24 -j MASQ"

  • /sbin/ipfwadm -F -a m -W eth0:1 -S 192.168.0.0/24 -D 0.0.0.0/0

如果您仍然对使用别名接口感兴趣,则需要在内核中启用 "IP 别名" 功能。然后您需要重新编译并重启。一旦运行新的内核,您需要配置 Linux 以使用新的接口(即 eth0:1 等)。之后,您可以将其视为普通的以太网接口,但有一些限制,例如上面的限制。


7.29. ( 多 LAN ) - 我有两个 MASQed LAN,但它们无法互相通信!

请参阅 第 6.5 节 以获取完整详细信息。


7.30. ( 整形 (SHAPING) ) - 我想限制特定类型流量的速度

我收到很多人发来的电子邮件,询问类似以下内容的问题:

How can I control the internet bandwidth among the LAN PCs behind the IPMASQ
server? Some times any local pc is downloading and it it will take the majority
of the bandwidth and thus the other PCs get little bandwidth. 

这个主题实际上与 IPMASQ 没有任何关系,而与 Linux 内置的流量整形和速率限制能力有关。您可以在 LDP 上找到有关此方面的信息,例如 ADSL 带宽 HOWTO高级路由 HOWTO带宽限制 HOWTO。请理解这是一个高级主题,您可能有的任何问题最好向这些论坛的人们咨询。


7.31. ( 记账 (ACCOUNTING) ) - 我需要对谁在使用网络进行记账

虽然这与 IPMASQ 没有太大关系,但这里有一些想法。如果您知道更好的解决方案,请发送电子邮件给本 HOWTO 的作者,以便可以将其添加到 HOWTO 中。

  • 想法 #1:您可以运行命令

    IPCHAINS: "ipchains -L -M" 
    
    IPTABLES: "cat /proc/net/ip_conntrack"
    
    IPFWADM:
    每秒一次并记录所有这些条目。然后您可以编写一个程序将这些信息合并到一个大文件中。同样,这只会为您提供远程 IP 地址,而不会提供有关查看或下载内容的信息。

  • 想法 #2:记录每个数据包:您可以匹配任何特定的流量流,但此方法将创建非常大的日志文件。不幸的是,这些日志文件不是很可读,并且没有告诉您传输了什么(FTP 文件等)。幸运的是,设置这种形式的记账很容易。

  • 想法 #3:假设您想记录所有流向互联网的流量。您可以设置一个防火墙规则来接受 SYN 位已设置的端口 80 流量并记录它。请注意,这会创建比上述想法小的日志文件,但您只会知道目标 IP 地址,而不知道查看了哪些 WWW 页面。

  • 想法 #4:透明代理:此方法实际上不使用 IPMASQ,因为它需要安装和设置 Squid HTTP/FTP 代理服务器。此方法的好处是内部用户不会注意到连接方面的任何差异,但现在系统管理员可以获得更多信息(下载的文件等)。但是,设置此方法有利弊。

    优点

    • + 完全记录所有传输的文件和发出的 FTP 命令

    • + 您可以在代理服务器上启用缓存。通过缓存,您可以节省带宽,因为一旦下载文件,任何相同的文件请求都将通过缓存提供服务,而不会通过互联网连接重新下载。

    缺点

    • - 设置透明代理很复杂,因为它需要内核更改、设置 Squid 等。

    • - 对于小型安装来说可能有点过分。

    有关更多详细信息,请参阅 高级路由 HOWTO


7.32. ( 多 IP - DMZ 网段 ) - 我有几个外部 IP 地址,我想将端口转发 (PORTFW) 到几台内部机器。我该怎么做?

虽然技术上可行,但不要使用 IP MASQ 执行此操作。对于这种网络设计,有更好的解决方案。

MASQ 是一种 1:多 NAT 设置,它是执行您正在寻找的操作的错误工具。您正在寻找的是多:多 NAT 解决方案或桥接设置。

注意:对于那些考虑使用 "IP 别名" 在一个内部 NIC 上启用多个 IP 地址,然后 PORTFW 所有这些端口 (0-65535),并最终使用 IPROUTE2 来维护正确的源/目标 IP 对的用户。这在 2.0.x 内核上已成功完成,在 2.2.x 内核上不太成功。无论成功与否,都不是正确的方法,这完全是黑客行为,并且不是受支持的 MASQ 配置。请认真考虑 2.4.x 内核上的 IPTABLES,或者在较小程度上,考虑 第 7.30 节 中针对 2.2.x 内核的 IPROUTE2。

无论如何,对于将外部 IP 地址转发到内部主机,您基本上有三种可能性:

  • 1. Route the external IPs 
    
       (This does NOT involve IPMASQ at all but requires special WAN addressing 
        and routing setup from your ISP):
    
        Internet -- Some public WAN -- Linux -- DMZ segment
                       IP address      Server     PUBLIC IPs
                                         |
                                         +------ Internal net
                                                  private IPs

  • 2. 1:1 NAT 
    
       (Most easily done via IPTABLES or with IPCHAINS and IPROUTE2 but still 
        some protocols cannot deal with NAT)
    
        Internet -- Linux -- DMZ segment
                    Server     Private IPs natted to 1:1 PUBLIC IPs
                       |
                       +------ Internal net
                                private IPs
    

  • 3. Bridging or ProxyARP:  
    
       The Bridging method is one of the more popular methods that many commercial 
       firewalls do and it's very slick.  Alternatively, you can use the ProxyARP 
       method which works well without some of the complications (or benefits of
       bridging).  With both solutions, all public IPs can transparently flow 
       through the Linux server to the DMZ but via firewall inspection.
    
        Internet -- Linux -- DMZ segment
                    Server     PUBLIC IPs
                      |
                      +------ Internal net
                               private IPs
    

这些解决方案各有优缺点

项目 #1:如果您足够幸运,您的 ISP 会为您设置此项(非常罕见),您只需要使用基本的 'route' 命令即可使其运行。这是最强大的解决方案,并且不需要任何形式的 IPMASQ 或 NAT 才能工作。

项目 #2:1:1 NAT 尚未在本 HOWTO 中介绍,但如果您需要帮助,请给我发送电子邮件,我会为您提供帮助。

项目 #3:ProxyARP 非常简单明了,但仅在特定情况下有效,并且仅适用于以太网网络。桥接功能更强大,但可能需要重新编译内核和进行一些高级配置。最终,这些解决方案都不再是 IPMASQ,因此我无法帮助您设置它们。幸运的是,还有其他 HOWTO 介绍了这个主题

注意: 如果您有桥接 DSL 或有线调制解调器连接(非 PPPoE),情况会有点困难,因为您的设置未路由。不过不用担心,请查看 Bridge+Firewall Mini HOWTOBridge+Firewall+DSL Mini HOWTO。这些 HOWTO 将教您如何让您的 Linux 机器在一个接口上支持多个 IP 地址!


7.33. ( 1:1 NAT ) - 我想进行 1:1 NAT,但我不知道该怎么做

有关所有详细信息,请参阅先前名为 第 7.32 节 的 FAQ 条目。


7.34. ( Netstat ) - 我正在尝试使用 NETSTAT 命令来显示我的伪装连接,但它不起作用

在基于 2.0.x 的 Linux 发行版中的 "netstat" 程序可能存在问题。在 Linux 重启后,运行 "netstat -M" 工作正常,但在 MASQed 计算机运行一些成功的 ICMP 流量(如 ping、traceroute 等)后,您可能会看到类似以下内容:

masq_info.c: 内部错误 `ip_masquerade unknown type'。

此问题的解决方法是使用 "/sbin/ipfwadm -M -l" 命令。您还会注意到,一旦列出的 ICMP 伪装条目超时,"netstat" 又可以正常工作了。


7.35. ( VPN ) - 我想让 Microsoft PPTP (GRE 隧道) 和/或 IPSEC (Linux SWAN) 隧道通过 IP MASQ 运行

对于特定模式,这是可能的。具体来说,所有内核版本(2.4.x、2.2.x 和 2.0.x)都支持补丁,允许一个或多个 PPTP 用户通过 IPMASQ 服务器连接到 -同一- PPTP 服务器。2.4.x 内核目前在最新版本的 IPTABLES 程序中有一个 PPTP 模块,IPMASQ WWW 站点上还有另一个版本可用。请查看 John Hardin 的 PPTP Masq 页面以获取详细信息。


7.36. ( 游戏 ) - 我想让 XYZ 网络游戏通过 IP MASQ 工作,但它不起作用。求助!

首先,查看 Steve Grevemeyer 的 MASQ 应用程序页面。如果您的解决方案未在其中列出,请尝试使用 Glenn Lamb 的 http://ipmasq.webhop.net/files20/loose-udp-2.0.36.patch.gz LooseUDP 补丁修补您的 Linux 内核,该补丁在上面的 第 6.10 节 中介绍。另请查看 Dan Kegel 的 NAT 页面 以获取更多信息。

如果您在技术方面有天赋,请使用程序 "tcpdump" 并嗅探您的网络。尝试找出您的 XYZ 游戏正在使用哪些协议和端口号。掌握这些信息后,订阅 IP Masq 邮件列表 并发送您的结果以寻求帮助。


7.37. ( 停止工作 ) - IP MASQ 一段时间内工作正常,但随后停止工作。重启似乎可以解决此问题。为什么?

我敢打赌您正在使用 IPAUTOFW 和/或您已将其编译到内核中,对吗?这是 IPAUTOFW 的已知问题。建议甚至不要将 IPAUTOFW 配置到 Linux 内核中,而是使用 IPPORTFW 选项。这在 第 6.7 节 中有更详细的介绍。


7.38. ( SMTP 中继 ) - 内部 MASQed 计算机无法发送 SMTP 或 POP-3 邮件!

虽然这不是伪装问题,但许多用户这样做,因此应该提及。

SMTP:问题是您可能正在使用您的 Linux 机器作为 SMTP 中继服务器,并收到以下错误:

"error from mail server: we do not relay"
较新版本的 Sendmail 和其他邮件传输代理 (MTA) 默认禁用中继(这是一件好事)。因此,请执行以下操作来解决此问题:

  • Sendmail:通过编辑 /etc/sendmail.cw 文件并添加内部 MASQed 机器的主机名和域名,为您的内部 MASQed 机器启用特定中继。您还应该检查 /etc/hosts 文件是否已配置了 IP 地址和完全限定域名 (FQDN)。完成后,您需要重启 Sendmail 以使其重新读取其配置文件。这在 TrinityOS - 第 25 节 中介绍。

POP-3:一些用户将其内部 MASQed 计算机的 POP-3 客户端配置为连接到某些外部 SMTP 服务器。虽然这很好,但许多外部 SMTP 服务器会尝试在端口 113 上 IDENT 您的连接。您的问题很可能源于您的默认伪装策略设置为 DENY。这是不好的。将其设置为 REJECT 并重新运行您的 rc.firewall-* 规则集。


7.39. ( 源路由 ) - 我需要不同的内部 MASQed 网络从不同的外部 IP 地址出口

假设您有以下设置:您有多个内部网络以及多个外部 IP 地址和/或网络。您想做的是让 LAN #1 仅使用外部 IP #1,但您希望 LAN #2 使用外部 IP #2。

内部 LAN ----------> 官方 IP

LAN #1 外部 IP #1 192.168.0.x --> 123.123.123.11

LAN #2 外部 IP #2 192.168.1.x --> 123.123.123.12

基本上,我们在这里描述的是不仅基于目标地址(典型的 IP 路由)的路由,而且还基于源地址的路由。这通常称为 "基于策略的路由" 或 "源路由"。此功能在 2.0.x 内核中不可用,对于 2.2.x 内核,它通过 IPROUTE2 包可用,并且它已内置到使用 IPTABLES 的新 2.4.x 内核中。

首先,您必须理解,IPFWADM 和 IPCHAINS 都在路由系统决定将给定数据包发送到何处 *之后* 介入。这个声明真的应该用大红色字母印在所有 IPFWADM/IPCHAINS/IPMASQ 文档上。原因是用户必须首先设置正确的路由,然后开始添加 IPFWADM/IPCHAINS 和/或 Masq 功能。

无论如何,对于上面显示的示例情况,您需要说服路由系统将来自 192.168.0.x 的数据包通过 123.123.1233.11 指向,并将来自 192.168.1.x 的数据包通过 123.123.123.12 指向。那是最难的部分,在正确的路由之上添加 Masq 很容易。

要进行这种花哨的路由,您将使用 IPROUTE2。由于此功能与 IPMASQ 没有任何关系,因此本 HOWTO 不会详细介绍此主题。有关此主题的完整 URL 和文档,请参阅 第 2.7 节

“iprule” 和 “iproute” 命令与 “ip rule” 和 “ip route” 命令相同(我更喜欢前者,因为它更容易搜索)。以下所有命令都未经完全测试,如果它们不起作用,请告知 David Ranch,但请联系 IPROUTE2 邮件列表寻求帮助。此功能与 IP 伪装没有任何关系。

2.4.x 内核

以下内容将集成到您的 rc.firewall-iptables 规则集的末尾

 EXTIF="eth0"
 INTNET1="192.168.0.0/24"
 INTNET2="192.168.1.0/24"
 EXTIP1="123.123.123.11"
 EXTIP2="123.123.123.12"

 iptables -t nat -A POSTROUTING -o $EXTIF -s $INTNET1 -j SNAT --to $EXTIP1
 iptables -t nat -A POSTROUTING -o $EXTIF -s $INTNET2 -j SNAT --to $EXTIP2
 

2.2.x 内核

前几个命令只需要在启动时执行一次,例如在 /etc/rc.d/rc.local 文件中。

# Allow internal LANs to route to each other, no masq.
  /sbin/iprule add from 192.168.0.0/16 to 192.168.0.0/16 table main pref 100
# All other traffic from 192.168.1.x is external, handle by table 101
  /sbin/iprule add from 192.168.1.0/24 to 0/0 table 101 pref 102
# All other traffic from 192.168.2.x is external, handle by table 102
  /sbin/iprule add from 192.168.2.0/24 to 0/0 table 102 pref 102

These commands need to be issued when eth0 is configured, perhaps in 
/etc/sysconfig/network-scripts/ifup-post (for Redhat systems).  Be sure to
do them by hand first to make sure they work.

# Table 101 forces all assigned packets out via 123.123.123.11
  /sbin/iproute add table 101 via 123.123.123.11
# Table 102 forces all assigned packets out via 123.123.123.12
  /sbin/iproute add table 102 via 123.123.123.12

At this stage, you should find that packets from 192.168.1.x to the
outside world are being routed via 123.123.123.11, packets from
192.168.2.x are routed via 123.123.123.12.

It is IMPORTANT that these IPROUTE2 rules be run /BEFORE/ the rc.firewall-*
ruleset is run.  

If everything hangs together, the masq code will see packets being
routed out on 123.123.123.11 and 123.123.123.12 and will use those addresses
as the masq source address.


7.40. ( 2.4.x 内核上的 IPCHAINS 规则集 ) - ipchains.o 模块在 2.4.x 内核上可以做什么

有些人希望继续在基于 2.4.x 的内核上使用他们遗留的 IPCHAINS 规则集。不幸的是,除非您仅进行数据包防火墙过滤,并且不尝试进行任何 NAT (MASQ)、PORTFW 或其他高级功能,否则您会遇到麻烦。

  • 如果您只是进行 IPCHAINS 过滤,您需要做的就是卸载来自 "/sbin/lsmod" 命令显示的所有 IPTABLES 模块。之后,通过运行 "/sbin/modprobe ipchains" 加载 IPCHAINS 模块。之后,像往常一样加载您的 IPCHAINS 规则集。

    • 请注意,如果您将 IPTABLES 支持静态编译到内核中,则无法加载 "ipchains" 模块(它甚至不应该存在),因为它会与 IPTABLES 内核代码冲突。在这种情况下,您唯一的选择是重新编译您的内核,但将 IPTABLES 和 IPCHAINS 选项作为模块。

那么为什么您不能在 2.4.x 内核上运行 IPCHAINS MASQ/PORTFW 功能呢?加载 IPCHAINS 模块后,您无法使用任何 IPTABLES 命令或模块,因为代码冲突。除此之外,您不能在 2.4.x 内核上使用任何遗留的 2.2.x IPCHAINS masq 模块,因为内核差异非常大。此外,这真的不应该是一个问题,因为所有这些功能现在都通过原生 IPTABLES 模块提供。最后,您不能将 IPMASQADM 工具与 2.4.x 内核一起使用,因为该程序既不会编译,最终 PORTFW 内核处理程序也不再存在(现在由 IPTABLES 代码原生完成)。因此,考虑到所有这些事实:

  • 您无法在此 2.4.x 机器上运行任何形式的 PORTFW

  • 需要特殊处理的协议,如 FTP、IRC、CuSeeme、RealAudio 等,将不再工作

基本上,2.4.x 内核附带的 ipchains 内核模块旨在实现基本的数据包防火墙兼容性,而不是任何 NAT(MASQ) 功能。


7.41. ( IPTABLES vs. IPCHAINS vs. IPFWADM ) - 为什么 2.4.x、2.2.x 和 2.0.x 内核使用不同的防火墙系统?

IPTABLES 支持以下 IPCHAINS 和 IPFWADM 不支持的功能:

  • 有状态 IPv4 协议和应用程序跟踪

  • 有状态 IPv6 协议跟踪

  • 真正的 1:1 和 1:多 NAT

  • 内置 PORTFW 功能

  • 有关更多详细信息,请参阅 第 2.6 节

IPCHAINS 支持以下 IPFWADM 不支持的功能:

  • “服务质量” (QoS 支持)

  • TREE 样式链系统 vs. 像 IPFWADM 这样的线性系统(例如,这允许类似“如果是 ppp0,则跳转到此链(其中包含其自己的一组不同的规则)”的操作)

  • IPCHAINS 在配置方面更灵活。例如,它具有 "replace" 命令(除了 "insert" 和 "add" 之外)。您还可以否定规则(例如,“丢弃任何不来自我注册 IP 的出站数据包”,这样您就不会成为欺骗攻击的来源)。

  • IPCHAINS 可以显式过滤任何 IP 协议,而不仅仅是 TCP、UDP、ICMP


7.42. ( 升级 ) - 我刚刚升级到 x.y.z 内核,为什么 IP 伪装不起作用?

假设您的 Linux IP Masq 机器已经与互联网和您的 LAN 建立了正确的连接,您应该检查以下几件事:

  • 确保您已编译并加载了必要的功能和模块。有关详细信息,请参阅前面的章节。

  • 检查/usr/src/linux/Documentation/Changes并确保您安装了网络工具的最低要求。

  • 确保您已按照 HOWTO 的 第 5 章 中的所有测试进行操作。

  • 确保您为您的内核使用了正确的防火墙工具,无论是 IPTABLES、IPCHAINS 还是 IPFWADM。

  • 如果您正在执行 PORTFW 功能,请确保为您的内核版本使用正确的工具。IPTABLES 具有所有内置功能,IPCHAINS 需要使用 IPMASQADM,而 IPFWADM 需要使用 IPPORTFW 或 IPAUTOFW。这在 第 6.7 节 中完全介绍。

  • 再次检查所有设置和配置!通常,这只是一个错别字或您忽略的简单错误。


7.43. ( EQL ) - 我需要 EQL 连接和 IP Masq 方面的帮助

EQL 与 IP Masq 无关,尽管它们通常在 Linux 机器上组合在一起。因此,我建议查看新版本的 Robert Novak 的 EQL HOWTO,以满足您的所有 EQL 需求。


7.44. ( 认输 (Wussing out) ) - 我无法让 IP 伪装工作!对于 Windows 平台,我有什么选择?

是否要放弃在最低硬件上运行的免费、可靠、高性能的解决方案,而花费巨资购买需要更多硬件、性能更低且我说过不太可靠的东西?(恕我直言。是的,我对此有实际经验 ;-)

好吧,这是您的选择。如果您想要 Windows NAT 和/或代理解决方案,这里有一个不错的列表。我没有特别偏爱这些工具中的任何一个,尤其是我以前没有使用过它们。

最后,在网络上搜索 "MS Proxy Server"、"Wingate"、"WinProxy",或访问 www.download.com。绝对不要告诉任何人是我们发送您来的。


7.45. ( 开发者 ) - 我想帮助 IP 伪装开发。我能做什么?

加入 Linux IP 伪装开发者列表,并询问那里的开发者您可以做些什么来提供帮助。有关加入列表的更多详细信息,请查看 第 7.5 节 FAQ 部分。

请不要在那里提出与非 IP 伪装开发相关的问题!!!!


7.46. ( 更多信息 ) - 在哪里可以找到有关 IP 伪装的更多信息?

您可以在 Ambrose Au 维护的 Linux IP 伪装资源 中找到有关 IP 伪装的更多信息。

您还可以在 Dranch 的 Linux 页面 中找到更多信息,其中保留了 TrinityOS 和其他 Linux 文档。

您还可以在 Indyramp Consulting 维护的半原始 Linux IP 伪装网站 中找到更多信息,Indyramp Consulting 也提供 IP Masq 邮件列表。

最后,您可以在 IP MASQ 和 IP MASQ DEV 电子邮件存档中查找特定问题,或在这些列表中提出特定问题。查看 第 7.5 节 FAQ 项目以获取更多详细信息。


7.47. ( 翻译人员 ) - 我想将此 HOWTO 翻译成另一种语言,我应该怎么做?

确保您要翻译的语言尚未被其他人涵盖。但是,大多数翻译后的 HOWTO 现在都已过时,需要更新。Linux IP 伪装资源 上提供了可用 HOWTO 翻译的列表。

如果您的目标语言中没有 当前 IP MASQ HOWTO 的副本,请从 Linux IP 伪装资源 下载最新版本的 IP-MASQ HOWTO SGML 代码。从那里开始您的工作,同时保持良好的 SGML 编码。有关 SGML 的更多帮助,请查看 www.sgmltools.org


7.48. ( 更新 ) - 此 HOWTO 似乎已过时,您还在维护它吗?您可以包含更多关于...的信息吗?是否有任何使其更好的计划?

是的,此 HOWTO 仍在维护中。过去,Ambrose 因为太忙于两份工作而没有太多时间来处理此事,我深感抱歉。自 v1.50 起,David Ranch 修改了文档并使其再次成为最新版本。

如果您想到可以包含在 HOWTO 中的主题,请发送电子邮件 dranch@trinnet.net。如果您可以提供该信息,那就更好了。一旦发现合适并经过测试,我们就会将该信息包含在 HOWTO 中。非常感谢您的贡献!

我们有很多新想法和计划来改进 HOWTO,例如将涵盖涉及 IP 伪装的不同网络设置的案例研究、通过强大的 IPFWADM/IPCHAINS 防火墙规则集提高安全性、IPCHAINS 用法、更多 FAQ 条目等。如果您认为可以提供帮助,请这样做!谢谢。


7.49. ( 感谢 ) - 我让 IP 伪装工作了,太棒了!我想感谢你们,我能做什么?

  • 您可以将新版本的 HOWTO 翻译成另一种语言吗?

  • 感谢开发者,并感谢他们为此花费的时间和精力。

  • 加入 IP 伪装邮件列表并支持新的 MASQ 用户

  • 给我们发送一封电子邮件,让我们知道您有多高兴

  • 向其他用户介绍 Linux,并在他们遇到问题时帮助他们。


第 8 章. 杂项

8.1. 有用资源


8.2. Linux IP 伪装资源

Linux IP 伪装资源 是一个专门介绍 Linux IP 伪装信息的网站,也由 Ambrose Au 维护。它具有与 IP 伪装相关的最新信息,并且可能包含未包含在 HOWTO 中的信息。

您可以在以下位置找到 Linux IP 伪装资源:


8.3. 感谢以下支持者..

按字母顺序排列

  • Gabriel Beitler, gabrielb@voicenet.com,感谢他提供第 3.3.8 节(设置 Novell)

  • Juan Jose Ciarlante,irriga@impsat1.com.ar,感谢他对 IPMASQADM 端口转发工具、2.1.x 和 2.2.x 内核代码以及原始 LooseUDP 补丁等工作的贡献。

  • Steven Clarke,steven@monmouth.demon.co.uk,感谢他对 IPPORTFW IP 端口转发器工具的贡献

  • Andrew Deryabin,djsf@usa.net,感谢他对 ICQ MASQ 模块的贡献

  • Ed Doolittle,dolittle@math.toronto.edu,感谢他对以下内容的建议:-V选项,在ipfwadm命令中,以提高安全性

  • Matthew Driver,mdriver@cfmeu.asn.au,感谢他对本 HOWTO 的广泛帮助,并提供了第 3.3.1 节(设置 Windows 95)

  • Ken Eves,ken@eves.com,感谢他提供的 FAQ,为本 HOWTO 提供了宝贵的信息

  • John Hardin,jhardin@impsec.org,感谢他提供的 PPTP 和 IPSEC 转发工具

  • Glenn Lamb,mumford@netcom.com,感谢他提供的 LooseUDP 补丁

  • Ed. Lott,edlott@neosoft.com,感谢他提供的经过测试的系统和软件的长列表

  • Nigel Metheringham,Nigel.Metheringham@theplanet.net,感谢他贡献的 IP 数据包过滤和 IP Masquerading HOWTO 版本,这使本 HOWTO 成为更好的、更深入的技术文档,特别是第 4.1、4.2 节以及其他章节

  • Keith Owens,kaos@ocs.com.au,感谢他提供的关于 ipfwadm 的优秀指南,特别是第 4.2 节中关于更正ipfwadm -deny选项的更正,该选项避免了一个安全漏洞,并澄清了ping在 IP Masquerade 上的状态

  • Michael Owings,mikey@swampgas.com,感谢他提供的关于 CU-SeeMe 和 Linux IP-Masquerade Teeny How-To 的章节

  • Rob Pelkey,rpelkey@abacus.bates.edu,感谢他提供的第 3.3.6 和 3.3.7 节(设置 MacTCP 和 Open Transport)

  • Harish Pillay,h.pillay@ieee.org,感谢他提供的第 4.5 节(使用 Diald 的按需拨号)

  • Mark Purcell,purcell@rmcs.cranfield.ac.uk,感谢他提供的第 4.6 节(IPautofw)

  • David Ranch,dranch@trinnet.net,感谢他维护 HOWTO,协助 Linux IP Masquerade 资源页面、TrinityOS 文档,...,此处无法一一列举 :-)

  • Paul Russell,rusty@linuxcare.com.au,感谢他在 IPTABLES、IPCHAINS、IP Masquerade 内核补丁等方面的所有工作。他简直是 IP NAT 狂人!

  • Ueli Rutishauser,rutish@ibm.net,感谢他提供的第 3.3.9 节(设置 OS/2 Warp)

  • Steve Grevemeyer,grevemes@tsmservices.com,感谢他从 Lee Nevo 手中接管 IP Masq Applications 页面,并将其更新为完整的 DB 后端。

  • Fred Viles,fv@episupport.com,感谢他对 FTP 正确端口转发的补丁。

  • John B. (Brent) Williams,forerunner@mercury.net,感谢他提供的第 3.3.7 节(设置 Open Transport)

  • Enrique Pessoa Xavier,enrique@labma.ufrj.br,感谢他提供的 BOOTp 设置建议

  • 感谢 IP-MASQ 邮件列表 masq@indyramp.com 上的所有用户,感谢他们对所有新的 Linux MASQ 用户的帮助和支持。

  • 感谢 IP Masquerade 的其他代码和文档开发者,感谢他们提供了这项出色的功能

  • Delian Delchev,delian@wfpa.acad.bg

  • David DeSimone (FuzzyFox),fox@dallas.net

  • Jeanette Pauline Middelink,middelin@polyware.iaf.nl

  • Miquel van Smoorenburg,miquels@q.cistron.nl

  • Jos Vos,jos@xos.nl

  • 以及其他我可能在此处未能提及的人(请告知我)

  • 感谢所有向邮件列表发送反馈和建议的用户,特别是那些报告文档错误以及支持和不支持的客户端的用户

  • 对于遗漏任何重要姓名、未包含一些用户发送给我们的信息等,我们深感抱歉。我们收到了许多建议和想法,但没有足够的时间来验证和整合这些更改。David Ranch 正在尽最大努力将所有发送给我的信息整合到 HOWTO 中。感谢您的努力,希望您能理解我们的情况。


8.4. 参考

  • Ken Eves 的原始 IP masquerade FAQ

  • Indyramp Consulting 的 IP masquerade 邮件列表存档

  • Ambrose Au 的 IP Masquerade WWW 站点

  • X/OS 的 Ipfwadm 页面

  • 各种与网络相关的 Linux HOWTO

  • David Ranch 的 TrinityOS 中涵盖的一些主题


8.5. 更改日志

待办事项 - HOWTO

  • 将脚本化的 IPMASQADM 示例添加到转发器部分。并确认语法。

  • 添加一个小节,介绍在 MASQ 服务器后设置多个子网

  • 确认 IPCHAINS 规则集,并确保其与 IPFWADM 规则集一致

待办事项 - WWW 页面

  • 更新 masq 站点上的 PPTP 补丁

  • 更新 portfw FTP 补丁

2005 年 5 月 22 日至 2005 年 11 月 13 日的更改

  • 11/13/05 - 修复了第 6.7 节中 PORTFW 示例规则不正确的错误。更新了 IPTABLES PORTFW 部分,以包含预路由规则的状态跟踪,添加了对 PORTFW FAQ 条目的交叉引用,并减少了 HOWTO 不同章节中重复的 PORTFW 示例。感谢 Thomas Zajic 提请我注意这一点。

  • 10/23/05 - 更新了动态 IP FAQ 部分,提供了关于如何为各种不同的 DHCP 客户端重新运行 rc.firewall-* 脚本的完整示例

  • 10/19/05 - 更新了 HOWTO,明确说明了加载各种 rc.firewall-* 规则集(本 HOWTO 中共有 6 个,分别是 IPTABLES、IPCHAINS 和 IPFWADM 的简单版和更强版)文件与加载通用 rc.firewall 文件之间的区别。我还更新了故障排除部分,以反映这个可能令人困惑的点。

  • 05/27/05 - 更新了多 NAT 情况,以包含 ProxyARP 解决方案

  • 05/26/05 - 澄清了关于 IPMASQ 在多个内部 LAN 网段上的章节

2005 年 5 月 3 日至 2005 年 5 月 22 日的更改

  • 05/22/05 - 将 rc.firewall-iptables-stronger 规则集更新到 0.87s。删除了未使用的 drop-and-logit 链,因为它稍后会被删除。感谢 Matthew Concannon 提供的这个更新。

  • 05/21/05 - 稍微更新了 Multiple-IPs FAQ 条目

2005 年 4 月 17 日至 2005 年 5 月 3 日的更改

  • 05/03/05 - 更新了 rc.firewall-iptables-stronger 规则集,以修复一个拼写错误

2004 年 3 月 19 日至 2005 年 4 月 17 日的更改

  • 04/30/05 - 更新了 unc.metalab.org 的 IP 地址,并将 HOWTO 发布到网络上。

  • 12/18/04 - 在 IPTABLES、IPCHAINS 和 IPFWADM 规则集中添加了一些注释,说明为什么默认策略是 ACCEPT 而不是 DROP 之类的策略。

  • 07/24/04:将 rc.firewall-2.4/2.2/2.0-* 规则集重命名为 rc.firewall-iptables/ipchains/ipfwadm-*。此更改更好地反映了这些规则集可以在不同的内核版本(例如 2.6.x)上运行。将 rc.firewall-iptables-stronger 规则集更新到 0.85s,以修复 INTIP 变量的不正确的 /24 子网掩码。

  • 04/10/04:更新了 rc.firewall-2.4-stronger 规则集,以使用 192.16.0.x 网络而不是 192.168.1.x 网络,以便更好地与 HOWTO 的其余部分对齐

  • 04/04/04:添加了 Redhat9 支持 IPMASQ 的信息

2003 年 11 月 10 日至 2004 年 3 月 18 日的更改

  • 03/18/04:为 IPTABLES 添加了一个支持多个内部网络的子章节

  • 02/02/04:更新了一些旧的 jhardin rubyriver URL 为 impsec.org URL

  • 01/10/04:更新了 rc.firewall-2.4-stronger 和 2.2 规则集,使 PORTFW 配置的位置更加明显

  • 01/01/04:某些系统要求 /etc/rc.d/init.d/firewall-2.* 文件是可执行的。已修复。感谢 Chris Carter 和其他人的提醒。

  • 01/01/04:某些系统要求 /etc/rc.d/init.d/firewall-2.* 文件是可执行的。已修复。感谢 Chris Carter 和其他人的提醒。

  • 01/01/04:在 Redhat 系统上添加了额外的 chkconfig 检查,以确保防火墙在 init 级别更改时加载。感谢 Chris Carter 的建议。

  • 12/19/03:将 rc.firewall-2.4-stronger 规则集更新到 0.82。这个新的规则集有一个特殊的 ICMP 过滤器,用于解决 Netfilter 的一个 bug。此外,drop-and-log-it 链已重命名为 reject-and-log-it,因为这实际上是它正在做的事情。感谢 Bart Martens 的建议。

  • 12/13/03:修复了一些小的语法问题。感谢 Lawrence Berlinsk 指出这些问题。

  • 11/30/03:将 rc.firewall-2.4-stronger 规则集更新到 0.81s,rc-firewall-2.2-stronger 规则集更新到 0.72s,并将 rc.firewall-2.0-stronger 规则集更新到 0.72s(以前没有版本号)。这些更改反映了规则集没有足够强的注释,或者允许所有目标是 MASQ 服务器本身的网络流量受到保护。建议如果您想启用对 MASQ 服务器本身上运行的服务器(http、ssh 等)的访问,请在 OPTIONAL INPUT 部分下有选择地启用它们。

  • 11/03/03:更新了 rc.firewall-2.2-stronger 规则集,其中一个 INTLAN 规则允许来自 ANY IP 地址的流量,而不是正确的 INTIP IP 地址。这使 IPCHAINS 规则集与 IPTABLES 和 IPFWADM 规则集示例对齐

  • 11/10/03:删除了所有 kernelnotes.org URLS (juanjox URLs)

2003 年 6 月 22 日至 2003 年 11 月 9 日的更改

  • 10/25/03:修复了第 3.3 节中一个失效的 RFC1918 URL。感谢 Mark Sobell 的报告。

  • 07/07/03:添加了“reducing-masq-log”FAQ 条目,以帮助人们减少防火墙日志的大小。

  • 06/27/03:将 rc.firewall-2.4-stronger 规则集更新到 0.80s。添加了 DISABLED ip_nat_irc 内核模块部分,将 ip_conntrack_irc 的默认值更改为默认不加载,并添加了额外的内核模块注释。

  • 06/27/03:将 rc.firewall-2.4 规则集更新到 0.75。添加了额外的 iptables 内核模块注释。

  • 06/24/03:将 Debian 3.0 添加到受支持的发行版列表中

  • 06/23/03:更改 PMTU URL,指向 Phil 的主要 www 站点

2003 年 5 月 26 日至 2003 年 6 月 22 日的更改

  • 06/22/03:再次更新了各种 Indyramp MASQ 电子邮件 URL,因为情况似乎又发生了变化。

  • 06/21/03:重写了 MTU FAQ 部分,使其更清晰,包括问题的具体信息,并修复了一个 PPPoE 用户的错误拼写,他们试图配置“--clamp-mss-to-mtu”,但应该是“--clamp-mss-to-pmtu”(pmtu 中缺少 p)。

  • 06/13/03:为 Mandrake 8.1 添加了内核信息

  • 06/02/03:修复了一个拼写错误,其中用于检查 IPMASQ 功能的扩展 2.2.x 内核检查使用了“cat”而不是“ls”

2003 年 4 月 8 日至 2003 年 5 月 26 日的更改

  • 05/26/03:更新了防火墙规则集:rc.firewall-2.4(到 0.74)、rc.firewall-2.2(到 1.22)、rc.firewall-2.4-stronger(到 0.79s)和 rc.firewall-2.2-strongerw(到 0.71s),以使用 modprobe 而不是 insmod。

  • 05/26/03:添加了如何在 Accounting FAQ 部分中转储 IPTABLES MASQ 条目的方法

  • 05/26/03:向 MTU faq 部分添加了 Clamp-MSS 建议

  • 05/26/03:当 MASQ 客户端无法 ping 通 MASQ 服务器时,在第 5 节中添加了额外的故障排除步骤。

  • 05/26/03:向 SHAPING FAQ 条目添加了额外的流量整形/流量限制器 URL

  • 05/26/03:将“IPROUTE2”FAQ 条目重命名为“Souce Routing”;向该部分添加了 IPTABLES 示例;修复了一个不正确的 IP 地址 62123.123.123.123

  • 05/25/03:修复了一个 SGML 脚本,该脚本不正确地转换了可下载的 firewall-* 和 rc.firewall-* 脚本的与号。还在 rc.firewall-2.0 文件的注释部分发现了一个 SGML 与号错误

  • 05/25/03:删除了几个失效的链接:ftp.gts.cz、novell.com LWP5、Old Juanjox mirror (geocities)、old ipmasq2.webhop.net URL、old zzdmacka NAT information URL、old linux.org/uk/VERSION url、old netfilter.samba.org URLs (不再是 netfilter 镜像 - 重定向)、old Activision BattleZone DLL url、old iproute2 (rpms, ras.ru, donlug, dontsk, tusur, waaug, etc.) urls、old rlynch ipautofw mirror

  • 05/25/03:更新了几个 URL:suse/proxy_suite/、www.indyramp.net URLs、几个 URL 中的“~”由于某种原因变成了 ~732、将所有 jhardin URl 从 wolfnet.com 更新为 impsec.org、更新了所有 LDP url (linuxdoc.org to tldp.org)、IPCHAINS patches for 2.0.x kernels、metalab to tldp.org、winfiles.com to download.com、Microsoft technet article 172227、Oidentd、mumford LooseUDP URL、2.2.x PORT-FTP URL、IRQTUNE url、midentd URL

  • 05/25/03:来自远程网站管理员的待处理更新:Indyramp EQL URL、insecurity.net sidentd

  • 05/25/03:许多小更新,例如:稍微更新了 Intro 部分的措辞,以反映 BETA 内核而不是 OLD 内核;更新了 Forward 部分(非 PORTFW),使其更通用一些;在 Forward 部分中添加了指向 IPMASQ 邮件列表的链接;更新了版权声明中的日期;

  • 05/24/03:更新了“Current Status”,添加了备注,说明某些程序已更新为使用 NAT 友好的协议,因此不再需要特殊的 NAT 模块

  • 05/24/03:更新了 2.4 Requirements 部分:删除了重复行(true 1:1 NAT);清理了一些添加内容;将 CuSeeme 添加到 2.4 移植列表

  • 05/24/03:更新了 2.2 / 2.0 Requirements 部分:删除了对过时的 IPMASQ ICQ 模块的引用;更新了 LooseUDP URL 的链接;

  • 05/24/03:更新了 Compiling Linux 2.2.x / 2.0.x 部分:删除了通过 rc.local 加载 rc.firewall 规则集的建议。这应该在 HOWTO 的后面部分介绍,并为不同的 Linux 发行版提供其他方法

  • 05/24/03:更新了 ICQ Application 部分,说明现代 ICQ 客户端不需要这些步骤。我将本节保留在 HOWTO 中,以演示一个大型 PORTFW 示例

  • 05/24/03:使一些 FAQ 条目更通用于内核版本,并删除了 2.0.x “upgrades-cont.html”FAQ 条目,因为它基本上是重复的

  • 05/24/03:更新了 LooseUDP 游戏部分,解释了它的工作原理,解释了在有状态 IPTABLES 系统下正确解决了多少问题,并说明它不适用于 2.4.x 内核。如果 IPTABLES 的有状态 UDP 跟踪不起作用,您可能就无能为力了。

  • 05/24/03:在 FAQ 部分中提到,MASQ 定时器在 IPTABLES 下是不可调整的

  • 05/24/03:大大扩展了数据包防火墙日志 FAQ 条目,并最终添加了 IPTABLES 数据包日志描述部分。我还对齐了 IPCHAINS 示例以匹配 IPFWADM 条目

  • 04/11/03:修复了一个不正确的 echo 语句,该语句说 IPTABLES 策略被设置为 REJECT 而不是 DROP。

2003 年 1 月 31 日至 2003 年 4 月 8 日的更改

  • 04/08/03:在第 3.2 节中添加了额外的格式和“ip_masquerade”/proc 条目。这有助于用户确定他们的内核是否已准备好 MASQ。

  • 03/08/03:将 EXTIP 变量添加到 2.4.x PORTFW 示例中,因为有几个人试图将其与 BASIC 规则集一起使用,我假设他们使用的是 STRONGER 规则集。感谢 Greg Lukins 提请我注意这一点。

  • 03/08/03:将发行版添加到 MASQ 兼容性列表:Mandrake、Gentoo

  • 02/08/03:忘记更新 rc.firewall-2.4-stronger 规则集的 VERSION 号码。添加了一些额外的格式

  • 02/01/03:在内核编译部分添加了额外的检查,以了解您的内核是否通过模块或静态编译方式支持 IPMASQ。

2003 年 1 月 12 日至 2003 年 1 月 31 日的更改

  • 01/31/03:Doh。我应该阅读我自己的评论。我已经将 2.4.x. 策略设置从 REJECT 恢复为 DROP。由于某些蹩脚的原因,REJECT 不是合法的策略。建议的 REJECT 操作仍然通过“drop-and-log-it”用户链执行。

  • 01/30/03:更新了 Multiple-IPs FAQ 条目,以更好地描述希望将外部 IP 放在 Linux 路由器后面的用户。添加了额外的 URL 并清理了一些文本。

  • 01/30/03:更新了 2.4.x requirement 部分,以反映 IPTABLES 的更多优点,并更新了一些旧的遗留 2.2.x 模块的更新状态

  • 01/30/03:添加了一个额外的 FAQ 条目,清楚地解释了 ipchains.o 模块在 2.4.x. 内核上可以做什么和不能做什么

  • 01/28/03:广泛更新了 2.4.x 内核编译部分,以反映带有 IPTABLES 1.2.7a 的 2.4.20 内核。该部分还反映了编译 IPTABLES、应用 Patch-O-Matic 补丁的新方法,并包括了许多示例输出。

  • 01/28/03:更新了内核编译部分,使其更清楚地说明不同的 Linux 发行版可以有不同的内核(模块与单内核)

  • 01/17/03:修复了一个主要问题,其中 rc.firewall-2.2-stronger 规则集引用了丢失的可执行变量。这是从 2.4-stronger 规则集中提取的,但我想我忘记完成它了。已修复。感谢 Samuel Kim 发现了这个问题!

  • 01/17/03:修复了一个问题,其中 rc.firewall-2.2-stronger 的注释 HTTP 部分缺少“-p tcp”选项。感谢 Samuel Kim 发现了这个问题!

  • 01/16/03:更新了 DJSF 的 ICQ 模块的 URL

  • 01/16/03:在 IPTABLES 规则集和高级 IPFWADM 规则集上,将默认策略和 drop 链从 DENY 更改为 REJECT。感谢 Jonathan Hutchins 提请我注意这一点。

  • 01/16/03:修复了 rc.firewall-2.2-s 规则集的注释掉的 HTTPd OUTPUT 部分的拼写错误

  • 01/13/03:将 IPMASQ www 站点 URL 从 ipmasq.cjb.net 更新为 ipmasq.webhop.net。CJB 开始更改他们的策略,所以我们切换了。

  • 01/13/03:添加到 2.4.x Requirements 部分,IPTABLES v1.2.7a 已经发布并推荐使用。

  • 01/13/03:为过旧的 IPTABLES 版本在“Test Section - Section 5”中添加了一个额外的测试项。我还清理了这部分,使其更易于阅读。

  • 01/13/03:更新了 rc.firewall-2.4-stronger 规则集,以包含注释掉的规则,以允许 HTTP 流量进入本地 HTTP 服务器。还在 FORWARD 部分中添加了规则注释,以帮助用户了解 PORTFW 命令应放在哪里。

  • 01/13/03:更新了 rc.firewall-2.2-stronger 规则集,以包含注释掉的规则,以允许 HTTP 流量进入本地 HTTP 服务器。还在 FORWARD 部分中添加了规则注释,以帮助用户了解 PORTFW 命令应放在哪里。

  • 01/13/03:澄清了 PORTFW 部分,以帮助用户更好地理解 PORTFW 命令应放在 rc.firewall 规则集中的哪个位置。我还清理了这部分,使其更易于阅读。

2002 年 12 月 13 日至 2003 年 1 月 12 日的更改

  • 01/03/03:将 Redhat 7.3 和 8.0 添加到兼容性图表中。

  • 01/03/03:修复了各种拼写错误。感谢 Gabriel Withington 的敏锐眼光。

  • 12/22/02:更新了 2.2.x H.323 内核补丁 URL。感谢 Maxime Plante 指出这一点。

  • 12/22/02:更新了 2.4.x 内核编译部分,让用户知道大多数现代内核不需要应用 IPTABLES Patch-o-matic 补丁,除非是为了修复错误或添加额外功能。

2002 年 10 月 20 日至 2002 年 12 月 13 日的更改

  • 11/27/02:修复了 init.d 脚本,使其将标头指向正确的配置文件。这肯定是由于较新版本的“chkconfig”做得更好。请注意,对于 rc.firewall-2.?-stronger 规则集,这可能仍然是一个问题。感谢 Joris Van Puyenbroeck 的提醒。

  • 11/25/02:更新了所有防火墙注释,以反映 PPPoE 用户需要使用“ppp0”逻辑接口作为其外部接口,而不是物理接口,例如“eth0”。感谢 Meng Cheah 的推动。

  • 11/13/02:更新了基于 Donald Becker 的 NIC 驱动程序的 URL。感谢 Bruce Gorgon 的提醒。

  • 11/01/02:添加了一个新的 FAQ 部分,涵盖了将本地 INTERNAL 流量重定向到内部 PORTFWed 服务器

  • 11/01/02:更新了 PORTFW 部分,使其更清晰一些。

2002 年 4 月 19 日至 2002 年 10 月 20 日的更改

  • 09/29/02:修复了一个指向 metalab.unc.edu 的不正确的 IP 地址

  • 08/29/02:修复了 firewall-2.2 启动脚本中的一个拼写错误,该脚本启动的是 2.4 防火墙而不是 2.2 版本。感谢 Jean-Marc Vanel 发现了这个问题。

  • 08/25/02:更新了 rc.firewall-2.2-stronger 和 rc.firewall-2.2 脚本,以使用 shell 环境变量。

  • 07/09/02:更新了 FTP PORTFW 部分,使其更易于阅读

  • 07/06/02:将所有 filewatcher.org URL 替换为 netfilter.org URL

  • 06/12/02:更改了一些格式,以尝试帮助新手更好地理解“\”字符用作上一行的延续。

  • 06/12/02:更新了第 5 节中 metalab.unc.edu 的 IP 地址。感谢 Pete Trachy 提请我注意这一点,但请注意,即使像 Metalab 这样的大型站点也会不时更改其 IP、子网甚至 ISP。

  • 06/02/02:更新了 rc.firewall-2.4 规则集,以包含用于 NATing IRC DCC 的注释掉的选项,添加了更多环境变量的使用,并添加了额外的格式。

  • 05/18/02:在 rc.firewall-2.4-stronger 规则集的注释部分中添加了一些额外的 # 行,以更好地服务于剪切和粘贴用户。

  • 05/04/02:- 更新了各种 PPTP MASQ 链接,以指向有效的 URL。还更新了 HOWTO,以反映 2.4.x 内核现在支持 PPTP。

  • 05/03/02:- 更新了 2.4.x 内核要求部分,以指出 2.4.x 内核下的 IPCHAINS 兼容性不是很好。如果您想在 2.4.x 内核下使用 IPMASQ,则应仅使用 IPTABLES 规则。

2002 年 1 月 5 日至 2002 年 4 月 19 日的更改 - v2.00.041902 发布到 LDP

  • 04/01/02:- 更新了 rc.firewall-2.4-stronger 规则集,以表示并禁用 OUTPUT 规则上的内部 DHCP 服务器支持

  • 02/09/02:- 添加了 Redhat 风格的 init.d 脚本来启动 rc.firewall 文件

  • 02/09/02:- 更新了所有各个章节,以使用人类可读的文件名,而不是像 x2623.html 这样的文件名。

  • 02/09/02:- 扩展了 IPMASQ 记帐部分

  • 02/04/02:- 从第 6.7.1 节的 PORTFW 变量中删除了一个额外的“$”

  • 01/31/02:- 更新了 PPPd 和 Diald 主页的 URL

  • 01/26/02:- 修复了一些拼写错误,并添加了 LooseUDP 说明,以告诉用户阅读示例 rc.firewall-2.2 规则集注释,了解如何启用 LooseUDP。

  • 01/08/02:- 对 IP 别名支持进行了一些细微的澄清

2001 年 11 月 19 日至 2002 年 1 月 5 日的更改 - 010502 发布到 LDP

  • 01/05/02:- 在 rc.firewall-2.4-stronger 规则集中添加了禁用的规则,以支持 INTERNAL DHCP 服务器和对 MASQ 计算机上运行的 WWW 服务器的 EXTERNAL 访问。

  • 01/05/02:- 如果人们 PORTFW 到非标准 FTP 端口,则添加了加载 ip_conntrack_ftp 模块所需的更改。

  • 01/05/02:- 在 2.4.x PORTFW 部分中添加了一个示例,说明如何在 2.4.x PORTFW 部分中将内部流量 REDIRECT 返回到 INTERNAL 服务器。这与在 2.2.x 和 2.0.x 内核下运行 REDIR 相同。

  • 01/05/02:- 将 Juanjox 镜像 URL 添加到 HOWTO。

  • 01/04/02:- 澄清并清理了 ICQ PORTFW 部分;添加了关于 ip_masq_icq、PORTFW 和 SOCKS 解决方案的想法

  • 01/05/02:- 将 Slackware 8.0 添加到受支持的列表中。

  • 01/04/02:- 修复了 2.4 和 2.2 规则集中的一些拼写错误。感谢 Michael Ott 的敏锐眼光。

  • 12/19/01:- 修复了 rc.firewall-2.4 文件中的一个小的注释拼写错误。感谢 Bruno Negrao 提供的这个错误。

  • 12/02/01:- 修复了 2.4.x rc.firewall 规则集中的一些小的版本拼写错误;为 2.4.x PORTFW 示例添加了缺失的 $PORTFWIF 变量。感谢 Neil Bunn 提供的勘误。

  • 11/25/01:- 扩展了第 5 节中关于 ipchains 模块冲突错误消息的内容

  • 11/23/01:- 更新了 HOWTO,以反映 2.4.x 内核的新 PPTP 内核模块

  • 11/19/01:- 澄清了对 2.4.x 内核的 PPTP 支持

2001 年 8 月 26 日至 2001 年 11 月 18 日的更改 - 111801 发布到 LDP

  • 11/12/01:- 更新了各种注释,以反映新版本:linux 2.4.14、iptables 1.2.4 和 linux 2.2.20。

  • 11/12/01:- 将 rc.firewall-2.4-stronger 规则集添加到 HOWTO,更新了 2.4.x 内核和 IPTABLES 编译步骤,以反映 2.4.14 和 1.2.4。

  • 11/10/01:- 将直接可下载版本的 2.4、2.4-stronger、2.2、2.2-stronger、2.0 和 and 2.0.x-stronger 规则集添加到 WWW。

  • 11/10/01:- 更新了 2.4.x PORTW 示例,以添加缺失的 FORWARD 选项。

  • 11/10/01:- 更新了 HOWTO 中的 DSL-HOWTO 链接

  • 10/27/01:- 更新了第 2.5 节中的网络图,使其更详细一些。

  • 09/18/01:- 修复了一些指向各自 2.4.x、2.2.x 和 2.0.x 内核编译建议的损坏的参考链接。

  • 09/16/01:- 清理并更新了 PORTFW 部分,还包括了 2.4.x 内核的 PREROUTING 示例。

  • 09/13/01:- 将 IPTABLES 简单 rc.firewall 规则集更新到 0.62。这修复了 MASQ 启用行上使用 eth0 而不是 $EXTIF 的拼写错误。感谢 Hafi 报告了这一点。

  • 09/07/01:- 似乎大多数遇到 IPCHAINS 和 IPTABLES 冲突的人都在运行 Redhat 7.1。我已经更新了第 5 节,说明如何解决这个问题。感谢 Jason Wenzel 帮助我解决了这个问题。

  • 09/07/01:- 指出 IPTABLES v1.2.3 是当前版本。所有版本低于 v1.2.3 的版本都有一个 FTP 模块 bug,可能会绕过强大的防火墙规则集。请立即升级您的 IPTABLES 副本。

  • 09/07/01:- 为简单 rc.firewall 规则集创建了版本号(IPTABLES - v0.61)(IPCHAINS - v1.01)(IPFWADM - v2.01)。并清理了每个部分中的一些注释。

  • 09/07/01:- 在简单 rc.firewall 规则集中添加了刷新各种表的规则。除此之外,我还添加了环境变量的使用和更多 echo 语句,以使规则集更易于编辑和监控。感谢 Ian Bishop 的好主意。

  • 09/07/01:- 在每个 rc.firewall 和部分防火墙规则集中添加了 EXTIF 和 INTIF 接口变量的使用,以提高清晰度(类似于 TrinityOS 一段时间以来的做法)。感谢 Sean McKeon 的推动。

  • 09/07/01:- 修复了 UNIX 客户端配置部分中的一个拼写错误,其中网络广播是 192.168.0.25 而不是 .255。

2001 年 2.01 至 2.05 的更改 - 08/26/01

  • 08/19/01:- 在 Section5 中添加了一个额外的测试步骤,以确保 rc.firewall 文件加载正常。感谢 Steven Levis 的好主意。

  • 08/15/01:- 将 /etc/hosts 文件的参考从 RFC952 更改为 RFC1035。感谢 Michael F. Maggard 的更正。

2001 年 1.96 至 2.01 的更改 - 08/12/01

  • 08/12/01:- 将基本 IPTABLES 规则集更新到 0.60,这修复了一个主要问题,即所有 MASQed 数据包都被丢弃。最终,我忘记添加一个规则来 ACCEPT 通过转发链的正确数据包。

  • - 添加了一个额外的规则来记录所有伪造的 FORWARD 数据包

  • - 默认情况下现在加载 FTP nat 模块

  • - 更改了一些内核模块的加载顺序,以避免创建伪造的错误消息

  • - 添加了一个关于如何在 IPTABLES 部分中 MASQ 特定主机而不是整个子网的部分

  • - 添加了更多 MASQ 客户端兼容的操作系统

  • 07/19/01:- 用于在多个接口之间转发的高级 IPCHAINS 示例缺少关键的“-j ACCEPT”,实际上无法让数据包流动。感谢 Shingo Yamaguchi 发现了这个问题。

2001 年 1.96 至 2.00 的更改 - 06/10/01

  • 06/21/01:更新了第 5 节(测试部分),添加了一个额外的测试,以帮助用户排除他们的 MASQ 设置故障。现在总共有 -11- 个测试。 06/16/01:更新了 HOWTO 开头的介绍历史部分。 06/14/01:添加了镜像 Netfilter 和 IPCHAINs 镜像 URL 06/13/01:更新了 H.323 URL

  • 06/10/01:Double DOH!用于 2.4 内核的简单 rc.firewall 脚本有两个主要错误。新版本信息量更大,甚至可以工作!我正在继续浏览 HOWTO 并清理内容,但我还没有完全完成。

  • 06/02/01:更新了已知的兼容 MASQ'ed 操作系统列表(Windows M3、Linux 2.3、2.4 等)在各种不同的 MASQ 客户端配置指南中更多地引用了 DHCP 和 DNS。

  • 04/12/01:感谢 Joshua X 和 Command Prompt, Inc. 的其他人员将 HOWTO 从 LinuxDoc 移植到 DocBook。在第 126 行添加电子邮件列表 URL

2000 年 1.90 至 1.95 的更改 - 11/11/00

  • 非常感谢 Joshua X 和 Command Prompt, Inc. 的其他人员将 HOWTO 从 LinuxDoc 移植到 DocBook。

  • 在介绍中添加了一个快速的前期通知,说明不建议在 MASQ 多个以太网段中运行 SINGLE NIC,并链接到相关的 FAQ 条目。感谢 Daniel Chudnov 帮助 HOWTO 更加清晰。

  • 在 Intro 部分中为正在查找 MASQ 与 NAT 和 Proxy 服务有何不同的用户添加了指向 FAQ 部分的指针。

  • 重新排序了内核要求部分,顺序为 2.2.x、2.4.x、2.0.x

  • 扩展了第 3 节中的内核测试,以查看给定的内核是否已支持 MASQ。

  • 颠倒了显示的简单 MASQ 规则集示例(2.2.x 和 2.0.x)的顺序

  • 清理了 2.0.x 和 2.2.x rc.firewall 文件中的一些格式问题

  • 在 2.2.x rc.firewall 中指出,defrag 选项在某些发行版的 proc 中已消失(Debian、TurboLinux 等)

  • 在 rc.firewall 脚本中添加了 NOTE #3,以包含 Pump 的说明。感谢 Ross Johnson 提供的这个说明。

  • 清理了 2.2.x 和 2.2.x 内核的简单 MASQ 规则集示例

  • 更新了简单和更强的 IPCHAINS 和 IPFWADM 规则集,以包含外部接口名称(IPCHAINS 是 -i;IPFWADM 是 -W),以避免一些内部流量 MASQing 问题。

  • 大大扩展了第 5 节(测试),增加了更多测试步骤,并添加了测试命令的输出结果示例。

  • 将 H.323 应用程序文档从 NOT supported 移动到 Supported。 :-)

  • 重新排序了 Multiple LAN 部分示例(2.2.x 然后 2.0.x)

  • 对 Multiple LAN 示例进行了一些额外的澄清

  • 修复了多个 NIC MASQing 的一个关键拼写错误,其中网络示例的网络规范颠倒了。感谢 Matt Goheen 发现了这个问题。

  • 在 PORTFW 部分中为 MFW 添加了一个小介绍。

  • 颠倒了 PORTFW 的 2.0.x 和 2.2.x 部分

  • 更新了关于 2.2.x 内核的 PORTFWing FTP 流量的新闻

      NOTE:  At this time, there *IS* a BETA level IP_MASQ_FTP module 
             for PORT Forwarding FTP connections 2.2.x kernels which also supports 
             adding additional PORTFW FTP ports on the fly without the requirement 
             of unloading and reloading the IP_MASQ_FTP module and thus breaking 
             any existing FTP transfers.
      

  • 添加了关于 PORTFWed FTP 支持的顶级注释

  • 在 2.0.x PORTFW'ed FTP 示例中添加了一个注释,说明用户为什么不需要 PORTFW 端口 20。

  • 更新了如何启用 PORTFWed FTP 的示例,还提到了用户可以使用 SuSe 的 FTP 代理应用程序来支持 PORTFWed FTP 类似的功能。感谢 Stephen Graham 提供的这个信息。

  • 更新了如何启用 PORTFWed FTP 的示例,还包括了对于使用多个 PORT 联系多个内部 FTP 服务器的用户,如何加载 ip_masq_ftp 模块的所需配置。感谢 Bob Britton 提醒我注意这一点。

  • 为 rc.firewall 文件中嵌入了 ^Ms 的用户添加了 FAQ 条目

  • 扩展了 FAQ 条目,讨论了 MASQ 与 NAT 和 Proxy 的不同之处,以包含一些信息丰富的 URL。

  • 更新了 MASQ MTU 问题的解释,并描述了该问题的两个主要解释。

  • 澄清了 RFC、PPPoE 应该只需要 1492 的 MTU,尽管某些 ISP 需要 1460 的设置。因此,我已更新示例以显示 1492 的 MTU。

  • 将 Windows 9x 部分分解为 Win95 和 Win98,因为它们使用不同的设置(DWORD 与 STRING)。我还更新了这些部分,使其更清晰,并且更新了注册表备份方法。

  • 修复了一个拼写错误,其中 NT 4.0 注册表条目是向后的 (Tcpip/Parameters 与 Parameters/Tcpip)。

  • 修复了一个问题,其中 WinNT 条目应该是 DWORD 而不是 STRING。

  • 非常感谢 Geoff Mottram 提供的各种 PPPoE 和各种 Windows 注册表条目修复。

  • 在 IRC FAQ 条目中为 Oident 添加了一个显式 URL

  • 更新了关于某些损坏的“netstat”版本的 FAQ 部分

  • 为 MASQ 记帐想法和流量整形添加了新的 FAQ 部分

  • 扩展了 IPROUTE2 FAQ 条目,介绍了什么是策略路由。

  • 将 IPROUTE2 URL 移动到 2.2.x Kernel requirements 部分,并添加了一些更多 URL。

  • 更正了更强的 IPCHAINS 规则集中的“intnet”变量,以反映 192.168.0.0 网络,使其与示例的其余部分一致。感谢 Ross Johnson 提供的这个错误。

  • 为询问多个内部 MASQed LAN 之间转发问题的用户添加了一个新的 FAQ 部分。

  • 为想要将来自多个外部 IP 地址的所有端口 PORTFW 到内部 IP 地址的用户添加了一个新的 FAQ 部分。我还介绍了尝试 PORTFW 多个 IP ALIASed 接口上的所有端口的用户,并为 DSL 和 Cablemodem 用户在非路由环境中拥有多个 IP 的用户注释了 Bridge+Firewall HOWTO。

  • 将 Mandrake 7.1、Mandrake 7.2 和 Slackware 7.1 添加到受支持的列表中

  • 将 Redhat 7.0 添加到 MASQ 支持的发行版中。感谢 Eugene Goldstein 提供的这个信息。

  • 修复了 FAQ 部分中“Maximum Throughput”计算中的数学错误。感谢 Joe White @ ip255@msn.com 提供的这个错误。

  • 修复了 Windows9x MTU 更改,使其成为 STRING 更改而不是注册表的 DWORD 更改。感谢 jmoore@sober.com 提供的这个错误。

  • 更新了 2.0.x rc.firewall 脚本中的注释,以指出 ip_defrag 选项适用于 2.0 和 2.2 内核。感谢 pumilia@est.it 提供的这个澄清。

2000 年 1.85 至 1.90 的更改 - 07/03/00

  • 更新了 TrinityOS 的 URL,以反映其最新布局

  • 在 IPCHAINS 规则集中发现一个错别字,我当时设置的是 "ip_ip_always_defrag" 而不是 "ip_always_defrag"

  • 指向 Taro Fukunaga 的 URL 无效,因为它使用的是 "mail:" 而不是 "mailto:"

  • 为 “伪装多个内部接口” 增加了一些说明,一些用户不明白为什么 eth0 被多次引用。

  • 修复了更强大的 IPCHAINS 部分中另一个 “EXTIP 变量后的空格” 错误。我猜我漏掉了一个。

  • 在第 5 节的测试 #7 中,我引导用户回到步骤 #4。那应该是步骤 #6。

  • 更新了 SuSe 5.2 和 6.0 附带的内核版本

  • 修复了第 7.2 节中的一个错别字(or 与 of)。

  • 在 MASQ 测试部分添加了第 9 项,以引导仍然遇到 MASQ 问题的用户阅读 FAQ 中的 MTU 条目

  • 改进了第 5 节中的条目编号

  • 更新了 IPCHAINS 语法以显示 MASQ/FORWARD 表。以前,运行 "ipchains -F -L" 是有效的,但现在只有 "ipchains -M -L" 有效。

  • 更新了 LooseUDP 文档,以反映 2.2.16+ 内核中的新 LooseUDP 行为。以前,它始终启用,现在,由于可能存在 MASQed UDP 端口扫描漏洞,默认设置为 OFF。我更新了 BASIC 和 SEMI-STRONG IPCHAINS 规则集以反映此选项。

  • 更新了推荐的 2.2.x 内核为 2.2.16+,因为所有较低版本都存在 TCP root 漏洞。

  • 将 Redhat 6.2 添加到 MASQ 支持列表

  • 更新了 Sonny Parlin 的 FWCONFIG 链接,使其指向 fBuilder。

  • 将 IP 地址的各种示例从 111.222.333.444 更新为 111.222.121.212,并在有效的 IP 地址范围内

  • 更新了 BETA H.323 MASQ 模块的 URL

  • 最终更新了 MTU FAQ 部分,以帮助 PPPoE DSL 和 Cablemodem 用户。基本上,第 7.15 节 现在反映了用户还可以更改其所有内部机器的 MTU 设置以解决可怕的 MASQ MTU 问题。

  • 为 PORTFW 部分添加了说明,PORTFW 连接对于外部客户端有效,但对于内部客户端无效。如果您还需要内部端口转发,您还需要实施 REDIR 工具。我还注意到,此问题已在带有 Netfilter 的 2.4.x 内核中得到修复。

  • 我还从 Juanjo 那里添加了一个技术解释到 PORTFW 部分的末尾,以说明为什么这种情况无法正常工作。

  • 更新了所有 IPCHAINS URL,使其指向 Paul Rusty 在 http://www.netfilter.org/ipchains/ 的新站点

  • 更新了 Paul Rusty 的电子邮件地址

  • 为连接长时间保持空闲状态且 PORTFW 连接不再工作的用户添加了新的 FAQ 部分。

  • 更新了所有指向 metalab.unc.edu 的 LDP URL,使其指向 linuxdoc.org 的新站点

  • 更新了 Netfilter URL,使其指向重命名的 HOWTO 等。

  • 我还更新了 2.4.x 支持的状态,以注明我 *将* 为此 HOWTO 添加完整的 Netfilter 支持,如果时机成熟,则将该支持拆分到另一个 HOWTO 中。

  • 更新了 2.4.x 要求部分,以反映 NetFilter 与 IPFWADM 和 IPCHAINS 相比的变化,并给出了新功能和旧行为更改的优缺点列表。

  • 在 “我的 MASQ 连接速度慢” FAQ 条目中添加了一个 TCP/IP 数学示例,以更好地解释用户应该期望的性能。

  • 更新了 HOWTO,以反映较新版本的 “pump” DHCP 客户端现在可以在启动、租约续订等时运行脚本。

  • 更新了 FTP 的端口转发,以反映多位用户表示他们可以成功地将 FTP 流量转发到内部机器,而无需特殊的 ip_masq_ftp 模块。我已经让 HOWTO 反映用户应该首先尝试不使用修改后的模块,然后在需要时再转向补丁。

从 1.82 到 1.85 的更改 - 00 年 5 月 29 日

  • Ambrose Au 的名字已从标题页中删除,因为 David Ranch 一年多来一直是 HOWTO 的主要维护者。不过,Ambrose 仍将参与 WWW 站点的工作。

  • 删除了第 6.4 节中的一个多余空格

  • 重新排序了兼容的 MASQ 系统部分,并添加了有关在 OS/400 上运行的 AS/400 系统设置说明。感谢 jaco@libero.it 提供的说明。

  • 为 FTP 访问添加了额外的 PORFW-FTP 补丁 URL,以防 HTTP 访问失败。

  • 更新了 FAQ 中 Redhat 5.1 和 6.1 的内核版本

  • 将 FloppyFW 添加到启用 MASQ 的 Linux 发行版列表

  • 修复了更强大的 IPFWADM 规则集中的一个问题,其中 “ppp_ip” 和 “=” 之间存在空格。

  • 在 2.2.x 内核的内核编译部分中,我删除了启用 “CONFIG_IP_ALWAYS_DEFRAG” 的引用。此选项已从编译部分中删除,并在 2.2.12 中启用 MASQ 后默认启用。

  • 由于内核行为的上述更改,我将启用 ip_always_defrag 添加到所有 rc.firewall 示例中。

  • 更新了对 H.323 支持的状态。现在有 ALPHA 版本的模块支持 2.0.x 和 2.2.x 内核上的 H.323。

  • 将 Debian v2.2 添加到受支持的 MASQ 发行版列表

  • 修复了一个长期存在的问题,其中涵盖 IPCHAINS 的 IP 地址显式过滤的部分具有旧的 IPFWADM 语法。我还稍微清理了这一部分,使其更易于理解。

  • 哎呀!将 Juan Ciarlante 的 URL 添加到重要的 MASQ 资源部分。伙计们.. 你们需要让我更诚实!

  • 更新了 HOWTO 以反映内核 2.0.38 和 2.2.15

  • 颠倒了显示的内核编译顺序,首先显示 2.2.x 内核,因为 2.0.x 已经很旧了。

  • 更新了 2.2.x 内核编译部分,以反映较新的 2.2.x 内核的更改选项。

  • 为未能通过 MASQ 测试 #5 的用户添加了一个可能的解决方案。

从 1.81 到 1.82 的更改 - 00 年 1 月 22 日

  • 在更强大的 IPCHAINS 规则集中添加了 /proc/sys/net/ipv4/ip_dynaddr 的缺失子节。第 6.5 节

  • 将 Debian 2.1 的 IP Masq 支持更改为 YES

  • 重新组织并更新了 “Masq 速度慢” FAQ 部分,以包括修复以太网速度和双工问题。

  • 添加了 Donald Becker 的 MII 实用程序链接,用于以太网 NIC 卡

  • 为 2.2.x 部分添加了缺失的 “)”(之前仅为 2.0.x 版本修复),添加到 ICQ 端口转发脚本,并将评估从 -lt 更改为 -le

  • 将 Caldera eServer v2.3 添加到 MASQ 支持列表

  • 将 Mandrake 6.0、6.1、7.0 添加到 MASQ 支持列表

  • 将 Slackware v7.0 添加到 MASQ 支持列表

  • 将 Redhat 6.1 添加到 MASQ 支持列表

  • 将 TurboLinux 4.0 Lite 添加到 MASQ 支持列表

  • 将 SuSe 6.3 添加到 MASQ 支持列表

  • 更新了推荐的稳定 2.2.x 内核为任何比 2.2.11 更新的版本

  • 在第 3.3 节中,HOWTO 忘记了如何告诉用户在每次重启时加载 /etc/rc.d/rc.firewall。现在已经涵盖了 Redhat(和基于 Redhat 的发行版)和 Slackware。

  • 在 Windows WFWG v3.x 和 NT 设置部分中添加了说明,说明为什么用户不应配置 DHCP、WINS 和转发选项。

  • 添加了一个关于如何修复 MASQ 系统 FTP 问题的 FAQ 部分。

  • 修复了更强大的防火墙规则集中的一个错别字。“extip” 变量不能在变量名和 “=” 符号之间有空格。感谢 johnh@mdscomp.com 的敏锐目光。

  • 更新了兼容性部分:Mandrake 7.0 基于 2.2.14,TurboLinux v6.0 运行 2.2.12

从 1.80 到 1.81 的更改 - 00 年 1 月 9 日

  • 更新了 ICQ 部分,以反映新的 ICQ Masq 模块支持文件传输和实时聊天。2.0.x 模块仍然存在这些限制。

  • 更新了 Steven E. Grevemeyer 的电子邮件地址。他是 IP Masq 应用程序页面的维护者。

  • 修复了缺少 “AREN'T” 工作的几行,用于 “setsockopt” 错误。

  • 更新了强 IPCHAINS 规则集中的一个错误,其中使用了变量名 “ppp_ip” 而不是 “extip”。

  • 修复了 DHCP 注释部分第 3.3.1 节中的 “.” 与 “?” 错别字。

  • 为 ICQ 端口转发脚本添加了缺失的 “)”,并将评估从 -lt 更改为 -le

  • 更新了 Quake 模块语法,使其不使用 “ports=” 动词

从 1.79 到 1.80 的更改 - 99 年 12 月 26 日

  • 修复了设置 “ppp_ip” 地址时的空格错别字。

  • 修复了简单 IPCHAINS 规则集中的一个错别字。“deny” 改为 “DENY”

  • 更新了 Bjorn 的 Linux “modutils” 的 URL

  • 添加了关于 NetFilter 和 IPTables 的说明,并提供了 URL,直到它被添加到此 HOWTO 或另一个 HOWTO 中。

  • 更新了简单的 /etc/rc.d/rc.firewall 示例,以告知用户旧的 Quake 模块错误。

  • 更新了强大的 IPFWADM /etc/rc.d/rc.firewall,以向用户澄清有关动态 IP 地址(PPP 和 DHCP)、较新的 DHCPCD 语法和旧的 Quake 模块错误。

  • 更新了强大的 IPCHAINS /etc/rc.d/rc.firewall,以添加有关动态 IP 地址(PPP 和 DHCP)和旧的 Quake 模块错误的缺失部分。

  • 在 “不起作用的应用程序” 部分中添加了一个注释,说明在 2.0.x 内核上存在 Microsoft NetMeeting(基于 H.323)v2.x 的 beta 模块。到目前为止,还没有适用于 Netmeeting 3.x 和/或 2.2.x 内核的版本。

从 1.78 到 1.79 的更改 - 99 年 10 月 21 日

  • 更新了 HOWTO 名称,以反映它不再是 MINI 了!

从 1.77 到 1.78 的更改 - 99 年 8 月 24 日

  • 修复了 “第 6.6 节 - 多个内部网络” 中的一个错别字,其中省略了 -a 策略。

  • 删除了 2.2.x 内核配置选项 “Drop source routed frames”,因为它现在默认启用,并且内核编译选项已删除。

  • 更新了 2.2.x 和所有其他 IPCHAINS 部分,以告知用户 IPCHAINS 分片错误。

  • 更新了所有指向 Lee Nevo 旧 IP Masq 应用程序页面的 URL,使其指向 Seg 的新页面。

从 1.76 到 1.77 的更改 - 99 年 7 月 26 日

  • 修复了端口转发部分中的一个错别字,该错别字使用了 “ipmasqadm ipportfw -C” 而不是 “ipmasqadm portfw -f”

从 1.75 到 1.76 的更改 - 99 年 7 月 19 日

  • 更新了 FAQ 中的 “ipfwadm: setsockopt failed: Protocol not available” 消息,使其更清晰,而不是让用户在转发器部分中寻找答案。

  • 修复了第 6.7 节中 IPMASQADM 和 “portfw” 的不正确语法

从 1.72 到 1.75 的更改 - 99 年 6 月 19 日

  • 修复了弱 IPFWADM 和 IPCHAINS 规则集以及强 IPFWADM 规则集的 Quake 模块端口设置顺序。

  • 添加了用户报告,关于直接端口转发 ICQ 4000,并使用 ICQ 的默认设置,而无需启用 “Non-Sock” 代理设置。

  • 更新了 IPMASQADM 工具的 URL

  • 添加了对 Taro Fukunaga, tarozax@earthlink.net 的引用,感谢他 MkLinux 端口的 HOWTO

  • 更新了关于 Sonny Parlin 的 FWCONFIG 工具的简介,以注意新的 IPCHAINS 支持

  • 注意到 Fred Vile 的端口转发 FTP 访问补丁仅适用于 2.0.x 内核

  • 使用有关 Experiemental 标签的一些说明更新了 2.2.x 内核步骤

  • 将 Glen Lamb 的名字添加到 LooseUDP 补丁的作者列表中

  • 添加了关于安装 LooseUDP 补丁的说明,即对于非压缩补丁应使用 “cat”。

  • 修复了 IPAUTO FAQ 部分中的一个错别字

  • 我将 IPFWADM 和 IPCHAINS 规则集的 DHCP 客户端端口号反转了。我拥有的顺序是如果您的 Linux 服务器是 DHCP 服务器。

  • 为所有弱规则集和强规则集示例添加了显式的 /sbin 路径。

  • 在关于 PPP 和 DHCP 用户的动态 IP 地址的强大 IPFWADM 部分中进行了一些说明。我还注意到,当 PPP 启动或 DHCP 租约续订时,应重新运行强大的规则集。

  • 在 2.2.x 要求中添加了引用,更新了 ICQ FAQ 部分,并将 Andrew Deryabin 添加到他的 ICQ MASQ 模块的作者部分。

  • 为 FAQ 部分添加了一些说明,解释了为什么 2.1.x 和 2.2.x 内核转向 IPCHAINS。

  • 为 FAQ 部分添加了一个关于通过 MASQ 服务器的 Microsoft 文件/打印/域服务 (Samba) 的小部分。我还添加了一个指向 Microsoft Knowledge based 文档的 URL,以获取更多详细信息。

  • 为 FAQ 部分添加了说明,即没有 Debian 发行版开箱即用地支持 IP masq。

  • 更新了 FAQ 部分中受支持的 MASQ 发行版。

  • 在 FAQ 的 Aliased NIC 部分中添加了您无法从别名接口进行 masq 的说明。

  • 哇.. 以前从未注意到这一点,但强规则集部分中的 “ppp-ip” 变量是一个无效的变量名!它已重命名为 “ppp_ip”

  • 在 IPFWADM 和 IPCHAINS 简单规则集设置区域中,我有一个关于启用 DHCP 流量的注释掉的部分。问题是,它位于最后的拒绝行下方!哎呀!我将两者都向上移动了一个部分。

  • 在简单的 IPCHAINS 设置中,对于 DHCP 用户的 #d 行,我使用的是 IPFWADM 的 “-W” 命令,而不是 IPCHAINS 的 “-i” 参数。

  • 在转发器部分中添加了关于著名的 “ipfwadm: setsockopt failed: Protocol not available” 错误解决方案的小简介。这还包括一个小型的 /proc 测试,让用户确认内核中是否启用了 IPPORTFW。我还将此错误添加到了 FAQ 部分,以便于简单搜索。

  • 向 HOWTO 添加了强大的 IPCHAINS 规则集

  • 添加了一个 FAQ 部分,解释了 “kernel: ip_masq_new(proto=UDP): no free ports.” 错误。

  • 添加了脚本化 IPMASQADM PORTFW 规则的示例

  • 更新了一些 Linux Documentation Project (LDP) URL

  • 在所有 rc.firewall 规则集的模块加载部分中添加了 Quake III 支持。

  • 修复了 ICQ 的 IPMASQADM 转发

  • 1.72 - 4/14/99 - Dranch: 在 FAQ 中添加了大量 Windows NAT/Proxy 替代方案列表,其中包含粗略的定价和 URL。

  • 1.71 - 4/13/99 - Dranch: 添加了用于多个内部 MASQ 网络的 IPCHAINS 设置。将 ICQ 设置更改为使用 ICQ 的默认 60 秒超时,并将 IPFWADM/IPCHAINS 超时更改为 160 秒。更新了 MASQ 和 MASQ-DEV 电子邮件列表和存档订阅说明。

  • 1.70 - 3/30/99 - Dranch: 添加了两个新的 FAQ 部分,涵盖 SMTP/POP-3 超时问题以及如何使用 IPROUTE2 将多个内部网络伪装到不同的外部 IP 地址。

  • 1.65 - 3/29/99 - Dranch: 错别字修复,所需的 2.2.x 内核选项的说明,向强大的防火墙部分添加了动态 PPP IP 地址支持,额外的 quake II 模块端口,注意到 LooseUDP 补丁内置于较新的 2.2.x 内核中,它来自 Glenn Lamb 而不是 Dan Kegel,在兼容性部分添加了更多游戏信息。

  • 1.62 - Dranch: 对文档进行最后的初稿更改,现在在 MASQ 电子邮件列表中宣布它。

  • 1.61 - Dranch: 进行了编辑更改,清理了内容并修复了 Windows95 和 NT 设置中的一些错误。

  • 1.58 - Dranch: 添加了端口转发部分;LooseUDP 设置;IRC 用户的 Ident 服务器,如何读取防火墙日志,删除了 CuSeeme Mini-HOWTO,因为它很少使用。

  • 1.55 - Dranch: 对 v1.50 HOWTO 进行了全面修订、功能和 FAQ 添加以及编辑扫描。完成了 2.2.x 内核和 IPCHAINS 配置。对于适用的示例,进行了从 IPAUTOFW 到 IPPORTFW 的转换。添加了许多指向各种其他文档和实用程序站点的 URL。变化太多了.. 我希望每个人都喜欢它。此 HOWTO 新版本的最终发布到 LDP 项目将在文档经过 IP MASQ 电子邮件列表的审查和批准后进行(然后是 v2.00)。

  • 1.50 - Ambrose: 对 HOWTO 进行了重大更新,并初步添加了 2.2.0 和 IPCHAINS 配置。

  • 1.20 - Ambrose: 仅处理 < 2.0.x 内核和 IPFWADM 的较新的 HOWTO 版本之一。