在运行 FreeS/WAN 软件之前,您必须确保一些事项是正确的。如果您不想在启动 VPN 期间收到错误消息,这些注意事项非常重要。以下是必需的
您需要在两个网关服务器上启用 TCP/IP 转发。在 Red Hat Linux 中,这可以通过更改或添加以下行来完成,具体取决于您使用的 Red Hat 版本
FORWARD_IPV4="false" |
FORWARD_IPV4="yes" |
您必须重启网络才能使更改生效
[root@deep] /# /etc/rc.d/init.d/network restart |
Bringing up interface lo [ OK ] Bringing up interface eth0 [ OK ] Bringing up interface eth1 [ OK ] |
要在您的 RH 6.2 系统上启用 IPv4 转发,请使用以下命令:编辑/etc/sysctl.conf文件并添加以下行
# Enable packet forwarding net.ipv4.ip_forward = 1 |
您必须重启网络才能使更改生效。重启网络的命令如下
[root@deep] /# /etc/rc.d/init.d/network restart |
Setting network parameters [ OK ] Bringing up interface lo [ OK ] Bringing up interface eth0 [ OK ] Bringing up interface eth1 [ OK ] |
请注意,自动密钥连接使用由 Pluto 密钥协商守护进程自动生成的密钥。pluto 守护进程将启动,尝试连接到隧道另一端的 Pluto 守护进程,并建立连接。因此,IPSEC 网关应在防火墙脚本文件中包含数据包过滤器规则,以允许以下协议在与其他 IPSEC 网关通信时穿过网关
UDP 端口 500,用于 Pluto 守护进程实现的 IKE
协议 50,用于 ESP 加密和/或身份验证
协议 51,用于 AH 数据包级身份验证
编辑firewall脚本文件,vi/etc/rc.d/init.d/firewall在两台网关机器上,添加/检查以下行,以允许 IPSEC 数据包从远程网络网关穿越到您的网络网关,反之亦然
# FreeS/WAN IPSec VPN # ------------------- # If you are using the FreeSWAN IPSec VPN, you will need to fill in the # addresses of the gateways in the IPSECSG and the virtual interfaces for # FreeS/Wan IPSEC in the FREESWANVI parameters. Look at the beginning of # this firewall script rules file to set the parameters. # IPSECSG is a Space separated list of remote gateways. FREESWANVI is a # Space separated list of virtual interfaces for FreeS/Wan IPSEC # implementation. Only include those that are actually used. # Allow IPSEC protocol from remote gateways on external interface # IPSEC uses three main types of packet: # IKE uses the UDP protocol and port 500, # ESP use the protocol number 50, and # AH use the protocol number 51 ipchains -A input -i $EXTERNAL_INTERFACE -p udp \ -s $IPSECSG -j ACCEPT ipchains -A output -i $EXTERNAL_INTERFACE -p udp \ -d $IPSECSG -j ACCEPT ipchains -A input -i $EXTERNAL_INTERFACE -p 50 \ -s $IPSECSG -j ACCEPT ipchains -A output -i $EXTERNAL_INTERFACE -p 50 \ -d $IPSECSG -j ACCEPT ipchains -A input -i $EXTERNAL_INTERFACE -p 51 \ -s $IPSECSG -j ACCEPT ipchains -A output -i $EXTERNAL_INTERFACE -p 51 \ -d $IPSECSG -j ACCEPT # Allow all traffic to FreeS/WAN Virtual Interface ipchains -A input -i $FREESWANVI \ -s $ANYWHERE \ -d $ANYWHERE -j ACCEPT ipchains -A output -i $FREESWANVI \ -s $ANYWHERE \ -d $ANYWHERE -j ACCEPT # Forward anything from the FreeS/WAN virtual interface IPSEC tunnel ipchains -A forward -i $FREESWANVI \ -s $ANYWHERE \ -d $ANYWHERE -j ACCEPT |
您连接到互联网的外部接口。
表示任何地方 0.0.0.0/0。
远程 VPN 网关的空格分隔列表。
FreeS/Wan 虚拟接口的空格分隔列表。
: 有关更多信息,请参阅 网络防火墙。不要忘记在另一个网关中也添加/检查这些防火墙规则。
Therp_filter与 IP 欺骗保护相关的 rp_filter 子系统必须在两个网关上都关闭,IPSEC 才能正常工作。这通过检查值 0(关闭)是否在以下文件中设置来完成/proc/sys/net/ipv4/conf/ipsec0/rp_filter和/proc/sys/net/ipv4/conf/eth0/rp_filter文件中。
要检查值 0(关闭)是否在以下文件中设置rp_filter文件中,请使用以下命令
[root@deep] /# cat /proc/sys/net/ipv4/conf/ipsec0/rp_filter |
0 |
[root@deep] /# cat /proc/sys/net/ipv4/conf/eth0/rp_filter |
0 |
: 子目录ipsec0在我们的示例中,仅在系统重启后才会创建。因此,您可以在系统重启后检查rp_filter文件中ipsec0目录中的文件值。
要在两个rp_filter文件中手动设置值 0(关闭),请使用以下命令
[root@deep] /# echo 0 > /proc/sys/net/ipv4/conf/ipsec0/rp_filter [root@deep] /# echo 0 > /proc/sys/net/ipv4/conf/eth0/rp_filter |
: 您也可以将如下行放入您的防火墙脚本文件中/etc/rc.d/init.d/firewall在两个网关上自动将这些值设置为 0(关闭),并避免手动设置
# Disable IP spoofing protection to allow IPSEC to work properly echo 0 > /proc/sys/net/ipv4/conf/ipsec0/rp_filter echo 0 > /proc/sys/net/ipv4/conf/eth0/rp_filter
: 在上面的防火墙脚本文件示例中,我们假设eth0是您用于连接的接口。当然,如果您使用eth1您必须更改eth0为eth1,等等。
ipsec_setup: WARNING: ipsec0 has route filtering turned on, KLIPS may not work ipsec_setup: (/proc/sys/net/ipv4/conf/ipsec0/rp_filter = `1', should be 0) ipsec_setup: WARNING: eth0 has route filtering turned on, KLIPS may not work ipsec_setup: (/proc/sys/net/ipv4/conf/eth0/rp_filter = `1', should be 0) |
重要的是要注意,任何用于使用 IPSEC 的内部网络的伪装规则都必须在允许 IPSEC 相关流量的规则(上面的步骤 2 和 3)之后,否则机器将尝试伪装数据包,而不是将它们传递给 IPSEC。编辑firewall脚本文件,vi/etc/rc.d/init.d/firewall在两台网关机器上,添加/检查以下行,以允许伪装的数据包从远程网络网关穿越到您的网络网关,反之亦然
# Masquerade internal traffic. # All internal traffic is masqueraded externally. ipchains -A forward -i $EXTERNAL_INTERFACE -s $LOCALNET_1 -j MASQ |
您连接到互联网的外部接口。
无论您使用哪个私有范围。
: 有关更多信息,请参阅 具有伪装和转发支持的网络防火墙。
现在,您可以重启系统,Gateway A 上的机器应该能够与 Gateway B 上的机器正常通信。