启用 iptables 防火墙¶
先决条件¶
- 迫切希望禁用默认的 firewalld 应用程序,并启用 iptables。
此过程已弃用
截至 Rocky Linux 9.0,iptables
及其所有相关实用程序均已弃用。这意味着该操作系统未来的版本将删除 iptables
。因此,强烈建议您不要使用此过程。如果您熟悉 iptables,我们建议使用 《iptables 到 firewalld 的指南》。如果您是防火墙概念的新手,那么我们推荐《面向初学者的 firewalld》。
简介¶
firewalld 现在是 Rocky Linux 上的默认防火墙。firewalld 曾经仅仅是通过 XML 文件动态应用 iptables,这些文件会在 CentOS 7/RHEL 7 中加载更改而不刷新规则。在 CentOS 8/RHEL 8/Rocky 8 中,firewalld 现在是 nftables 的包装器。但是,如果您愿意,仍然可以安装并使用纯 iptables。要安装并运行纯 iptables 而不使用 firewalld,您可以按照本指南进行操作。本指南不会告诉您如何编写 iptables 规则。假定如果您想摆脱 firewalld,您必须已经知道如何为 iptables 编写规则。
禁用 firewalld¶
您实际上无法在 firewalld 旁边运行旧的 iptables 实用程序。它们不兼容。解决此问题的最佳方法是完全禁用 firewalld(如果您愿意,无需卸载它),然后重新安装 iptables 实用程序。可以使用以下命令禁用 firewalld:
停止 firewalld
systemctl stop firewalld
禁用 firewalld,使其在启动时不会启动
systemctl disable firewalld
屏蔽该服务,使其无法找到
systemctl mask firewalld
安装并启用 iptables 服务¶
接下来,我们需要安装旧的 iptables 服务和实用程序。使用以下命令完成此操作:
dnf install iptables-services iptables-utils
这将安装运行纯 iptables 规则集所需的所有内容。
现在我们需要启用 iptables 服务,以确保它在启动时启动
systemctl enable iptables
结论¶
如果您更喜欢使用纯 iptables 而不是 firewalld,您可以继续使用它。您可以通过简单地撤销这些更改来恢复使用默认的 firewalld。
作者:Steven Spencer
贡献者:Ezequiel Bruni, Ganna Zhyrnova