You did not provide what is the issue basically, moreover neither a log excerpt with messages you want to catch in filter, nor the atempt what fail2ban-regex -v
find with filter.
I guess the message looks like:
Jan 26 14:00:10 srv named[26403]: client 192.0.2.100#21324 (example.com): rate limit drop all response to 192.0.2.0/24
Then here are 2 things to note - firstly the IP is after client (here 192.0.2.100
), and at end it has a subnet (IP/CIDR notation, here 192.0.2.0/24
).
If you want to ban a subnet (if your fail2ban and choosen banaction are able to ban subnets at all), you can use depending on your version:
either this (if your fail2ban supports <SUBNET>
):
failregex = ^\s*\S+\s+named(?:\[\d+\])?: [^:]+: rate limit drop all response to <SUBNET>
or this:
failregex = ^\s*\S+\s+named(?:\[\d+\])?: [^:]+: rate limit drop all response to (?:<F-IP4>\d+\.\S+</F-IP4>|<F-IP6>\w+\:\S+</F-IP6>)
You can also ban IP instead of subnet, then use either this one:
failregex = ^\s*\S+\s+named(?:\[\d+\])?: client <ADDR>[^:]*: rate limit drop all response
You can also check it with fail2ban-regex
, for example:
msg='Jan 26 14:00:10 srv named[26403]: client 192.0.2.100#21324 (example.com): rate limit drop all response to 192.0.2.0/24'
fail2ban-regex "$msg" '^\s*\S+\s+named(?:\[\d+\])?: [^:]+: rate limit drop all response to <SUBNET>'
...
Lines: 1 lines, 0 ignored, 1 matched, 0 missed
or to test the filter with a log-file use this:
fail2ban-regex /var/log/named/rate.log named-antispam
As for your prefregex
and failregex
- they are just not correct. Neither prefregex nor failregex must contain a part with timestamp matching datepattern
(read a how-to's in our wiki or manual, it contains:
NOTE: the failregex
will be applied to the remaining part of message after prefregex
processing (if specified), which in turn takes place after datepattern
processing (whereby the string of timestamp matching the best pattern, cut out from the message).
Also prefregex
makes sense, if you need some prefiltering, for instance you have more than one failregex (and such a regex's will be applied either on whole part of line, or on part matched RE enclosed between <F-CONTENT>
and </F-CONTENT>
, if it is specified.
If no prefiltering expected, prefregex
makes few sense.
Anyway if you need it for some reason, it would look like this:
prefregex = ^\s*\S+\s+named(?:\[\d+\])?: <F-CONTENT>.+</F-CONTENT>$
failregex = ^[^:]+: rate limit drop all response to <SUBNET>
#failregex = ^[^:]+: rate limit drop all response to (?:<F-IP4>\d+\.\S+</F-IP4>|<F-IP6>\w+\:\S+</F-IP6>)
#failregex = ^client <ADDR>[^:]*: rate limit drop all response