Re: Question on rate limiting on nftables
<[email protected]> Mon, 8 Jun 2026 17:54:38 -0400
| Newsgroups | gmane.comp.security.firewalls.netfilter.general |
|---|---|
| Message-ID | <20260608175438.34c41f02@playground> |
On Mon, 08 Jun 2026 12:30:55 +0100 "Andre Rodier" <[email protected]> wrote: > Hello, > > I am testing nftables SSH connections attempts limit, and I read about "meters" > > I would like to know the difference between these two methods of new connections limiting, and to ensure the first one is correct. > > The first option: > > ~~~ > table inet filter { > [...] > meta nfproto ipv4 tcp dport ssh ct state new,untracked \ > limit rate over 10/second \ > counter add @banned_ipv4 { ip saddr . ssh } \ > comment "Ban SSH bots" > } > ~~~ > > And the second option: > > ~~~ > table inet filter { > [...] > meta nfproto ipv4 tcp dport ssh ct state new,untracked \ > meter ssh4 { ip saddr limit rate over 10/second } \ > add @banned_ipv4 { ip saddr . ssh } > } > ~~~ > > Is there any advantage using the second method ? > > Thanks for your insights > The first method, as already explained, effectively drops packets when too many arrive too quickly from all sources. The second tracks individual IPs. In my F/W, attempts from internet to access ports that are *not* open/forwarded are logged as 'badtraffic' and dropped. Attempts, again from internet, to access open/forwarded ports too quickly (N SYNs in M seconds) are logged as 'badtraffic' and dropped. The limiter looks at all open/forwarded ports. I also have a script that runs periodically; it gathers the IPs from the 'badtraffic' log entries (and IPs from other sources) and adds them to an IP set if they are not already covered there by a /16 or /24 set and not already present in the IP set. Periodically blocking them allows the rate-limited IPs to expire from the rate limiter. They stay blocked until they fall out of the logs. This and the other measures I've taken have reduced bandit* traffic from well over 100kbit/s to around 3kbit/s on average. They've reduced guests on my forum from over 400 (up to 5000) to less than 15. Alas, there is one drawback to my methods: I don't know how many false positives they trigger; my limits are probably a little too tight. The rate limiter has 2048 entries. At present, the sets contain 9000 blocked nets and 535k blocked IPs. That's about 1/8000 of the internet, so my methods mightn't be too aggressive. Neal * - Yes, I call all of those miscreants 'bandits', for that is what they are.