firewall-cmd設置NAT轉換

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章