JAIL.CONF(5) | Fail2Ban Configuration | JAIL.CONF(5) |
jail.conf - configuration for the fail2ban server
fail2ban.conf fail2ban.d/*.conf fail2ban.local fail2ban.d/*.local
jail.conf jail.d/*.conf jail.local jail.d/*.local
action.d/*.conf action.d/*.local action.d/*.py
filter.d/*.conf filter.d/*.local
Fail2ban has four configuration file types:
*.conf files are distributed by Fail2Ban. It is recommended that *.conf files should remain unchanged to ease upgrades. If needed, customizations should be provided in *.local files. For example, if you would like to enable the [ssh-iptables-ipset] jail specified in jail.conf, create jail.local containing
enabled = true
In .local files specify only the settings you would like to change and the rest of the configuration will then come from the corresponding .conf file which is parsed first.
In addition to .local, for jail.conf or fail2ban.conf file there can be a corresponding .d/ directory containing additional .conf files. The order e.g. for jail configuration would be:
i.e. all .local files are parsed after .conf files in the original configuration file and files under .d directory. Settings in the file parsed later take precedence over identical entries in previously parsed files. Files are ordered alphabetically, e.g.
fail2ban.d/01_custom_log.conf - to use a different log path
Configuration files have sections, those specified with [section name], and name = value pairs. For those name items that can accept multiple values, specify the values separated by spaces, or in separate lines space indented at the beginning of the line before the second value.
Configuration files can include other (defining common variables) configuration files, which is often used in Filters and Actions. Such inclusions are defined in a section called [INCLUDES]:
Using Python "string interpolation" mechanisms, other definitions are allowed and can later be used within other definitions as %(name)s.
Fail2ban has more advanced syntax (similar python extended
interpolation). This extended interpolation is using
%(section/parameter)s to denote a value from a foreign section.
Besides cross section interpolation the value of parameter in [DEFAULT]
section can be retrieved with %(default/parameter)s.
Fail2ban supports also another feature named %(known/parameter)s (means
last known option with name parameter). This interpolation makes
possible to extend a stock filter or jail regexp in .local file (opposite to
simply set failregex/ignoreregex that overwrites it), e.g.
baduseragents = IE|wget|%(my-settings/baduseragents)s failregex = %(known/failregex)s
useragent=%(baduseragents)s
Additionally to interpolation %(known/parameter)s, that does not works for filter/action init parameters, an interpolation tag <known/parameter> can be used (means last known init definition of filters or actions with name parameter). This interpolation makes possible to extend a parameters of stock filter or action directly in jail inside jail.conf/jail.local file without creating a separately filter.d/*.local file, e.g.
[Init] test.method = GET baduseragents = IE|wget [Definition] failregex = ^%(__prefix_line)\s+"<test.method>"\s+test\s+regexp\s+-\s+useragent=(?:<baduseragents>) # jail.local: [test] # use filter "test", overwrite method to "POST" and extend known bad agents with "badagent": filter = test[test.method=POST, baduseragents="badagent|<known/baduseragents>"]
Comments: use '#' for comment lines and '; ' (space is important) for inline comments. When using Python2.X, '; ' can only be used on the first line due to an Python library bug.
These files have one section, [Definition].
The items that can be set are:
The following options are applicable to any jail. They appear in a section specifying the jail name or in the [DEFAULT] section which defines default values to be used if not specified in the individual section.
Optional space separated option 'tail' can be added to the end of the path to cause the log file to be read from the end, else default 'head' option reads file from the beginning
Ensure syslog or the program that generates the log file isn't configured to compress repeated log messages to "*last message repeated 5 time*s" otherwise it will fail to detect. This is called RepeatedMsgReduction in rsyslog and should be Off.
If this option is not specified, log lines from which no explicit time zone has been found are interpreted by fail2ban in its own system time zone, and that may turn to be inappropriate. While the best practice is to configure the monitored applications to include explicit offsets, this option is meant to handle cases where that is not possible.
The supported time zones in this option are those with fixed offset: Z, UTC[+-]hhmm (you can also use GMT as an alias to UTC).
This option has no effect on log lines on which an explicit time zone has been found. Examples:
logtimezone = UTC
logtimezone = UTC+0200
logtimezone = GMT-0100
[name=value,name2=value,name3="values,values"]
Available options are listed below.
Each jail can be configured with only a single filter, but may have multiple actions. By default, the name of a action is the action filename, and in the case of Python actions, the ".py" file extension is stripped. Where multiple of the same action are to be used, the actname option can be assigned to the action to avoid duplication e.g.:
[ssh-iptables-ipset] enabled = true action = smtp.py[dest=chris@example.com, actname=smtp-chris]
smtp.py[dest=sally@example.com, actname=smtp-sally]
The time entries in fail2ban configuration (like findtime or bantime) can be provided as integer in seconds or as string using special abbreviation format (e. g. 600 is the same as 10m).
years?, yea?, yy? months?, mon? weeks?, wee?, ww? days?, da, dd? hours?, hou?, hh? minutes?, min?, mm? seconds?, sec?, ss? The question mark (?) means the optional character, so day as well as days can be used.
You can combine multiple tokens in format (separated with space
resp. without separator), e. g.: 1y 6mo or 1d12h30m.
Note that tokens m as well as mm means minutes, for month use
abbreviation mo or mon.
The time format can be tested using fail2ban-client:
fail2ban-client --str2sec 1d12h
Action files specify which commands are executed to ban and unban an IP address.
Like with jail.conf files, if you desire local changes create an [actionname].local file in the /etc/fail2ban/action.d directory and override the required settings.
Action files have two sections, Definition and Init .
The [Init] section enables action-specific settings. In jail.conf/jail.local these can be overridden for a particular jail as options of the action's specification in that jail.
The following commands can be present in the [Definition] section.
The [Init] section allows for action-specific settings. In jail.conf/jail.local these can be overwritten for a particular jail as options to the jail. The following are special tags which can be set in the [Init] section:
Commands specified in the [Definition] section are executed through a system shell so shell redirection and process control is allowed. The commands should return 0, otherwise error would be logged. Moreover if actioncheck exits with non-0 status, it is taken as indication that firewall status has changed and fail2ban needs to reinitialize itself (i.e. issue actionstop and actionstart commands). Tags are enclosed in <>. All the elements of [Init] are tags that are replaced in all action commands. Tags can be added by the fail2ban-client using the "set <JAIL> action <ACT>" command. <br> is a tag that is always a new line (\n).
More than a single command is allowed to be specified. Each command needs to be on a separate line and indented with whitespace(s) without blank lines. The following example defines two commands to be executed.
actionban = iptables -I fail2ban-<name> --source <ip> -j DROP
echo ip=<ip>, match=<match>, time=<time> >>
/var/log/fail2ban.log
The following tags are substituted in the actionban, actionunban and actioncheck (when called before actionban/actionunban) commands.
Python based actions can also be used, where the file name must be [actionname].py. The Python file must contain a variable Action which points to Python class. This class must implement a minimum interface as described by fail2ban.server.action.ActionBase, which can be inherited from to ease implementation.
Filter definitions are those in /etc/fail2ban/filter.d/*.conf and filter.d/*.local.
These are used to identify failed authentication attempts in log files and to extract the host IP address (or hostname if usedns is true).
Like action files, filter files are ini files. The main section is the [Definition] section.
There are two filter definitions used in the [Definition] section:
Similar to actions, filters have an [Init] section which can be overridden in jail.conf/jail.local. Besides the filter-specific settings, the filter [Init] section can be used to set following standard options:
Similar to actions [Init] section enables filter-specific settings. All parameters specified in [Init] section can be redefined or extended in jail.conf/jail.local.
Filters can also have a section called [INCLUDES]. This is used to read other configuration files.
Fail2ban was originally written by Cyril Jaquier <cyril.jaquier@fail2ban.org>. At the moment it is maintained and further developed by Yaroslav O. Halchenko <debian@onerussian.com>, Daniel Black <daniel.subs@internode.on.net> and Steven Hiscocks <steven-fail2ban@hiscocks.me.uk> along with a number of contributors. See THANKS file shipped with Fail2Ban for a full list. Manual page written by Daniel Black and Yaroslav Halchenko.
Report bugs to https://github.com/fail2ban/fail2ban/issues
Copyright © 2013 the Fail2Ban Team
Copyright of modifications held by their respective authors.
Licensed under the GNU General Public License v2 (GPL) or (at your option) any
later version.
November 2015 | Fail2Ban |