温馨提示×

centos minimal如何关防火墙

小樊
57
2026-09-14 21:56:42
栏目: 智能运维

在 CentOS Minimal(最小化安装)里,默认使用的是 firewalld(CentOS 7/8/Stream 通用)。下面是常用操作方式:


一、临时关闭防火墙(重启后恢复)

systemctl stop firewalld

二、永久关闭防火墙(开机不启动)

systemctl disable firewalld

如果只想开机不启动但当前不关,可只执行上面这条。


三、彻底关闭(停止 + 禁止启动)

systemctl stop firewalld
systemctl disable firewalld

四、查看防火墙状态

systemctl status firewalld

或

firewall-cmd --state

五、如果你用的是 iptables(少见)

有些老版本或自定义系统可能用 iptables:

systemctl stop iptables
systemctl disable iptables

六、CentOS 6(非常老,仅供参考)

service iptables stop
chkconfig iptables off

✅ 建议:

  • 生产环境不建议直接关防火墙
  • 可用 firewall-cmd 开放端口,例如:
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload

如果你说明 CentOS 版本(6 / 7 / 8 / Stream) 和 使用场景(测试 / 生产),我可以给你更合适的建议。

0 踩