linux 防火墙

前言

  • centos7已经开始使用firewall作为防火墙,而不是iptables
  • systemctl是CentOS7的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体

查看防火墙的状态

第一种:

显示的比较简单,只显示是否开启

firewall-cmd --state

第二种:

显示的比较详细,显示开启时间等信息

systemctl status firewalld

开启防火墙

systemctl start firewalld

systemctl start firewalld.service

关闭防火墙

systemctl stop firewalld

重启防火墙

systemctl restart firewalld

开启指定端口

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

解释命令:

--zone=public:表示作用域为公共的;

--add-port=8080/tcp:添加tcp协议的端口8080;

--permanent:永久生效,如果没有此参数,则只能维持当前服务生命周期内,重新启动后失效;

移除指定端口

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

重新载入配置

firewall-cmd --reload

查看指定端口

firewall-cmd --zone= public --query-port=8080/tcp
firewall-cmd --query-port=8080/tcp

有版本提示public错误,删了public部分再执行

查看所有端口

第一种:

firewall-cmd --list-ports

第二种.:

firewall-cmd --list-all

第三种:

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

关闭开机启动

systemctl disable firewalld

开启开机启动 

systemctl enable firewalld

查看是否开机启动

systemctl is-enabled firewalld.service

禁用就是关闭开机启动,停止只是关闭程序

查看已启动的服务列表:

systemctl list-unit-files|grep enabled

查看启动失败的服务列表:

systemctl --failed

查看版本

firewall-cmd --version

参考:

https://developer.aliyun.com/article/353077

posted @ 2023-02-14 15:04  精神病人王大夫  阅读(73)  评论(0)    收藏  举报