fail2ban
Install Fail2Ban
RHEL
Debian
Config Files
There are two main configuration files in Fail2Ban: /etc/fail2ban/fail2ban.conf
and /etc/fail2ban/jail.conf
/etc/fail2ban/fail2ban.conf
: This is the configuration file for the operational settings of the Fail2Ban daemon. Settings like loglevel, log file, socket and pid file is defined here.
/etc/fail2ban/jail.conf
: This is where all the magic happens. This is the file where you can configure things like default ban time, number of reties before banning an IP, whitelisting IPs, mail sending information etc. Basically you control the behavior of Fail2Ban from this file.
Now before you go and change these files, Fail2Ban advise to make a copy with .local
file for these conf files. It’s because the default conf files can be overwritten in updates and you’ll lose all your settings.
If I remove the comments, the default section looks like this:
bantime: Set the length of the ban. Default is 10 minutes.
findtime: The window in which the action on an IP will be taken. Default is 10 minutes. Suppose a bad login was attempted by a certain IP at 10:30. If the same IP reaches the maximum number of retries before 10:40, it will be banned. Otherwise, the next failed attempt after 10:40 will be counted as first failed attempt.
maxretry: The number of failed retries before an action is taken
usedns: The “warn” setting attempts to use reverse-DNS to look up the hostname and ban it using hostname. Setting it to no will ban IPs, not hostname.
destemail: The email address to which the alerts will be sent (needs to be configured)
sender: The sender name in the notification email
mta: Mail Transfer Agent used for notification email
banaction: This parameter uses the /etc/fail2ban/action.d/iptables-multiport.conf file to set the action after maximum failed retries
protocol: The type of traffic that will be dropped after the ban
Enable Fail2Ban
Once Fail2Ban is enabled, you can see the status and the active jails with fail2ban-client command:
Output:
Fail2Ban log is located at /var/log/fail2ban.log
The log files are in the following format:
See banned IPs
Unban IPs
Whitelist IPs
Remove IPs from Whitelist
Last updated