N.B. any syntax / function changes made within fail2ban-client
will alter the
commands used. The commands used here worked with versions 0.8.6-3wheezy3
and 0.8.13-1
. 0.9 may or may not work exactly using the below.
For anyone visiting this and stuck on a version pre 0.10 where you want to add a jail but do not want run reload (which pre 0.10 stops and starts all enabled jails as well as reparsing the config
- Modify
jail.local
and add any required files tofilter.d
/action.d
- Interrogate
jail.local
/filter.d
/action.d
for settings to use - Interrogate existing running jail for useful items (if neccessary)
- Use
fail2ban-client
to create and start new jail.
# fail2ban-client get ssh ignoreip
These IP addresses/networks are ignored:
|- 127.0.0.1/8
|- another ip
`- last ip
# fail2ban-client get ssh actionstart iptables-multiport
iptables -N fail2ban-<name>
iptables -A fail2ban-<name> -j RETURN
iptables -I <chain> -p <protocol> -m multiport --dports <port> -j fail2ban-<name>
Here I've used new-jail
as the name of the jail you want to create (you may
wish to keep it the same as you've defined in jail.local
for consistency)
{my-logpath}
is what you would definelogpath
as in yourjail.local
{my-regex}
is a quoted string (due to bash expansions) of what you would definefailregex
as in yourjail.local
- repeat the line with
addignoreip
for all addresses to use forignoreip
- the values used for
actionstart
,actioncheck
,actionstop
,actionban
,actionunban
are the same as those that were already in use foriptables-allports
within another jail - Unsure if its the version I was using or not but most
fail2ban
variables found had to be expanded when using this way i.e. note<name>
,<protocol>
,<port>
,<chain>
,<blocktype>
have all be replaced in the below statements. The only variables I left in the statements were<ip>
for theiptables-allports
statements and<HOST>
in theaddfailregex
statement.
# fail2ban-client add new-jail auto
# fail2ban-client set new-jail maxretry 1
# fail2ban-client set new-jail findtime 2592000
# fail2ban-client set new-jail bantime 604800
# fail2ban-client set new-jail addlogpath {my-logpath}
# fail2ban-client set new-jail addfailregex '{my-regex}'
# fail2ban-client set new-jail addignoreip 127.0.0.1/8
# fail2ban-client set new-jail addaction iptables-allports
# fail2ban-client set new-jail actionstart iptables-allports 'iptables -N fail2ban-new-jail
iptables -A fail2ban-new-jail -j RETURN
iptables -I INPUT -p tcp -j fail2ban-new-jail'
# fail2ban-client set new-jail actioncheck iptables-allports "iptables -n -L INPUT | grep -q 'fail2ban-new-jail[ \t]'"
# fail2ban-client set new-jail actionstop iptables-allports "iptables -D INPUT -p tcp -j fail2ban-new-jail
iptables -F fail2ban-new-jail
iptables -X fail2ban-new-jail"
# fail2ban-client set new-jail actionban iptables-allports "iptables -I fail2ban-new-jail 1 -s <ip> -j REJECT --reject-with icmp-port-unreachable"
# fail2ban-client set new-jail actionunban iptables-allports "iptables -D fail2ban-new-jail -s <ip> -j REJECT --reject-with icmp-port-unreachable"
# fail2ban-client start new-jail
If fail2ban
doesnt like anything you've done it will log it to the error log
WARNING Jail name 'new-jail' might be too long and some commands (e.g. iptables) might not function correctly. Please shorten
Your jail name is too long. Remember fail2ban
prefixes your jail name in
iptables
names with fail2ban-
.
You did not change <blocktype>
in your banaction
The iptables jump entry does not exist
Your startaction
is not creating the chain and appropriate jump entry