温馨提示×

debian防火墙怎么关闭服务

小樊
59
2026-09-20 16:00:20
栏目: 智能运维

在 Debian 里“防火墙”和“服务”通常分两层来看:

  • 防火墙本身(如 ufw / nftables / iptables)
  • 被防火墙管控的网络服务(如 ssh、http 等)

下面按常见情况说。


一、关闭 Debian 防火墙

1️⃣ 如果使用 ufw(最常见)

查看状态:

sudo ufw status

关闭防火墙:

sudo ufw disable

开启(如需):

sudo ufw enable

2️⃣ 如果使用 nftables

查看状态:

sudo systemctl status nftables

停止并禁用:

sudo systemctl stop nftables
sudo systemctl disable nftables

3️⃣ 如果使用 iptables(未使用 ufw/nftables)

清空规则:

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

⚠️ 重启后可能恢复,建议配合 ufw 或 nftables 管理。


二、关闭某个“服务”(不是防火墙)

例如关闭 SSH 服务:

sudo systemctl stop ssh
sudo systemctl disable ssh

查看所有服务:

systemctl list-units --type=service

三、只允许“防火墙关,但服务还在”

如果你只是想 放行端口,而不是关服务:

sudo ufw allow 22
sudo ufw allow 80

四、常见组合示例

  • 完全关闭防火墙(测试环境)
    sudo ufw disable
    
  • 生产环境不建议直接关防火墙 推荐只开放需要的端口。

如果你能告诉我:

  • Debian 版本
  • 用的是 ufw / nftables / 还是云厂商防火墙
  • 想关的是哪个服务(如 ssh、mysql)

我可以给你更精确的命令。

0 踩