Centos7.x[firewall]防火墙常用、实用命令操作

2024-11-05 13:20:41

习铲邑诱匮惯实用Centos系统的用户,有一部分之前一直习惯centos5.x 6.x的iptables防火墙,一旦换到centos7.x上进行操作的时候就麻爪了。firewall防火墙在安全性上要比足毂忍珩iptables防火墙好一点。今天给大家带来一些Centos7firewall的实用、常用的命令

第一条:查看 firewall 防火墙状态,可使用一下命令查看

1、[root@localhost ~]# firewall-cmd --state或[root@localhost ~]# systemctl status firewalld.service反馈结果如下

2、运行状态

Centos7.x[firewall]防火墙常用、实用命令操作

3、不运行状态

Centos7.x[firewall]防火墙常用、实用命令操作

第二条:查看完防火墙状态后,可以选择运行或关闭,可使用一下命令

1、启动:[root@localhost ~]# systemctl start firewalld停止:[root@localhost ~]# system艘早祓胂ctl stop firewalld重启:[root@localhost ~]#systemctl restart firewalld或启动:[root@localhost ~]# systemctl start firewalld.service关闭:[root@localhost ~]# systemctl stop firewalld.service重启:[root@localhost ~]# systemctl restart firewalld.service

2、以上命令输入后无反馈,不做图片演示。执行后可用第一条教程中的命令查看

第三条:开机启用或禁用防火墙

1、启用:[root@localhost ~]# systemctl enable firewalld.service禁用:[root@localhost ~]# systemctl disable firewalld.service

Centos7.x[firewall]防火墙常用、实用命令操作

2、或启用:[root@localhost ~]# systemctl enable firewalld禁用:[root@localhost ~]# systemctl disable firewalld

Centos7.x[firewall]防火墙常用、实用命令操作

3、查看是否开机启动[root@localhost ~]#systemctl is-enabled firewalld.serviceenable为启用disable为禁用

Centos7.x[firewall]防火墙常用、实用命令操作Centos7.x[firewall]防火墙常用、实用命令操作

第四条:防火墙 添加/删除/查看 服务的命令

1、查看已添加的服务[root@localhost ~]#firewall-cmd --list-services

Centos7.x[firewall]防火墙常用、实用命令操作

2、添加服务[root@localhost ~]# fire嘛术铹砾wall-cmd --add-service=http防火墙放行服务时,会自动放行服务所吹涡皋陕用到的默认的端口如:添加http服务,等同于开放80端口如:添加https服务,等同于开放443端口其他服务相同,会自动添加默认端口

Centos7.x[firewall]防火墙常用、实用命令操作

3、删除服务[root@localhost ~]#firewall-cmd --remove-service=http

Centos7.x[firewall]防火墙常用、实用命令操作

第五条:防火墙 添加/删除/查看 端口的命令

1、查看开启了哪些端口 [root@localhost ~]#firewall-cmd --zone=public --list-ports防火墙放行服务时,自动放行的默认服务端口。如SSH服务,默认使用22,放行SSH服务时相当于放行了22端口所以在查看端口里并不显示

Centos7.x[firewall]防火墙常用、实用命令操作

2、添加一个端口到防火墙[root@localhost ~]# firewall-cmd --zone=public --add-port=80/tcp --permanentpermanent是永久生效的意思,部署的话,重启机器之后,添加的端口会自动删除

Centos7.x[firewall]防火墙常用、实用命令操作

3、删除一个防火墙端口[root@localhost ~]#firewall-cmd --zone=public --remove-port=80/tcp --permanent

Centos7.x[firewall]防火墙常用、实用命令操作

第六条:第四、五条命令执行后,需要输入 重载/更新防火墙 命令

1、[root@localhost ~]# firewall-cmd --reload更新反馈值:success(成功),添加或删除的规则就会立刻生效

Centos7.x[firewall]防火墙常用、实用命令操作
猜你喜欢