禁用firewalld,启用iptables

1. 停止并禁用firewalld

systemctl stop firewalld
systemctl disable firewalld

2. 安装iptables服务(保证重启自动加载)

yum install -y iptables-services

3. 启用iptables

systemctl enable iptables
systemctl start iptables

4. 写入你的规则

iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT

… 其他规则

5. 保存规则(防重启丢失)

service iptables save

iptables-save > /etc/sysconfig/iptables

为什么要禁firewalld?(5个硬理由)

理由说明严重程度
1. Docker/K8s 冲突firewalld 启动会清掉 Docker 加的 iptables 规则,容器网络必断🔴 致命
2. 运维脚本兼容10年积累的 iptables 脚本,没人重写成 firewall-cmd🔴 成本高
3. NAT/复杂策略firewalld 的 rich-rule 写 DNAT/SNAT 反人类🟡 麻烦
4. 多一层抽象firewalld 自己还有一套规则,最终转成 iptables,出问题难排查🟡 复杂
5. 性能损耗多一层服务调用,虽然不大,但能省则省🟢 轻微

四、哪些场景会留firewalld?

场景是否禁用原因
容器宿主机✅ 必禁Docker 冲突,没商量
物理机/VM(传统应用)✅ 推荐禁脚本管理方便
公有云默认镜像⚠️ 看情况阿里云/CentOS 默认开,懒得动就不动
桌面/开发机❌ 可留图形化方便
UbuntuUbuntu 默认 ufw,不是 firewalld

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注