1、啓用IP轉發
vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
sysctl -p #命令生效
2、修改網卡的zone
firewall-cmd --permanent --zone=external --change-interface=ens33(出口網卡)
3、設置IP地址僞裝
firewall-cmd --zone=external --add-masquerade --permanent
firewall-cmd --permanent --zone=external --add-rich-rule=‘rule family=ipv4 source address=192.168.2.0/24 masquerade’ 將source爲192.168.2.0網段來的數據包僞裝成external(即ens33)的地址
4、重載Firewall使配置生效
firewall-cmd --reload
5、端口映射
firewall-cmd --zone=external --add-forward-port=port=1122:proto=tcp:toport=22:toaddr=192.168.100.3 --permanent
firewall-cmd --reload
注:或者設置NAT規則也可實現
firewall-cmd --permanent --direct --passthrough ipv4 -t nat -A POSTROUTING -s 192.168.0.0/24 -j SNAT --to-source 192.168.1.10