在 Debian 系统中,“防火墙”通常指 iptables / nftables 以及用户层管理工具(如 ufw、firewalld)。所谓“替换防火墙”,一般有以下几种常见场景:
sudo apt update
sudo apt install ufw
sudo iptables -F
sudo iptables -X
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow ssh
sudo ufw enable
sudo ufw status
✅ 此时 ufw 已“替换”你原来的 iptables 管理方式。
Debian 默认已逐步转向 nftables。
sudo apt install nftables
sudo systemctl stop iptables
sudo systemctl disable iptables
(如未安装 iptables 服务可忽略)
sudo systemctl enable nftables
sudo systemctl start nftables
sudo nft add table inet filter
sudo nft add chain inet filter input { type filter hook input priority 0 \; }
sudo nft add rule inet filter input ct state established,related accept
sudo nft add rule inet filter input tcp dport 22 accept
sudo nft add rule inet filter input drop
sudo apt install firewalld
sudo ufw disable
sudo systemctl enable firewalld
sudo systemctl start firewalld
sudo firewall-cmd --add-service=ssh --permanent
sudo firewall-cmd --reload
ufw disablesystemctl stop iptablesnftables / firewalld / ufw| 场景 | 推荐 |
|---|---|
| 个人 / VPS | ufw |
| 服务器 / 新系统 | nftables |
| 企业 / 多区域 | firewalld |
如果你能说明:
我可以给你精确到命令的替换方案。