Firewalld 防火牆 nat 上網配置
firewall-cmd實現:
1、啟用IP轉發
vim /etc/sysctl.conf net.ipv4.ip_forward = 1
sysctl -p #命令生效
2、修改網卡的zone
firewall-cmd --permanent --zone=external --change-interface=eth0 firewall-cmd --permanent --zone=internal --change-interface=eth1
3、設置IP地址偽裝
firewall-cmd --zone=external --add-masquerade --permanent
4、設置NAT規則
firewall-cmd --permanent --direct --passthrough ipv4 -t nat POSTROUTING -o eth0 -j MASQUERADE -s 192.168.100.0/24
5、重載Firewall使配置生效
firewall-cmd --reload
6、端口映射
firewall-cmd --zone=external --add-forward-port=port=1122:proto=tcp:toport=22:toaddr=192.168.100.3 --permanent
firewall-cmd --reload
7、驗證:
root@aiker:/mnt/c/Users/aikera# ssh -p 1122 root@192.168.0.173 root@192.168.0.173's password: #輸入192.168.100.3的密碼 [root@aiker03 ~]#