在 Debian 上防火墙本身(如 iptables / nftables)是可以做限速的,不过要看你说的“防火墙”是指哪一层。
Debian 默认常带 iptables,可以用 hashlimit 或 limit 模块。
iptables -A INPUT -p tcp --dport 80 -m limit --limit 10/s --limit-burst 20 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j DROP
⚠️ 这是按包,不是按带宽。
iptables -A INPUT -p tcp --dport 22 -m hashlimit \
--hashlimit-mode srcip \
--hashlimit-above 5/min \
--hashlimit-name ssh_limit \
-j DROP
效果:每个 IP 每分钟最多 5 次 SSH 连接。
Debian 10+ 默认更推荐 nftables
table inet filter {
chain input {
type filter hook input priority 0;
tcp dport 80 limit rate 1 mbytes/second accept
}
}
支持单位:
packets/secondbytes/secondmbytes/second⚠️ iptables / nftables 不适合精确带宽限速
应使用 TC(traffic control)
tc qdisc add dev eth0 root tbf rate 100kbit burst 10k latency 50ms
或配合 htb 做更复杂控制。
如果是具体服务:
limit_rate| 需求 | 推荐方案 |
|---|---|
| 防止暴力破解 | iptables / nftables |
| 控制连接频率 | hashlimit |
| 精确带宽限速 | tc |
| Web 服务限速 | Nginx |
如果你告诉我:
我可以直接给你可复制的配置。