在本文的私有 IP 配置示例中,我们将使用以下示例网络
在本文的注册 IP 配置示例中,我们将使用以下示例网络Internet-------- 200.200.200.* ppp0 or 200.200.200.200 eth1 Dual-Homed Linux Firewall .--- 10.0.0.1 eth0 | |--- 10.0.0.2 VPN client or server |
示例客户端连接到的 VPN 服务器将是Internet-------- 200.200.200.200 eth1 Dual-Homed Linux Firewall .--- 222.0.0.1 eth0 | |--- 222.0.0.2 VPN client or server |
199.0.0.1
连接到示例服务器的 VPN 客户端将是 199.0.0.2
和 199.0.0.3
如果您的 VPN 客户端或服务器具有注册的互联网 IP 地址,则您不需要进行地址伪装或修改内核 - 默认内核将成功路由所有 VPN 流量。您可以直接跳到下面的注册 IP 设置部分。
如果您的 VPN 客户端或服务器具有如 RFC1918 中描述的私有网络 IP 地址,则您需要修补您的内核(除非您的内核是 2.0.x 系列中的 2.0.37 或更高版本)。
如果您正在设置伪装的 VPN 服务器,您还需要获取并安装以下两个软件包
ipportfw
端口转发内核补丁和配置工具。端口转发已并入 2.2.x 内核。有关配置详细信息,请参阅 man ipmasqadm
。如果您的发行版未包含 ipmasqadm
,则可以从 http://juanjox.kernelnotes.org/ 获取。
ipfwd
通用 IP 重定向器。如果您仅伪装客户端,则不需要端口转发或 ipfwd。
/usr/src/linux
的目录中。
如果您的内核版本是 2.0.36 或更低版本,请从上面“资源”部分中的 VPN 伪装主页获取 2.0.x VPN 伪装内核补丁。
如果您的内核版本是 2.0.x 系列中的 2.0.37 或更高版本,则无需应用任何补丁。VPN 伪装代码已包含在内核中。跳过有关修补内核的讨论。
出于本文档的目的,我们假设您已将相应的补丁保存在 /usr/src/ip_masq_vpn.patch.gz
中。
cd /usr/src/linux
zcat ../ip_masq_vpn.patch.gz | patch -l -p0 > vpn-patch.log 2>&1
请注意,选项是“短划线小写 L,短划线小写 P 零”。如果您更改参数的顺序,可能会得到奇怪的结果,因为 patch 似乎对它们在命令行中出现的顺序敏感。
vpn-patch.log
文件,查看是否有任何 hunk 失败。如果出现 hunk 失败,则您可能省略了选项,或者从错误的目录运行了 patch 程序。从备份还原您的内核并重试。
ipportfw
补丁。VPN 伪装补丁与另外两个网络补丁之间存在已知冲突:IP 防火墙链补丁和 ipportfw 补丁。它们都试图在 net/ipv4/Config.in
中的相同位置添加选项,并且一个补丁所做的更改会改变其他补丁正在寻找的上下文。
如果您要将 VPN 伪装补丁和 IP 防火墙链或 ipportfw 补丁应用于您的 2.0.x 内核,则必须手动编辑 net/ipv4/Config.in
并从无法工作的补丁文件中添加配置选项块。查看补丁文件应该会显示您应该在 net/ipv4/Config.in
中的哪个位置添加新选项。
补丁文件的语法很简单。对于要进行的每个更改块,都有两个部分:第一部分显示“之前”状态,并指示要更改或删除的行;第二部分显示“之后”状态,并指示已更改或添加的行。使用第一部分查找添加行的位置,并添加第二部分中指示的行。
一旦这些补丁更新为 2.0.37+,这应该不是问题
* Prompt for development and/or incomplete code/drivers
CONFIG_EXPERIMENTAL
- You must enable this to see the VPN Masq options.
* Networking support
CONFIG_NET
* Network firewalls
CONFIG_FIREWALL
* TCP/IP networking
CONFIG_INET
* IP: forwarding/gatewaying
CONFIG_IP_FORWARD
* IP: firewalling
CONFIG_IP_FIREWALL
* IP: masquerading (EXPERIMENTAL)
CONFIG_IP_MASQUERADE
- This is required.
* IP: PPTP masq support (EXPERIMENTAL)
CONFIG_IP_MASQUERADE_PPTP
- Enables PPTP data channel masquerading, if you are
masquerading a PPTP client or server.
* IP: PPTP Call ID masq support (EXPERIMENTAL)
CONFIG_IP_MASQUERADE_PPTP_MULTICLIENT
- Enables PPTP Call ID masquerading; only necessary if
you will be masquerading more than one client trying
to connect to the same remote server. DO NOT enable
this option if you will be masquerading a PPTP server.
* IP: IPsec ESP & ISAKMP masq support (EXPERIMENTAL)
CONFIG_IP_MASQUERADE_IPSEC
- Enables IPsec masquerade, if you are masquerading an
IPsec host.
* IP: IPSEC masq table lifetime (minutes)
- See your network administrator to determine what the
"rekey interval" or "key lifetime" is set to. The
default lifetime of masq table entries is thirty
minutes. If your rekey interval is greater than
thirty minutes, then you should increase the lifetime
to a value slightly greater than the rekey interval.
* IP: always defragment
CONFIG_IP_ALWAYS_DEFRAG
- Highly recommended for a firewall.
注意: 这些只是您进行伪装所需的设置。选择您的特定设置所需的任何其他选项。
要确定正在运行的内核是否包含 VPN 伪装支持,请运行以下命令
...并查找以下条目grep -i masq /proc/ksyms
ip_masq_out_get_isakmp
、ip_masq_in_get_isakmp
、ip_fw_masq_esp
和 ip_fw_demasq_esp
ip_fw_masq_gre
和 ip_fw_demasq_gre
ip_masq_pptp
如果您没有看到这些条目,则 VPN 伪装支持可能不可用。如果您收到有关 /proc/ksyms
不可用或 /proc
不可用的投诉,请确保您已在内核配置中启用了 /proc
文件系统。
有关配置和重新编译内核的更多详细信息,请参阅 Kernel HOWTO。
如果您正在使用 IPsec 伪装,并且您的系统正在生成常规保护错误(请参阅 /var/log/messages
)或正在锁定,请参阅 VPN 伪装主页 以获取更新。此补丁适用于 2.0.38,但应该适用于较早的内核。它已提交给 Alan Cox,以包含在 2.0.39 内核中。
/usr/src/linux
的目录中。
出于本文档的目的,我们假设您已将相应的补丁保存在 /usr/src/ip_masq_vpn.patch.gz
中。
cd /usr/src
zcat ip_masq_vpn.patch.gz | patch -l -p0 > vpn-patch.log 2>&1
请注意,选项是“短划线小写 L,短划线小写 P 零”。如果您更改参数的顺序,可能会得到奇怪的结果,因为 patch 似乎对它们在命令行中出现的顺序敏感。
另请注意,对于 2.2.x 内核补丁,您运行 patch 命令的目录是不同的
vpn-patch.log
文件,查看是否有任何 hunk 失败。如果出现 hunk 失败,则您可能省略了选项,或者从错误的目录运行了 patch 程序。从备份还原您的内核并重试。
ipportfw
补丁,因为端口转发现在是内置的。有关更多详细信息,请参阅 ipmasqadm
手册页。如果您的发行版未包含 ipmasqadm
,则可以从 http://juanjox.kernelnotes.org/ 获取。
* Prompt for development and/or incomplete code/drivers
CONFIG_EXPERIMENTAL
- You must enable this to see the VPN Masq options.
* Networking support
CONFIG_NET
* Network firewalls
CONFIG_FIREWALL
* TCP/IP networking
CONFIG_INET
* IP: firewalling
CONFIG_IP_FIREWALL
* IP: always defragment
CONFIG_IP_ALWAYS_DEFRAG
- Required for masquerading. This may or may not
be in your kernel config. If not, you should
run this in your startup scripts:
echo 1 > /proc/sys/net/ipv4/ip_always_defrag
* IP: masquerading (EXPERIMENTAL)
CONFIG_IP_MASQUERADE
- This is required.
* IP: masquerading special modules support
CONFIG_IP_MASQUERADE_MOD
- This is required.
* IP: ipportfw masq support (EXPERIMENTAL)
CONFIG_IP_MASQUERADE_IPPORTFW
- Enable this if you will be masquerading a VPN server.
* IP: PPTP masq support
CONFIG_IP_MASQUERADE_PPTP
- Enables PPTP data channel masquerading, if you are
masquerading a PPTP client or server. This is now
available as a module.
Note that you no longer need to specify Call-ID masquerade.
* IP: IPsec ESP & ISAKMP masq support (EXPERIMENTAL)
CONFIG_IP_MASQUERADE_IPSEC
- Enables IPsec masquerade, if you are masquerading an
IPsec host. This is now available as a module.
* IP: IPsec masq table lifetime (minutes)
- See your network administrator to determine what the
"rekey interval" or "key lifetime" is set to. The default
lifetime of masq table entries is thirty minutes. If
your rekey interval is greater than thirty minutes,
then you should increase the lifetime to a value
slightly greater than the rekey interval.
* IP: Enable parallel sessions (possible security risk - see help)
CONFIG_IP_MASQUERADE_IPSEC_PAROK
- See the IPsec masquerade technical notes and special
security considerations section of the HOWTO for
security considerations to be aware of when
masquerading IPsec traffic. If you are only
masquerading one IPsec client this setting has no
effect.
对以下选项选择否
* IP: GRE tunnels over IP
CONFIG_NET_IPGRE
- This, confusingly, has *NOTHING* to do with PPTP.
It enables support for GRE tunnels as used by Cisco
routers. The fact that you see this option does not
imply that PPTP support is available. You still need
to apply the VPN Masquerade patch if the PPTP options
listed above do not appear when you are configuring
your kernel. DO NOT enable this unless you are setting
up a GRE tunnel to a Cisco router.
注意: 这些只是您进行伪装所需的设置。选择您的特定设置所需的任何其他选项。
要确定正在运行的内核是否包含 VPN 伪装支持,请运行以下命令
...并查找以下条目grep -i masq /proc/ksyms
ip_masq_esp
和 ip_demasq_esp
ip_masq_pptp_tcp
和 ip_demasq_pptp_tcp
...并查找以下条目lsmod
ip_masq_ipsec
ip_masq_pptp
如果您没有看到这些条目,则 VPN 伪装支持可能不可用 - 您是否记得在将它们编译为模块时 modprobe ip_masq_pptp.o
或 modprobe ip_masq_ipsec.o
?如果 VPN 伪装在您重新启动后停止工作,您是否记得将 modprobe
命令添加到您的 /etc/rc.d/rc.local
启动脚本中?
如果您收到有关 /proc/ksyms
不可用或 /proc
不可用的投诉,请确保您已在内核配置中启用了 /proc
文件系统。
有关配置和重新编译内核的更多详细信息,请参阅 Kernel HOWTO。
现在必须配置防火墙以伪装出站 VPN 流量。您可能希望访问 http://www.wolfenet.com/~jhardin/ipfwadm.html 以查看 ipfwadm 命令的 GUI 包装器,该包装器自动化了许多与安全相关的包过滤设置。
最小防火墙规则是
但这完全是一个开放的设置。它将伪装来自本地网络上任何主机,目标为互联网上任何主机的任何流量,并且根本不提供任何安全性。# Set the default forwarding policy to DENY: ipfwadm -F -p deny # Allow local-network traffic ipfwadm -I -a accept -S 10.0.0.0/8 -D 0.0.0.0/0 -W eth0 ipfwadm -O -a accept -S 0.0.0.0/0 -D 10.0.0.0/8 -W eth0 # Masquerade traffic for internet addresses and allow internet traffic ipfwadm -F -a accept -m -S 10.0.0.0/8 -D 0.0.0.0/0 -W ppp0 ipfwadm -O -a accept -S 0.0.0.0/0 -D 0.0.0.0/0 -W ppp0 ipfwadm -I -a accept -S 0.0.0.0/0 -D 0.0.0.0/0 -W ppp0或者,如果您有永久连接,ipfwadm -F -a accept -m -S 10.0.0.0/8 -D 0.0.0.0/0 -W eth1 ipfwadm -O -a accept -S 0.0.0.0/0 -D 0.0.0.0/0 -W eth1 ipfwadm -I -a accept -S 0.0.0.0/0 -D 0.0.0.0/0 -W eth1
严格的防火墙设置将仅允许客户端和服务器之间的流量,并阻止其他所有流量
# Set the default policy to DENY: ipfwadm -I -p deny ipfwadm -O -p deny ipfwadm -F -p deny # Allow local-network traffic ipfwadm -I -a accept -S 10.0.0.0/8 -D 0.0.0.0/0 -W eth0 ipfwadm -O -a accept -S 0.0.0.0/0 -D 10.0.0.0/8 -W eth0 # Masquerade only VPN traffic between the VPN client and the VPN server ipfwadm -F -a accept -m -P udp -S 10.0.0.2/32 500 -D 199.0.0.1/32 500 -W ppp0 ipfwadm -F -a accept -m -P tcp -S 10.0.0.2/32 -D 199.0.0.1/32 1723 -W ppp0 ipfwadm -F -a deny -P tcp -S 10.0.0.2/32 -D 199.0.0.1/32 -W ppp0 ipfwadm -F -a deny -P udp -S 10.0.0.2/32 -D 199.0.0.1/32 -W ppp0 ipfwadm -F -a accept -m -P all -S 10.0.0.2/32 -D 199.0.0.1/32 -W ppp0 ipfwadm -O -a accept -P udp -S 200.200.200.0/24 500 -D 199.0.0.1/32 500 -W ppp0 ipfwadm -O -a accept -P tcp -S 200.200.200.0/24 -D 199.0.0.1/32 1723 -W ppp0 ipfwadm -O -a deny -P tcp -S 200.200.200.0/24 -D 199.0.0.1/32 -W ppp0 ipfwadm -O -a deny -P udp -S 200.200.200.0/24 -D 199.0.0.1/32 -W ppp0 ipfwadm -O -a accept -P all -S 200.200.200.0/24 -D 199.0.0.1/32 -W ppp0 ipfwadm -I -a accept -P udp -S 199.0.0.1/32 500 -D 200.200.200.0/24 500 -W ppp0 ipfwadm -I -a accept -P tcp -S 199.0.0.1/32 1723 -D 200.200.200.0/24 -W ppp0 ipfwadm -I -a deny -P tcp -S 199.0.0.1/32 -D 200.200.200.0/24 -W ppp0 ipfwadm -I -a deny -P udp -S 199.0.0.1/32 -D 200.200.200.0/24 -W ppp0 ipfwadm -I -a accept -P all -S 199.0.0.1/32 -D 200.200.200.0/24 -W ppp0或者,如果您有永久连接,ipfwadm -F -a accept -m -P udp -S 10.0.0.2/32 500 -D 199.0.0.1/32 500 -W eth1 ipfwadm -F -a accept -m -P tcp -S 10.0.0.2/32 -D 199.0.0.1/32 1723 -W eth1 ipfwadm -F -a deny -P tcp -S 10.0.0.2/32 -D 199.0.0.1/32 -W eth1 ipfwadm -F -a deny -P udp -S 10.0.0.2/32 -D 199.0.0.1/32 -W eth1 ipfwadm -F -a accept -m -P all -S 10.0.0.2/32 -D 199.0.0.1/32 -W eth1 ipfwadm -O -a accept -P udp -S 200.200.200.200/32 500 -D 199.0.0.1/32 500 -W eth1 ipfwadm -O -a accept -P tcp -S 200.200.200.200/32 -D 199.0.0.1/32 1723 -W eth1 ipfwadm -O -a deny -P tcp -S 200.200.200.200/32 -D 199.0.0.1/32 -W eth1 ipfwadm -O -a deny -P udp -S 200.200.200.200/32 -D 199.0.0.1/32 -W eth1 ipfwadm -O -a accept -P all -S 200.200.200.200/32 -D 199.0.0.1/32 -W eth1 ipfwadm -I -a accept -P udp -S 199.0.0.1/32 500 -D 200.200.200.200/32 500 -W eth1 ipfwadm -I -a accept -P tcp -S 199.0.0.1/32 1723 -D 200.200.200.200/32 -W eth1 ipfwadm -I -a deny -P tcp -S 199.0.0.1/32 -D 200.200.200.200/32 -W eth1 ipfwadm -I -a deny -P udp -S 199.0.0.1/32 -D 200.200.200.200/32 -W eth1 ipfwadm -I -a accept -P all -S 199.0.0.1/32 -D 200.200.200.200/32 -W eth1
注意:这些规则仅允许 VPN 流量,并阻止其他所有流量。您必须为您希望允许的任何其他流量添加规则,例如 DNS、HTTP、POP、IMAP 等。
最小 ipchains 防火墙规则是
但这完全是一个开放的设置。它将伪装来自本地网络上任何主机,目标为互联网上任何主机的任何流量,并且根本不提供任何安全性。# Set the default forwarding policy to DENY: ipchains -P forward DENY # Allow local-network traffic ipchains -A input -j ACCEPT -s 10.0.0.0/8 -d 0.0.0.0/0 -i eth0 ipchains -A output -j ACCEPT -s 0.0.0.0/0 -d 10.0.0.0/8 -i eth0 # Masquerade traffic for internet addresses and allow internet traffic ipchains -A forward -j MASQ -s 10.0.0.0/8 -d 0.0.0.0/0 -i ppp0 ipchains -A output -j ACCEPT -s 0.0.0.0/0 -d 0.0.0.0/0 -i ppp0 ipchains -A input -j ACCEPT -s 0.0.0.0/0 -d 0.0.0.0/0 -i ppp0或者,如果您有永久连接,ipchains -A forward -j MASQ -s 10.0.0.0/8 -d 0.0.0.0/0 -i eth1 ipchains -A output -j ACCEPT -s 0.0.0.0/0 -d 0.0.0.0/0 -i eth1 ipchains -A input -j ACCEPT -s 0.0.0.0/0 -d 0.0.0.0/0 -i eth1
严格的防火墙设置将仅允许客户端和服务器之间的流量,并阻止其他所有流量
# Set the default policy to DENY: ipchains -P input DENY ipchains -P output DENY ipchains -P forward DENY # Allow local-network traffic ipchains -A input -j ACCEPT -s 10.0.0.0/8 -d 0.0.0.0/0 -i eth0 ipchains -A output -j ACCEPT -s 0.0.0.0/0 -d 10.0.0.0/8 -i eth0 # Masquerade only VPN traffic between the VPN client and the VPN server # IPsec ipchains -A forward -j MASQ -p udp -s 10.0.0.2/32 500 -d 199.0.0.1/32 500 -i ppp0 ipchains -A output -j ACCEPT -p udp -s 200.200.200.0/24 500 -d 199.0.0.1/32 500 -i ppp0 ipchains -A input -j ACCEPT -p udp -s 199.0.0.1/32 500 -d 200.200.200.0/24 500 -i ppp0 ipchains -A forward -j MASQ -p 50 -s 10.0.0.2/32 -d 199.0.0.1/32 -i ppp0 ipchains -A output -j ACCEPT -p 50 -s 200.200.200.0/24 -d 199.0.0.1/32 -i ppp0 ipchains -A input -j ACCEPT -p 50 -s 199.0.0.1/32 -d 200.200.200.0/24 -i ppp0 # PPTP ipchains -A forward -j MASQ -p tcp -s 10.0.0.2/32 -d 199.0.0.1/32 1723 -i ppp0 ipchains -A output -j ACCEPT -p tcp -s 200.200.200.0/24 -d 199.0.0.1/32 1723 -i ppp0 ipchains -A input -j ACCEPT -p tcp -s 199.0.0.1/32 1723 -d 200.200.200.0/24 -i ppp0 ipchains -A forward -j MASQ -p 47 -s 10.0.0.2/32 -d 199.0.0.1/32 -i ppp0 ipchains -A output -j ACCEPT -p 47 -s 200.200.200.0/24 -d 199.0.0.1/32 -i ppp0 ipchains -A input -j ACCEPT -p 47 -s 199.0.0.1/32 -d 200.200.200.0/24 -i ppp0或者,如果您有永久连接,# IPsec ipchains -A forward -j MASQ -p udp -s 10.0.0.2/32 500 -d 199.0.0.1/32 500 -i eth1 ipchains -A output -j ACCEPT -p udp -s 200.200.200.200/32 500 -d 199.0.0.1/32 500 -i eth1 ipchains -A input -j ACCEPT -p udp -s 199.0.0.1/32 500 -d 200.200.200.200/32 500 -i eth1 ipchains -A forward -j MASQ -p 50 -s 10.0.0.2/32 -d 199.0.0.1/32 -i eth1 ipchains -A output -j ACCEPT -p 50 -s 200.200.200.200/32 -d 199.0.0.1/32 -i eth1 ipchains -A input -j ACCEPT -p 50 -s 199.0.0.1/32 -d 200.200.200.200/32 -i eth1 # PPTP ipchains -A forward -j MASQ -p tcp -s 10.0.0.2/32 -d 199.0.0.1/32 1723 -i eth1 ipchains -A output -j ACCEPT -p tcp -s 200.200.200.200/32 -d 199.0.0.1/32 1723 -i eth1 ipchains -A input -j ACCEPT -p tcp -s 199.0.0.1/32 1723 -d 200.200.200.200/32 -i eth1 ipchains -A forward -j MASQ -p 47 -s 10.0.0.2/32 -d 199.0.0.1/32 -i eth1 ipchains -A output -j ACCEPT -p 47 -s 200.200.200.200/32 -d 199.0.0.1/32 -i eth1 ipchains -A input -j ACCEPT -p 47 -s 199.0.0.1/32 -d 200.200.200.200/32 -i eth1
注意:这些规则仅允许 VPN 流量。您必须为您希望允许的任何其他流量添加规则,例如 DNS、HTTP、POP、IMAP 等。
另请注意,这些规则比等效的 ipfwadm 规则更简洁,更容易理解。这是因为 ipchains 允许指定所有 IP 协议,而不仅仅是 TCP、UDP、ICMP 或 ALL。
如果您的防火墙由您的 ISP 分配了动态 IP 地址(拨号帐户是这种情况,某些有线互联网服务也是如此),那么您应该将以下内容添加到启动脚本 /etc/rc.d/rc.local
中
这启用了动态 IP 地址跟踪,这意味着如果您的连接断开并重新建立,任何活动的会话都将更新为新的 IP 地址,而不是使用旧的 IP 地址。这并不意味着会话将在中断期间继续,而是会很快关闭。echo 7 > /proc/sys/net/ipv4/ip_dynaddr
如果您不这样做,那么在您重拨后和旧的 masq 表条目过期之前,可能会有一个“死区”,在此期间您正在使用错误的 IP 地址进行伪装,这将阻止您建立连接。
如果您正在使用诸如 diald
之类的按需拨号守护程序来管理您的拨号连接,这将特别有帮助。
有关更多详细信息,请参阅 /usr/src/linux/Documentation/networking/ip_dynaddr.txt
。
如果您正在为私有 IP VPN 服务器设置 VPN 伪装(也就是说,您希望为入站连接以及出站连接提供支持),您还需要安装两个数据包转发实用程序。一个 (ipportfw
) 将寻址到防火墙系统上特定端口的入站 TCP 或 UDP 流量转发到防火墙后面的本地网络上的系统。这用于将初始入站 1723/tcp PPTP 控制通道或 500/udp ISAKMP 流量重定向到 VPN 服务器。另一个 (ipfwd
) 是一个更通用的转发实用程序,允许您对任何 IP 协议执行此操作。它用于将初始入站 47/ip (GRE) 或 50/ip (ESP) 数据通道流量转发到 VPN 服务器。
入站 1723/tcp 或 500/udp 流量的出站响应使用 Linux 内核中的正常 IP 伪装工具进行伪装。出站 47/ip 或 50/ip 流量使用您之前安装的 VPN 伪装内核补丁进行伪装。
安装这些实用程序后,您必须配置它们以将流量转发到 VPN 服务器。
ipportfw
以下命令将设置 ipportfw
以将初始入站 500/udp 流量转发到 IPsec 服务器
以下命令将设置# Static-IP ipportfw setup for IPsec # Clear the ipportfw forwarding table /sbin/ipportfw -C # Forward traffic addressed to the firewall's 500/udp port # to the IPsec server's 500/udp port /sbin/ipportfw -A -u 200.200.200.200/500 -R 10.0.0.2/500
ipportfw
以将初始入站 1723/tcp 流量转发到 PPTP 服务器请注意,ipportfw 命令行需要防火墙的互联网 IP 地址,并且您不能像使用 ipfwadm 那样指定接口(例如# Static-IP ipportfw setup for PPTP # Clear the ipportfw forwarding table /sbin/ipportfw -C # Forward traffic addressed to the firewall's 1723/tcp port # to the PPTP server's 1723/tcp port /sbin/ipportfw -A -t 200.200.200.200/1723 -R 10.0.0.2/1723
ppp0
)。这意味着对于动态 IP 连接(例如典型的拨号 PPP 连接),您必须在每次连接到互联网并分配新 IP 地址时运行这些命令。您可以非常轻松地做到这一点 - 只需将以下内容添加到您的 /etc/ppp/ip-up
或 /etc/ppp/ip-up.local
脚本中或# Dynamic-IP ipportfw setup for IPsec # Clear the ipportfw forwarding table /sbin/ipportfw -C # Forward traffic addressed to the firewall's 500/udp port # to the IPsec server's 500/udp port /sbin/ipportfw -A -u ${4}/500 -R 10.0.0.2/500
有关使用动态 IP 进行防火墙的更多信息,请参阅 http://www.wolfenet.com/~jhardin/ipfwadm/invocation.html。# Dynamic-IP ipportfw setup for PPTP # Clear the ipportfw forwarding table /sbin/ipportfw -C # Forward traffic addressed to the firewall's 1723/tcp port # to the PPTP server's 1723/tcp port /sbin/ipportfw -A -t ${4}/1723 -R 10.0.0.2/1723
ipfwd
以下命令将设置 ipfwd
以将初始入站 50/ip 流量转发到 IPsec 服务器
以下命令将设置/sbin/ipfwd --masq 10.0.0.2 50 &
ipfwd
以将初始入站 47/ip 流量转发到 PPTP 服务器它应该只运行一次,从您的/sbin/ipfwd --masq 10.0.0.2 47 &
/etc/rc.d/rc.local
脚本中运行。
此处描述的技术可以推广到允许伪装大多数任何类型的服务器 - HTTP、FTP、SMTP 等。纯粹基于 TCP 或 UDP 的服务器不需要 ipfwd
。
如果您要伪装 PPTP 服务器,还需要确保您没有在内核中启用 PPTP Call ID 伪装。启用 PPTP Call ID 伪装会构建一些假设,即您仅伪装 PPTP 客户端,因此启用它会阻止正确伪装 PPTP 服务器流量。这也意味着,使用 2.0.x 版本的补丁,您不能同时伪装 PPTP 服务器和 PPTP 客户端。
在 Linux 防火墙后面设置注册 IP VPN 服务器是一个简单的问题,即确保适当的路由和数据包过滤命令就位。不需要伪装。
不幸的是,2.0.x 系列内核不允许我们直接指定 IP 协议 47 或 50,因此此防火墙的安全性不如它本可以达到的水平。如果这对您来说是一个问题,那么请安装 IP 防火墙链内核补丁或迁移到 2.1.x 或 2.2.x 系列内核,您可以在其中按 IP 协议进行过滤。
防火墙规则看起来像这样
# This section should follow your other firewall rules. # Specify the acceptable clients explicitly for tighter security. # Allow the IPsec ISAKMP traffic in and out. ipfwadm -I -a accept -W eth1 -V 200.200.200.200 -P udp -S 199.0.0.2/32 500 -D 222.0.0.2/32 500 ipfwadm -O -a accept -W eth1 -V 200.200.200.200 -P udp -D 199.0.0.2/32 500 -S 222.0.0.2/32 500 ipfwadm -I -a accept -W eth1 -V 200.200.200.200 -P udp -S 199.0.0.3/32 500 -D 222.0.0.2/32 500 ipfwadm -O -a accept -W eth1 -V 200.200.200.200 -P udp -D 199.0.0.3/32 500 -S 222.0.0.2/32 500 # Allow the PPTP control channel in and out. ipfwadm -I -a accept -W eth1 -V 200.200.200.200 -P tcp -S 199.0.0.2/32 -D 222.0.0.2/32 1723 ipfwadm -O -a accept -W eth1 -V 200.200.200.200 -P tcp -D 199.0.0.2/32 -S 222.0.0.2/32 1723 ipfwadm -I -a accept -W eth1 -V 200.200.200.200 -P tcp -S 199.0.0.3/32 -D 222.0.0.2/32 1723 ipfwadm -O -a accept -W eth1 -V 200.200.200.200 -P tcp -D 199.0.0.3/32 -S 222.0.0.2/32 1723 # Block all other TCP and UDP traffic from the internet. # This is essentially a "default deny TCP/UDP" that # only applies to the internet interface. ipfwadm -I -a deny -W eth1 -V 200.200.200.200 -P tcp ipfwadm -I -a deny -W eth1 -V 200.200.200.200 -P udp # Specify the acceptable clients explicitly for tighter security. # Note that this is too open since we're forced to # specify "-P all" rather than "-P 47" or "-P 50"... # Allow the PPTP data channel and IPsec ESP traffic in and out. ipfwadm -I -a accept -W eth1 -V 200.200.200.200 -P all -S 199.0.0.2/32 -D 222.0.0.2/32 ipfwadm -0 -a accept -W eth1 -V 200.200.200.200 -P all -D 199.0.0.2/32 -S 222.0.0.2/32 ipfwadm -I -a accept -W eth1 -V 200.200.200.200 -P all -S 199.0.0.3/32 -D 222.0.0.2/32 ipfwadm -O -a accept -W eth1 -V 200.200.200.200 -P all -D 199.0.0.3/32 -S 222.0.0.2/32 # Block all other traffic from the internet. # This is essentially a "default deny" that # only applies to the internet interface. ipfwadm -I -a deny -W eth1 -V 200.200.200.200
如果您要在转发和/或内部接口上安装防火墙规则,则需要执行类似的操作。上面的示例仅涵盖 VPN 流量;您必须将其合并到您现有的防火墙设置中,以允许您需要的任何其他流量。
在 Linux 防火墙后面设置注册 IP VPN 客户端类似于设置注册 IP VPN 服务器。
防火墙规则看起来像这样
# Allow the IPsec ISAKMP traffic out and in. ipfwadm -O -a accept -W eth1 -V 200.200.200.200 -P udp -S 222.0.0.2/32 500 -D 199.0.0.1/32 500 ipfwadm -I -a accept -W eth1 -V 200.200.200.200 -P udp -D 222.0.0.2/32 500 -S 199.0.0.1/32 500 # Allow the PPTP control channel out and in. ipfwadm -O -a accept -W eth1 -V 200.200.200.200 -P tcp -S 222.0.0.2/32 -D 199.0.0.1/32 1723 ipfwadm -I -a accept -W eth1 -V 200.200.200.200 -P tcp -D 222.0.0.2/32 -S 199.0.0.1/32 1723 # Block all other TCP and UDP traffic from the internet. # This is essentially a "default deny TCP/UDP" that # only applies to the internet interface. ipfwadm -I -a deny -W eth1 -V 200.200.200.200 -P tcp ipfwadm -I -a deny -W eth1 -V 200.200.200.200 -P udp # Note that this is too open since we're forced to # specify "-P all" rather than "-P 47" or "-P 50"... # Allow the PPTP data channel and IPsec ESP traffic out and in ipfwadm -O -a accept -W eth1 -V 200.200.200.200 -P all -S 222.0.0.2/32 -D 199.0.0.1/32 ipfwadm -I -a accept -W eth1 -V 200.200.200.200 -P all -D 222.0.0.2/32 -S 199.0.0.1/32 # Block all other traffic from the internet. # This is essentially a "default deny" that # only applies to the internet interface. ipfwadm -I -a deny -W eth1 -V 200.200.200.200
在 Linux 防火墙后面设置注册 IP VPN 服务器是一个简单的问题,即确保适当的路由和数据包过滤命令就位。不需要伪装。
防火墙规则看起来像这样
# Specify the acceptable clients explicitly for tighter security. # Allow the IPsec ISAKMP traffic in and out. ipchains -A input -j ACCEPT -p udp -s 199.0.0.2/32 500 -d 222.0.0.2/32 500 -i eth1 ipchains -A output -j ACCEPT -p udp -d 199.0.0.2/32 500 -s 222.0.0.2/32 500 -i eth1 ipchains -A input -j ACCEPT -p udp -s 199.0.0.3/32 500 -d 222.0.0.2/32 500 -i eth1 ipchains -A output -j ACCEPT -p udp -d 199.0.0.3/32 500 -s 222.0.0.2/32 500 -i eth1 # Allow the IPsec ESP traffic in and out. ipchains -A input -j ACCEPT -p 50 -s 199.0.0.2/32 -d 222.0.0.2/32 -i eth1 ipchains -A output -j ACCEPT -p 50 -d 199.0.0.2/32 -s 222.0.0.2/32 -i eth1 ipchains -A input -j ACCEPT -p 50 -s 199.0.0.3/32 -d 222.0.0.2/32 -i eth1 ipchains -A output -j ACCEPT -p 50 -d 199.0.0.3/32 -s 222.0.0.2/32 -i eth1 # Allow the PPTP control channel in and out. ipchains -A input -j ACCEPT -p tcp -s 199.0.0.2/32 -d 222.0.0.2/32 1723 -i eth1 ipchains -A output -j ACCEPT -p tcp -d 199.0.0.2/32 -s 222.0.0.2/32 1723 -i eth1 ipchains -A input -j ACCEPT -p tcp -s 199.0.0.3/32 -d 222.0.0.2/32 1723 -i eth1 ipchains -A output -j ACCEPT -p tcp -d 199.0.0.3/32 -s 222.0.0.2/32 1723 -i eth1 # Allow the PPTP tunnel in and out. ipchains -A input -j ACCEPT -p 47 -s 199.0.0.2/32 -d 222.0.0.2/32 -i eth1 ipchains -A output -j ACCEPT -p 47 -d 199.0.0.2/32 -s 222.0.0.2/32 -i eth1 ipchains -A input -j ACCEPT -p 47 -s 199.0.0.3/32 -d 222.0.0.2/32 -i eth1 ipchains -A output -j ACCEPT -p 47 -d 199.0.0.3/32 -s 222.0.0.2/32 -i eth1
如果您要在转发和/或内部接口上安装防火墙规则,则需要执行类似的操作。上面的示例仅涵盖 VPN 流量;您必须将其合并到您现有的防火墙设置中,以允许您需要的任何其他流量。
在 Linux 防火墙后面设置注册 IP VPN 客户端类似于设置注册 IP VPN 服务器。
防火墙规则看起来像这样
# Allow the IPsec ISAKMP traffic out and in. ipchains -A output -j ACCEPT -p udp -s 222.0.0.2/32 500 -d 199.0.0.1/32 500 -i eth1 ipchains -A input -j ACCEPT -p udp -d 222.0.0.2/32 500 -s 199.0.0.1/32 500 -i eth1 # Allow the IPsec ESP traffic out and in. ipchains -A output -j ACCEPT -p 50 -s 222.0.0.2/32 -d 199.0.0.1/32 -i eth1 ipchains -A input -j ACCEPT -p 50 -d 222.0.0.2/32 -s 199.0.0.1/32 -i eth1 # Allow the PPTP control channel out and in. ipchains -A output -j ACCEPT -p tcp -s 222.0.0.2/32 -d 199.0.0.1/32 1723 -i eth1 ipchains -A input -j ACCEPT -p tcp -d 222.0.0.2/32 -s 199.0.0.1/32 1723 -i eth1 # Allow the PPTP tunnel out and in. ipchains -A output -j ACCEPT -p 47 -s 222.0.0.2/32 -d 199.0.0.1/32 -i eth1 ipchains -A input -j ACCEPT -p 47 -d 222.0.0.2/32 -s 199.0.0.1/32 -i eth1
http://www.linuxrouter.org/ 上的 Linux 路由器项目提供了一个基于 Linux 的软盘防火墙套件。使用 '386 PC、两张网卡和一个软盘驱动器,您可以设置一个功能齐全的伪装防火墙。不需要硬盘。
VPN 伪装应该包含在 LRP 2.2.9 版本中 - 要验证它是否可用,请查看 Package Settings -> Modules
中的可加载模块中是否列出了 ip_masq_ipsec
或 ip_masq_pptp
,或者如上所述 grep /proc/ksyms
。如果您想将 VPN 伪装添加到早期版本的 LRP,那么 LRP 邮件列表中的某人可能能够为您提供软盘映像,或者您可以使用 LRP 主页上提供的说明来滚动您自己的内核。
防火墙规则将添加到 Network Settings -> Direct Network Setup
中的启动脚本文件中。
如果您要将防火墙用作带有 FreeS/WAN 的 IPsec 网关,则必须不启用 IPsec 伪装。如果您要将防火墙用作带有 PoPToP 的 PPTP 服务器,或使用 Linux PPTP 客户端软件的 PPTP 客户端,则必须不启用 PPTP 伪装。
VPN 伪装和使用相同协议的 VPN 客户端或服务器目前不能在同一台计算机上共存。
但是,您的防火墙可以是 FreeS/WAN IPsec VPN 网关,同时伪装 PPTP 流量,反之亦然。