Created
June 27, 2018 11:06
-
-
Save behringer24/5bb09447496d4705c6c42964a68fa7be to your computer and use it in GitHub Desktop.
How to block a whole IP subnet with fail2ban and iptables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fail2Ban configuration file | |
# | |
# Author: Cyril Jaquier | |
# Modified: Yaroslav O. Halchenko <[email protected]> | |
# made active on all ports from original iptables.conf | |
# Modified: Andreas Behringer | |
# made fail2ban block whole /24 subnets | |
# put this file in /etc/fail2ban/action.d/ | |
# | |
[INCLUDES] | |
before = iptables-blocktype.conf | |
[Definition] | |
# Option: actionstart | |
# Notes.: command executed once at the start of Fail2Ban. | |
# Values: CMD | |
# | |
actionstart = iptables -N fail2ban-<name> | |
iptables -A fail2ban-<name> -j RETURN | |
iptables -I <chain> -p <protocol> -j fail2ban-<name> | |
# Option: actionstop | |
# Notes.: command executed once at the end of Fail2Ban | |
# Values: CMD | |
# | |
actionstop = iptables -D <chain> -p <protocol> -j fail2ban-<name> | |
iptables -F fail2ban-<name> | |
iptables -X fail2ban-<name> | |
# Option: actioncheck | |
# Notes.: command executed once before each actionban command | |
# Values: CMD | |
# | |
actioncheck = iptables -n -L <chain> | grep -q 'fail2ban-<name>[ \t]' | |
# Option: actionban | |
# Notes.: command executed when banning an IP-range. Take care that the | |
# command is executed with Fail2Ban user rights. | |
# Tags: See jail.conf(5) man page | |
# Values: CMD | |
# | |
actionban = iptables -I fail2ban-<name> 1 -s <ip>/24 -j <blocktype> | |
# Option: actionunban | |
# Notes.: command executed when unbanning an IP-range. Take care that the | |
# command is executed with Fail2Ban user rights. | |
# Tags: See jail.conf(5) man page | |
# Values: CMD | |
# | |
actionunban = iptables -D fail2ban-<name> -s <ip>/24 -j <blocktype> | |
[Init] | |
# Default name of the chain | |
# | |
name = default | |
# Option: protocol | |
# Notes.: internally used by config reader for interpolations. | |
# Values: [ tcp | udp | icmp | all ] Default: tcp | |
# | |
protocol = tcp | |
# Option: chain | |
# Notes specifies the iptables chain to which the fail2ban rules should be | |
# added | |
# Values: STRING Default: INPUT | |
chain = INPUT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just a small modification to etc/fail2ban/action.d/iptables-allports.conf