在 Ubuntu 22.04 中继续使用 iptables
内容提要
今天进行 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。
延伸解读
切换到 iptables-legacy 的原因
在 Ubuntu 22.04 中,默认使用 iptables-nft,但由于其与 Fail2ban 的兼容性较差,许多用户选择切换回 iptables-legacy。iptables-legacy 提供了更简单的配置方式,适合对防火墙规则有基本需求的用户。
使用 iptables-persistent 的重要性
安装 iptables-persistent 工具后,可以确保在系统重启时自动加载防火墙规则。这对于维护服务器的安全性至关重要,避免因重启而导致的规则丢失,确保防火墙始终处于预期状态。
注意选择正确的版本
在切换 iptables 版本时,用户需谨慎选择。通过命令查看当前版本后,确保选择 iptables-legacy,以避免因错误配置导致的网络安全问题。了解各版本的特点,有助于做出更合适的选择。
延伸问答
如何在 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 以保存规则。