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 @   精神病人王大夫  阅读(66)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示