在 Debian 里“防火墙”通常有两层含义:iptables / nftables 或 UFW(简化前端)。下面按常见场景说明。
sudo apt update
sudo apt install ufw
sudo ufw enable
sudo ufw allow from 1.2.3.4
sudo ufw allow from 1.2.3.4 to any port 22
sudo ufw allow from 192.168.1.0/24
sudo ufw status
iptables -A INPUT -s 1.2.3.4 -j ACCEPT
iptables -A INPUT -p tcp -s 1.2.3.4 --dport 22 -j ACCEPT
apt install iptables-persistent
netfilter-persistent save
nano /etc/nftables.conf
示例:
table inet filter {
chain input {
type filter hook input priority 0;
ip saddr 1.2.3.4 accept
}
}
nft -f /etc/nftables.conf
systemctl enable nftables
deny all,必须先 allow 再 deny如果你能告诉我:
我可以给你精确命令。