温馨提示×

centos防火墙怎么重启

小樊
36
2026-07-20 02:17:04
栏目: 智能运维

CentOS 上重启防火墙,取决于你使用的 CentOS 版本和防火墙服务(firewalldiptables)。下面分别说明。


一、CentOS 7 / 8 / Stream(默认使用 firewalld

1️⃣ 重启 firewalld 防火墙

sudo systemctl restart firewalld

2️⃣ 查看 firewalld 状态

sudo systemctl status firewalld

3️⃣ 停止 / 启动 / 开机自启

sudo systemctl stop firewalld      # 停止
sudo systemctl start firewalld     # 启动
sudo systemctl enable firewalld    # 开机自启
sudo systemctl disable firewalld   # 关闭开机自启

二、CentOS 6 或更早版本(使用 iptables

1️⃣ 重启 iptables

sudo service iptables restart

2️⃣ 查看状态

sudo service iptables status

3️⃣ 停止 / 启动

sudo service iptables stop
sudo service iptables start

三、确认当前系统使用的是哪种防火墙

systemctl status firewalld
  • ✅ 显示 active (running) → 使用的是 firewalld
  • ❌ 显示 inactivenot found → 可能使用的是 iptables

四、常见注意事项

⚠️ 重启防火墙会短暂中断网络连接
特别是远程 SSH 连接时,请确保规则正确,避免被锁在外面。

✅ 建议操作前先查看规则:

sudo firewall-cmd --list-all

如果你愿意,可以告诉我:

  • CentOS 具体版本(如 7.9、8 Stream)
  • 云服务器 还是 本地服务器
  • 是否有 SSH / 端口访问问题

我可以给你更精确的操作建议。

0