firewalld实现网关功能

用ip a查看自己的路由服务器接口,一个外网接口 wan ,还有内网接口:

我这里是一块网卡,配了一个虚拟ip,eth0: wan口   eth0:1 lan口

注意:要注意顺序,先将接口加到zones,然后再配置snat

配置:

firewall-cmd --permanent --direct --passthrough ipv4 -I FORWARD -i eth0:1 -j ACCEPT(实现网关功能,这条可以不要)

firewall-cmd --change-interface=eth0 --zone=external --permanent

firewall-cmd --change-interface=eth0:1 --zone=internal --permanent

 

配置nat转发:

firewall-cmd --permanent  --direct --passthrough ipv4 -t nat -I POSTROUTING -o eth0 -j SNAT -s 10.0.67.0/24 --to 外网ip

 

配置允许dns,不然dns解析不了

firewall-cmd --zone=internal --add-service=dns --permanent

vim /etc/sysctl.conf

net.ipv4.ip_forward=1
systcl -p
firewall-cmd --reload

然后内网机器配置好网关:网关ip为这台网关的lan口ip

 

这里将网卡接口设为内外区域,interal区域是可信的,只有external区域需要修改,所以这里设置转发规则:将访问879端口的转发到内网机器的10.0.67.151的873端口。

firewall-cmd --add-forward-port=port=879:proto=tcp:toaddr=10.0.67.151:toport=873 --zone=external

 

端口映射,将内网端口映射到外网:

firewall-cmd --add-forward-port=port=80:proto=tcp:toport=8080   # 将80端口的流量转发至8080
firewall-cmd --add-forward-port=proto=80:proto=tcp:toaddr=192.168.1.0.1 # 将80端口的流量转发至192.168.0.1
firewall-cmd --add-forward-port=proto=80:proto=tcp:toaddr=192.168.0.1:toport=8080 # 将80端口的流量转发至192.168.0.1的8080端口

 

可以加端口
firewall-cmd --add-forward-port=port=874:interface=eth1:proto=tcp:toaddr=10.0.62.185:toport=873 --zone=external

 






 

posted @ 2017-11-07 09:59  行知散人  阅读(879)  评论(0编辑  收藏  举报