在 Debian 上限制 IP,通常取决于你使用的防火墙工具。下面按常见情况说明。
ufw(最推荐,简单)sudo apt update
sudo apt install ufw
sudo ufw enable
sudo ufw deny from 1.2.3.4
sudo ufw deny from 1.2.3.4 to any port 22
sudo ufw default deny incoming
sudo ufw allow from 192.168.1.100
sudo ufw status numbered
sudo ufw delete [编号]
iptables(底层方式)iptables -A INPUT -s 1.2.3.4 -j DROP
iptables -A INPUT -s 1.2.3.4 -p tcp --dport 22 -j DROP
iptables -P INPUT DROP
iptables -A INPUT -s 192.168.1.100 -j ACCEPT
apt install iptables-persistent
netfilter-persistent save
nftables(新版 Debian 推荐)sudo apt install nftables
sudo systemctl enable nftables
nft add rule inet filter input ip saddr 1.2.3.4 drop
nft add rule inet filter input ip saddr 1.2.3.4 tcp dport 22 drop
DROP 比 REJECT 更隐蔽如果你能说明:
我可以给你更精确的规则。