41.5. 防火墙直接规则
firewalld
服务提供多种配置规则的方法,包括:
- 常规规则
- 直接规则
这两者的一个区别在于,每个方法与底层后端(iptables
或 nftables
)交互的方式。
直接规则是高级低级别规则,允许直接与 iptables
交互。它们绕过 firewalld
的结构化管理,为您提供更多控制。您可以使用原始 iptables
语法使用 firewall-cmd
命令手动定义直接规则。例如,firewall-cmd --direct --add-rule ipv4 filter INPUT 0 -s 198.51.100.1 -j DROP
。此命令添加了一个 iptables
规则来丢弃来自 198.51.100.1 源 IP 地址的流量。
但是,使用直接规则也具有其缺点。特别是当 nftables
是您的主要防火墙后端时。例如:
-
直接规则很难维护,并可能会与基于
nftables
的firewalld
配置冲突。 -
直接规则不支持您可以在
nftables
中找到的高级功能,如原始表达式和有状态对象。 -
直接规则不永不。
iptables
组件已弃用,最终将从 RHEL 中删除。
因此,您可以考虑使用 nftables
替换 firewalld
直接规则。查看知识库解决方案 如何将 firewalld 直接规则替换为 nftables? 以查看更多详情。