Skip to content

Instantly share code, notes, and snippets.

@mindo
Created June 29, 2012 15:44
Show Gist options
  • Save mindo/3018725 to your computer and use it in GitHub Desktop.
Save mindo/3018725 to your computer and use it in GitHub Desktop.
fail2ban monitor and ban really persistent attackers
# /etc/fail2ban/filter.d/fail2ban.conf
# Fail2Ban configuration file
#
# Author: Tom Hendrikx
#
# $Revision$
#
[Definition]
# Option: failregex
# Notes.: regex to match the password failures messages in the logfile. The
# host must be matched by a group named "host". The tag "<HOST>" can
# be used for standard IP/hostname matching and is only an alias for
# (?:::f{4,6}:)?(?P<host>\S+)
# Values: TEXT
#
# Count all bans in the logfile
failregex = fail2ban.actions: WARNING \[(.*)\] Ban <HOST>
# Option: ignoreregex
# Notes.: regex to ignore. If this regex matches, the line is ignored.
# Values: TEXT
#
# Ignore our own bans, to keep our counts exact.
# In your config, name your jail 'fail2ban', or change this line!
ignoreregex = fail2ban.actions: WARNING \[fail2ban\] Ban <HOST>
# add to /etc/fail2ban/jail.conf
[fail2ban]
enabled = true
filter = fail2ban
action = iptables-allports[name=fail2ban]
sendmail-whois[name=fail2ban]
logpath = /var/log/fail2ban.log
# findtime: 1 week
findtime = 604800
# bantime: 1 week
bantime = 604800
@AllanIT
Copy link

AllanIT commented Sep 18, 2015

Thanks for the great jail.

I have used your jail for several years very successfully but the other day I upgraded Fail2ban to v0.8.14 to overcome a problem with the apache jails and now your jail has stopped working. when I run it with failregex it returns

Failregex: 1178 total
|- #) [# of hits] regular expression
| 1) [1178] fail2ban.actions: WARNING [(.*)] Ban
`-

however there are no bans in iptables and the same persistent ip returns again and again. Do you have any ideas what could have gone wrong?

@AllanIT
Copy link

AllanIT commented Sep 20, 2015

For the benefit of any one who is having a problem with this jail. You may want to try the solution that worked for me. Hope it works for you. You will have to change both the failregex and the ignoreregex to the ones below.

failregex = fail2ban.actions\[(.*)\]: WARNING \[(.*)\] Ban <HOST>

ignoreregex = fail2ban.actions\[(.*)\]: WARNING \[fail2ban-reban\] Ban <HOST>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment