在 CentOS 上重启防火墙,取决于你使用的 CentOS 版本和防火墙服务(firewalld 或 iptables)。下面分别说明。
sudo systemctl restart firewalld
sudo systemctl status firewalld
sudo systemctl stop firewalld # 停止
sudo systemctl start firewalld # 启动
sudo systemctl enable firewalld # 开机自启
sudo systemctl disable firewalld # 关闭开机自启
sudo service iptables restart
sudo service iptables status
sudo service iptables stop
sudo service iptables start
systemctl status firewalld
active (running) → 使用的是 firewalldinactive 或 not found → 可能使用的是 iptables⚠️ 重启防火墙会短暂中断网络连接
特别是远程 SSH 连接时,请确保规则正确,避免被锁在外面。
✅ 建议操作前先查看规则:
sudo firewall-cmd --list-all
如果你愿意,可以告诉我:
我可以给你更精确的操作建议。