打赏

centos7 查看、打开和关闭防火墙,查询及开放防火墙端口

使用centos7会发现,用centos6以前的方式查看、打开和关闭防火墙都无效了。这是因为centos7的防火墙改用firewalld,而不再使用iptables

查看centos7的防火墙的状态,查看的命令为

sudo systemctl status firewalld

查看后,看到active(running)就意味着防火墙打开了

关闭防火墙,命令为:

sudo systemctl stop firewalld

关闭后查看是否关闭成功,如果看到inactive(dead)就意味着防火墙关闭了。

打开防火墙的命令为:

sudo systemctl start firewalld

上面打开和关闭防火墙都是临时的,重启电脑后又会恢复到默认的状态(我的默认状态是打开)

如果是想重启后防火墙还是处于关闭的状态,得使用命令:

sudo systemctl disable firewalld

输入上一步的命令后,关闭防火墙,然后重启

重启后再次查看防火墙状态,这时防火墙就是处于关闭状态了

參考:https://jingyan.baidu.com/article/49ad8bce97bd965834d8fa8b.html

 

添加端口,或查詢端口是否開放

添加端口【3690】

firewall-cmd --permanent --add-port=3690/tcp

或:

firewall-cmd --permanent --zone=public --add-port=3690/tcp

返回success为成功

命令含义: 

--zone #作用域 

--add-port=80/tcp #添加端口,格式为:端口/通讯协议 

--permanent #永久生效

 

查詢端口【3690】是否开放

firewall-cmd --permanent --query-port=3690/tcp

解决CentOS7关闭/开启防火墙出现Unit iptables.service failed to load: No such file or directory.

參考:https://www.jianshu.com/p/739d6ab203c8

 

posted on 2019-03-07 18:13  头大的冯冯  阅读(451)  评论(0编辑  收藏  举报

导航