本实验仅供参考,只提供基本的一些操作命令,希望可以帮助到大家解决防火墙服务的一些错误以及运维。
1、检查防火墙的状态
[root@localhost ~]# firewall-cmd --state
running
此命令将显示防火墙的当前状态,"runing"表示防火墙正在运行
2、查看防火墙区域
[root@localhost ~]# firewall-cmd --get-active-zones
public
interfaces: ens33
显示了当前激活的防火墙区域为 "public",并且指定了接口 "ens33"。这意味着防火墙当前将 "ens33" 接口划分到了 "public" 区域。在firewalld中,防火墙规则是基于区域来管理的,不同的区域可以有不同的安全策略。因此,接口 "ens33" 将会受到 "public" 区域的防火墙规则的影响。
3、查看特定区域的规则
[root@localhost ~]# firewall-cmd --zone=public --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: ens33
sources:
services: ssh dhcpv6-client
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
命令将列出指定区域(例如“public”)的所有规则,包括允许的服务、端口等信息。
4、添加服务
[root@localhost ~]# firewall-cmd --zone=public --add-service=ssh --permanent
Warning: ALREADY_ENABLED: ssh
success
5、移除服务
[root@localhost ~]# firewall-cmd --zone=public --remove-service=ssh --permanent
success
此命令用于向指定区域添加或移除特定服务(例如SSH),使用 --permanent
标志可使更改在系统重启后依然生效。
6、重新加载防火墙配置。每当对防火墙进行了更改后,需要通过重新加载配置来使更改生效
firewall-cmd --reload
7、重启/停止防火墙
systemctl restart firewalld #重启防火墙
systemctl stop firewalld #关闭防火墙
当然在我们的日常实验中直接关闭防火墙是可以实现的,避免防火墙导致的种种问题,但是如果不是在虚拟环境中,关闭防火墙就等于将服务器暴露在外,无法保证内部服务器的安全,所以希望大家可以对防火墙有一个基本的认识。