插件窝 干货文章 linux关闭firewalld的方法是什么

linux关闭firewalld的方法是什么

firewalld 防火墙 iptables sudo 490    来源:    2025-05-15

在 Linux 系统中关闭 firewalld(默认防火墙服务,常见于 RHEL/CentOS/Fedora 等发行版)的方法如下:


1. 临时停止 firewalld 服务

sudo systemctl stop firewalld
  • 效果:立即停止防火墙,但 重启系统后会自动恢复

2. 永久禁用 firewalld(重启后仍关闭)

sudo systemctl disable firewalld
  • 效果:禁止防火墙开机自启,需配合 stop 命令立即生效。

3. 确认 firewalld 状态

sudo systemctl status firewalld
  • 检查是否显示 inactive (dead)disabled 表示已关闭。

4. 可选:安装/切换至 iptables(如需替代方案)

# 安装 iptables 服务
sudo yum install iptables-services -y  # RHEL/CentOS
sudo dnf install iptables-services -y  # Fedora

# 启用 iptables
sudo systemctl enable --now iptables

注意事项

  • 谨慎操作:关闭防火墙可能导致系统暴露于网络攻击,建议仅在测试环境或确保有其他安全措施(如云平台安全组)时使用。
  • 恢复防火墙:若需重新启用,执行: bash sudo systemctl enable --now firewalld

常见问题

  • 报错 "Unit not found":可能系统未安装 firewalld,通过 sudo yum install firewalld 安装后再操作。
  • SELinux 影响:关闭防火墙后,仍需检查 SELinux 状态(getenforce),确保其配置符合需求。

如有其他需求,请补充说明具体场景!