CentOS 防火墙启动失败,常见原因和排查思路如下(以 firewalld 为主,也顺带提 iptables):
CentOS 7+ 默认是 firewalld
CentOS 6 及以前常用 iptables
systemctl status firewalld
# 或
systemctl status iptables
rpm -q firewalld
如果没有:
yum install firewalld -y
查看日志:
tail -f /var/log/messages
# 或
ausearch -m AVC -ts recent
临时关闭测试:
setenforce 0
systemctl start firewalld
若可启动,说明是 SELinux 策略问题。
iptables 与 firewalld 冲突
systemctl stop iptables
systemctl disable iptables
systemctl start firewalld
ls /etc/firewalld/
尝试重置:
mv /etc/firewalld /etc/firewalld.bak
systemctl start firewalld
错误类似:
Failed to connect to D-Bus
解决:
yum install dbus -y
systemctl start dbus
df -h
free -m
systemctl start firewalld
journalctl -xe
或
firewall-cmd --state
| 报错 | 原因 |
|---|---|
Unit not found |
未安装 |
Address already in use |
端口冲突 |
Failed to start |
配置错误 |
Permission denied |
SELinux / 权限 |
systemctl stop iptables
systemctl disable iptables
yum reinstall firewalld -y
systemctl enable firewalld
systemctl start firewalld
如果你愿意,可以把 具体报错信息 或 journalctl -xe 的输出贴出来,我可以精准帮你定位原因。