Alibaba Cloud Linux 3.2104 LTS 64位 iptables?

Alibaba Cloud Linux 3.2104 LTS 64位 系统中,iptables 的使用取决于系统默认的防火墙管理工具。虽然 iptables 仍然可用,但 Alibaba Cloud Linux(基于 RHEL/CentOS)通常默认使用 firewalldnftables 作为其主要的防火墙管理系统。


✅ 是否支持 iptables?

是的,iptables 是支持的,但需要注意:

  • Alibaba Cloud Linux 3 默认使用 nftables 框架(iptables 命令可能只是对 nftables 的兼容层)。
  • iptables-services 包需要手动安装才能启用传统的 iptables 服务。
  • 推荐使用 firewalld 或直接使用 nftables 命令进行管理。

🔧 安装和配置 iptables

1. 安装 iptablesiptables-services

sudo yum install -y iptables iptables-services

如果提示找不到包,请确认你已启用正确的软件源。


2. 启动并启用 iptables 服务

sudo systemctl start iptables
sudo systemctl enable iptables

3. 查看当前规则

sudo iptables -L -n -v

4. 添加规则示例(开放端口)

例如:开放 SSH(22)端口

sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT

保存规则:

sudo service iptables save
# 或者
sudo iptables-save > /etc/sysconfig/iptables

5. 设置开机启动

确保 iptables 开机自启:

sudo systemctl enable iptables

🔄 使用 firewalld 替代方案(推荐)

如果你不一定要用传统 iptables,建议使用更现代的 firewalld

sudo yum install -y firewalld
sudo systemctl start firewalld
sudo systemctl enable firewalld

# 示例:开放端口 80
sudo firewall-cmd --permanent --add-port=80/tcp
sudo firewall-cmd --reload

📌 注意事项

  • Alibaba Cloud ECS 实例的安全组(Security Group)已经提供了一层网络防火墙功能。
  • 在实例内部再配置 iptablesfirewalld 是第二层保护,应确保两者之间规则不会冲突。
  • 若你仅通过阿里云控制台或 API 管理安全组,可以不需要在系统内再设置复杂防火墙规则。

❓如何判断当前使用的是 nftables 还是 legacy iptables?

运行:

iptables --version

输出如果是:

iptables v1.8.x (nf_tables)

表示你使用的是 nftables 后端。


如需切换回传统 iptables 模式(不推荐),可以修改配置文件 /etc/modprobe.d/nf_conntrack.conf 或禁用 nftables


📚 参考链接

  • Alibaba Cloud Linux 官方文档
  • Red Hat iptables to nftables 迁移指南

如需进一步帮助(如配置具体规则、关闭 firewalld 使用 iptables),请告诉我你的需求场景,我可以提供详细命令。