温馨提示×

linux防火墙如何升级

小樊
43
2026-10-16 00:47:20
栏目: 智能运维

在 Linux 中,“防火墙升级”通常有两种理解:

  1. 升级防火墙软件本身(如 iptables、nftables、firewalld、ufw)
  2. 更新防火墙规则 / 策略(不是升级软件)

下面分别说明。


一、升级防火墙软件(系统包升级)

1. 使用 firewalld(CentOS / RHEL / Rocky / Alma)

# CentOS/RHEL 7/8/9
sudo yum update firewalld
# 或
sudo dnf update firewalld

重启服务:

sudo systemctl restart firewalld

查看版本:

firewall-cmd --version

2. 使用 ufw(Ubuntu / Debian)

sudo apt update
sudo apt upgrade ufw

查看版本:

ufw version

3. 使用 iptables / nftables

# Debian / Ubuntu
sudo apt update
sudo apt upgrade iptables nftables

# CentOS / RHEL
sudo yum update iptables nftables

查看版本:

iptables --version
nft --version

二、从 iptables 升级到 nftables(架构升级)

现代 Linux 推荐使用 nftables 替代 iptables。

检查是否支持 nftables

lsmod | grep nf_tables

安装 nftables

# Debian / Ubuntu
sudo apt install nftables

# CentOS / RHEL 8+
sudo dnf install nftables

启用 nftables

sudo systemctl enable --now nftables

三、升级防火墙规则(常见操作)

firewalld 示例

# 开放端口
sudo firewall-cmd --add-port=8080/tcp --permanent
sudo firewall-cmd --reload

ufw 示例

sudo ufw allow 8080/tcp
sudo ufw reload

四、注意事项(很重要)

  • ✅ 升级前备份规则
    iptables-save > iptables.bak
    nft list ruleset > nft.bak
    
  • ✅ 远程服务器谨慎操作,避免断网
  • ✅ 升级后确认防火墙仍在运行

如果你能告诉我:

  • 使用的 Linux 发行版
  • 用的是 firewalld / ufw / iptables / nftables
  • 是“软件升级”还是“规则更新”

我可以给你更精确的命令。

0 踩