21.2. 将 iptables 和 ip6tables 规则集转换为 nftables


使用 iptables-restore-translateip6tables-restore-translate 实用程序将 iptablesip6tables 规则集转换为 nftables

先决条件

  • 已安装 nftablesiptables 软件包。
  • 系统配置了 iptablesip6tables 规则。

流程

  1. iptablesip6tables 规则写入一个文件:

    # iptables-save >/root/iptables.dump
    # ip6tables-save >/root/ip6tables.dump
    Copy to Clipboard Toggle word wrap
  2. 将转储文件转换为 nftables 指令:

    # iptables-restore-translate -f /root/iptables.dump > /etc/nftables/ruleset-migrated-from-iptables.nft
    # ip6tables-restore-translate -f /root/ip6tables.dump > /etc/nftables/ruleset-migrated-from-ip6tables.nft
    Copy to Clipboard Toggle word wrap
  3. 检查,如果需要,手动更新生成的 nftables 规则。
  4. 要启用 nftables 服务来加载生成的文件,请在 /etc/sysconfig/nftables.conf 文件中添加以下内容:

    include "/etc/nftables/ruleset-migrated-from-iptables.nft"
    include "/etc/nftables/ruleset-migrated-from-ip6tables.nft"
    Copy to Clipboard Toggle word wrap
  5. 停止并禁用 iptables 服务:

    # systemctl disable --now iptables
    Copy to Clipboard Toggle word wrap

    如果您使用自定义脚本加载 iptables 规则,请确保脚本不再自动启动并重新引导以刷新所有表。

  6. 启用并启动 nftables 服务:

    # systemctl enable --now nftables
    Copy to Clipboard Toggle word wrap

验证

  • 显示 nftables 规则集:

    # nft list ruleset
    Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat