在 Ubuntu 22.04 中继续使用 iptables

💡 原文中文,约1100字,阅读约需3分钟。
📝

内容提要

今天进行 do-release-upgrade,将 iptables-nft 切换回 iptables-legacy,以提高兼容性和易用性。可通过命令查看和选择 iptables 版本,并安装 iptables-persistent 保存规则。

🎯

关键要点

  • 今天进行 do-release-upgrade,切换 iptables-nft 到 iptables-legacy。
  • 选择 iptables-legacy 是为了提高兼容性和易用性,特别是与 Fail2ban 的兼容性。
  • Ubuntu 22.04 默认使用 iptables-nft,若需使用传统 iptables,可切换到 iptables-legacy。
  • 使用命令查看当前 iptables 版本:sudo update-alternatives --config iptables。
  • 在命令输出中选择 iptables-legacy 的编号并按回车确认。
  • 安装 iptables-persistent 工具以保存 iptables 规则:sudo apt install iptables-persistent。
  • 安装过程中选择保存当前 iptables 规则,并确保系统启动时加载这些规则:sudo systemctl enable netfilter-persistent。

延伸问答

如何在 Ubuntu 22.04 中切换到 iptables-legacy?

可以通过命令 sudo update-alternatives --config iptables 查看当前 iptables 版本,并选择 iptables-legacy 的编号确认切换。

为什么选择使用 iptables-legacy 而不是 iptables-nft?

选择 iptables-legacy 是为了提高兼容性和易用性,特别是与 Fail2ban 的兼容性。

如何保存 iptables 规则以便系统重启后加载?

需要安装 iptables-persistent 工具,并在安装过程中选择保存当前的 iptables 规则,确保系统启动时加载这些规则。

Ubuntu 22.04 默认使用哪种 iptables 版本?

Ubuntu 22.04 默认使用 iptables-nft,这是基于 nftables 的工具。

如何查看当前的 iptables 版本?

可以使用命令 sudo update-alternatives --config iptables 来查看当前的 iptables 版本。

在切换 iptables 版本时需要注意什么?

在切换时要确保选择正确的编号,并在需要时安装 iptables-persistent 以保存规则。

➡️

继续阅读