伪装多个内部网络相当简单。您首先需要确保所有网络(包括内部和外部网络)都运行正常。然后,您需要启用流量以传递到其他内部接口,并被伪装到互联网。
接下来,您需要在内部接口上启用伪装。此示例总共使用三个接口:EXTIF 代表 eth0 接口,它是到互联网的外部连接。INTIF 代表 eth1 接口,它是 192.168.0.0 网络。最后,INTIF2 代表 eth2 接口,它是 192.168.1.0 网络。INTIF 和 INTIF2 都将通过 eth0 或 EXTIF 接口进行伪装。在您的 rc.firewall-* 规则集中,在现有 MASQ 规则集的末尾,添加以下内容
# 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 |
# 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 |
# 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 是互联网连接,因此为每个内部接口都列出了它。