I implemented SSH connection rate limiting using the following.
iptables -N SSH_BRUTE_FORCE_MITIGATION
iptables -A SSH_BRUTE_FORCE_MITIGATION -m recent --name SSH --set
iptables -A SSH_BRUTE_FORCE_MITIGATION -m recent --name SSH --update --seconds 300 --hitcount 10 -m limit --limit 1/second --limit-burst 100 -j LOG --log-prefix "iptables[ssh-brute-force]: "
iptables -A SSH_BRUTE_FORCE_MITIGATION -m recent --name SSH --update --seconds 300 --hitcount 10 -j DROP
iptables -A SSH_BRUTE_FORCE_MITIGATION -j ACCEPT
How can I reset rate limit counter?
Edit: tried sudo iptables -Z
, but following error is thrown.
$ sudo iptables -Z
[sudo] password for pi:
iptables v1.8.2 (nf_tables): RULE_REPLACE failed (Invalid argument): rule in chain INPUT
To reset the
-m recent --name SSH
data:From
man 8 iptables-extensions
, section "recent":This is not the same as the per-rule packet/byte counters which can be cleared with
iptables -Z
.This is also not the same as the
-m limit
(which you are using for rate-limiting the logging) or-m hashlimit
counters. Those do not offer such proc interface. Possible workarounds:xt_recent
/xt_limit
/xt_hashlimit
will discard the respective associated data--name
/--hashlimit-name
(appending a number will do)