在 Debian 中,“防火墙”通常指的是 iptables / nftables,不过 Debian 10 及以后更推荐使用 UFW(Uncomplicated Firewall) 或 firewalld 来管理。下面按常见方式说明。
sudo apt update
sudo apt install ufw
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow ssh
# 或
sudo ufw allow 22/tcp
sudo ufw enable
sudo ufw status
✅ UFW 开启后会在系统启动时自动启用。
sudo apt install firewalld
sudo systemctl start firewalld
sudo systemctl enable firewalld
sudo firewall-cmd --state
sudo firewall-cmd --permanent --add-port=22/tcp
sudo firewall-cmd --reload
sudo apt install nftables
sudo systemctl enable nftables
sudo systemctl start nftables
规则写在:
/etc/nftables.conf
Debian 新版本已用 nftables 替代 iptables 后端:
sudo apt install iptables
sudo systemctl enable iptables
如果你告诉我:
cat /etc/debian_version)我可以帮你写一套具体防火墙规则。