SERVER:
echo 'net.ipv4.ip_forward = 1' >> /etc/sysctl.conf
sysctl -p
yum install iptables-services iptables -y
iptables -t nat -A POSTROUTING -s 10.9.0.0/16 -o eth0 -j MASQUERADE
执行这一步之前应该是编辑好了"/etc/sysconfig/iptables"配置文件删除默认规则
service iptables save
systemctl enable iptables
systemctl start iptables
SERVER B:
route del default && route add default gw {SERVER IP_ADDRESS}
sed -i 's:GATEWAY=10.9.0.1:GATEWAY={SERVER IP_ADDRESS}:g' /etc/sysconfig/network-scripts/ifcfg-eth0
PS:
因为iptables-save命令保存后并不会更新 /etc/sysconfig/iptables 配置管理文件,这个文件是依赖 iptables-services 软件包生成。所以还是用service命令来管理比较稳妥。
删除 “/etc/sysconfig/iptables” 配置文件中默认的规则,否则执行systemd管理命令会加载一些默认规则,造成意外。
同时还要注意删除iptables软件会将一些关联的其他软件包也删除,可以停用iptables服务,但小心谨慎删除iptables软件包。
PSPS:
截图并没有在前面附上,应该能看懂的~~
此图为安装好iptables-services包之后,里面含有的默认规则

贴上此图是要说明卸载iptbales包会将一些其关联的软件包一并删除,谨慎操作

此图为保存规则并显示具体的保存内容

此图为请大家自己来理解吧。呵呵

网友评论