Linux下利用Firewall进行端口转发 |
发表者:admin分类:Devops2020-11-02 17:19:15 阅读[1140] |
本文介绍使用Firewall进行端口转发。
如果安装过iptables的机器,需要先停止,然后设置开机禁用:
[root@localhost ~]#servcie iptables stop --临时关闭防火墙 [root@localhost ~]#chkconfig iptables off --永久关闭防火墙
特别注意:请勿使用yum remove iptables来卸载防火墙,因为iptables附带了很多依赖文件,这样卸载会导致机器SSH丢失。
安装firewall防火墙
yum install firewalld -y
设置开机自启
systemctl enable --now firewalld
开启路由转发
echo 'net.ipv4.ip_forward = 1' >> /etc/sysctl.conf sysctl -p
开启防火墙的流量伪装功能
firewall-cmd --zone=public --permanent --add-masquerade
开启TCP流量转发
firewall-cmd --add-forward-port=port=8080:proto=tcp:toaddr=2.2.2.2:toport=666 --permanent #将本地8080端口,转发到2.2.2.2的tcp666端口。
开启UDP流量转发
firewall-cmd --add-forward-port=port=8080:proto=udp:toaddr=2.2.2.2:toport=666 --permanent #将本地8080端口,转发到2.2.2.2的udp666端口。
重载配置文件
firewall-cmd --reload
如何开放端口?
开启TCP流量端口
firewall-cmd --add-port=8080/tcp --permanent
开启UDP流量端口
firewall-cmd --add-port=8080/udp --permanent
注意:每次操作完成后,都需要对Firewall进行重载:
重载配置文件firewall-cmd --reload
转载请标明出处【Linux下利用Firewall进行端口转发】。
《www.micoder.cc》
虚拟化云计算,系统运维,安全技术服务.
Tags: | [阅读全文...] |
最新评论