腾讯云服务器在防火墙上添加可访问端口(CentOS7)

centos7版本对防火墙进行加强,不再使用原来的iptables,启用firewalld,如果低于CentOS7版本,需要使用iptables。

该开放端口以8080为例。

1.查看防火墙状态。

firewall-cmd --state  #查看防火墙状态。

得到结果是running或者not running

 如果没开启(not running)

systemctl start firewalld 

2.在running 状态下,向firewall 添加需要开放的端口

firewall-cmd --permanent --zone=public --add-port=8080/tcp  #永久的添加该端口。去掉--permanent则表示临时。

与之对应关闭的命令为

firewall-cmd --zone=public --remove-port=8080/tcp --permanent

3.加载配置,使得修改有效。

firewall-cmd --reload  

使用命令 查看开启的端口,出现8080/tcp这开启正确

firewall-cmd --permanent --zone=public --list-ports

别忘了关键一步 再次启动防火墙

systemctl start firewalld.service 

再查看端口8080就开放了。

 

posted @ 2021-12-17 08:51  莴苣&  阅读(360)  评论(0编辑  收藏  举报