温馨提示×

怎么关闭Debian防火墙

小樊
40
2026-07-18 05:17:27
栏目: 智能运维

在 Debian 系统中,防火墙通常是通过 ufwiptables/nftables 来管理的。下面按常见情况说明如何关闭防火墙。


一、如果使用 ufw(最常见)

1. 查看 ufw 状态

sudo ufw status

2. 关闭 ufw 防火墙

sudo ufw disable

关闭后,规则不会立即删除,但防火墙不再生效。

3. 可选:彻底停止并禁止开机启动

sudo systemctl stop ufw
sudo systemctl disable ufw

二、如果使用 iptables(较老方式)

1. 查看当前规则

sudo iptables -L

2. 清空所有规则(临时关闭)

sudo iptables -F
sudo iptables -X
sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT

⚠️ 注意:重启后会恢复,除非保存规则。

3. 防止开机恢复规则

sudo apt remove iptables-persistent -y

三、如果使用 nftables(Debian 10+ 默认)

1. 查看状态

sudo systemctl status nftables

2. 停止并禁用 nftables

sudo systemctl stop nftables
sudo systemctl disable nftables

3. 清空规则(可选)

sudo nft flush ruleset

四、确认防火墙是否已关闭

sudo iptables -L
sudo nft list ruleset

如果看到几乎为空或全是 ACCEPT,说明防火墙已关闭。


五、重要提醒 ⚠️

  • 生产服务器不建议完全关闭防火墙
  • 更安全的方式是:
    • 只开放需要的端口
    • 或临时关闭测试后再恢复

如果你愿意,可以告诉我:

  • Debian 版本(cat /etc/debian_version
  • 用的是云服务器还是本地机器
    我可以给你更精确、安全的操作方案。

0