一、查看防火墙状态

查看防火墙状态:systemctl status firewalld

开启防火墙:systemctl start firewalld

关闭防火墙:systemctl stop firewalld

若遇到无法开启

先用:systemctl unmask firewalld.service

然后:systemctl start firewalld.service

二、查看对外开放的端口状态

查询已开放的端口列表:firewall-cmd --zone=public --list-ports

查询指定端口是否开放:netstat -apn | grep  80 端口号

查询指定端口是否已开:firewall-cmd --query-port=666/tcp

提示 yes,表示开启;no表示未开启。

当服务器未安装 netstat 工具时,查看端口监听状态会提示如下报错 “command not found”。

[root@VM_0_15_linux ~]# netstat -an|grep 9200
-bash: netstat: command not found

执行 yum install net-tools 安装命令

三、对外开放端口

查看想开的端口是否已开:firewall-cmd --query-port=80/tcp

返回 no  是没有开启,yes  是开启。

添加指定需要开放的端口:firewall-cmd --add-port=80/tcp --permanent

重载入添加的端口:firewall-cmd --reload

查询指定端口是否开启成功:firewall-cmd --query-port=80/tcp

移除指定端口:firewall-cmd --permanent --remove-port=123/tcp
 

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐