Fail2ban has four configuration file types. Failban configuration files that contain global configuration items, Action configuration files are the commands for banning and unbanning of IP address, Filter configuration files tell fail2ban how to detect authentication failures, and Jail configuration files combine filters with actions into jails.
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 new lines between the values which also requires space at the beginning of the line before the second value..
Comments: use '#' for comment lines and ';' (following a space) for inline comments. When using Python2.X ';' can only be used on the first line due to an Python library bug.
Set the log level output. , 1 = ERROR, 2 = WARN, 3 = INFO, 4 = DEBUG. Default: 1
.TP
\fBlogtarget\fR
Set the log target. This could be a file, SYSLOG, STDERR or STDOUT. Only one log target can be specified.
If you change logtarget from the default value and you are using logrotate -- also adjust or disable rotation in the
corresponding configuration file (e.g. /etc/logrotate.d/fail2ban on Debian systems). Values can be [ STDOUT | STDERR | SYSLOG | FILE ] Default: STDERR.
.TP
\fBsocket\fR
Set the socket file. This is used to communicate with the fail2ban server daemon. Do not remove this file when Fail2ban runs. It will not be possible to communicate with the server afterwards. Default: /var/run/fail2ban/fail2ban.sock
.TP
\fBpidfile\fR
Set the PID file. This is used to store the process ID of the fail2ban server.
The following options are applicable to all jails. They appear in a section specifing the jail name or in the \fI[DEFAULT]\fR section which is used if individual sections don't have a value specified.
the log filename(s)separated by new lines. Globs, like paths containing * and ? or [0-9], can be used however only the files that exist at startup matching this glob pattern will be read. 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
action(s) from \fI/etc/fail2ban/action.d/\fR without the \fI.conf\fR/\fI.local\fR extension. Arguements can be passed to actions to override the default values from the [Init] section. Arguements are specified by [name=value,name2=value]. Values can also be quoted. More that one action can be specified.
A command that is executed to determine if the current ban's actionban is to be executed. This command will return true if the current ban should be ignored. A false return value will result in the ban's actionban executed.
Like ACTION FILES, tags like <ip> are can be included in the ignore command value and will be substitued before execution. Currently only <ip> is supported however more will be added later.
This is the backend used to detect changes in the logpath. It defaults to "auto" which will try "pyinotify", "gamin" before "polling". Any of these can be specified. "pyinotify" is only valid on Linux systems with the "pyinotify" Python libraries. "gamin" requires the "gamin" libraries.
This tells fail2ban to use DNS to resolve HOST names that appear in the logs. By default it is "warn" which will preform the resolving hostnames to IPs however it will also log a warning. If you are using DNS here you could be blocking the wrong IPs due to the asymetric nature of reverse DNS (that the application used to write the domain name to log) compared to forward DNS that fail2ban uses to resolve this back to an IP (but not necessarly the same one). Idealy configure your applications to log a real IP. This can be set to "yes" to prevent warnings in the log or "no" to disable DNS resolution.
Here a failregex can be added which is effectively added to the filter's failregexes. If this is useful for others using your application please tell the fail2ban developers by reporting an issue (REPORTING BUGS below).
Here you can specify a Python regex that when applied to a log file line will be ignored. This will be ignored even if it matches a failregex of the jail or any of its filters.
\fBbackend\fR specifies the backend used to get files modification. This option can be overridden in each jail as well.
Available options are listed below.
.TP
\fIpyinotify\fR
requires pyinotify (a file alteration monitor) to be installed. If pyinotify is not installed, Fail2ban will use auto.
.TP
\fIgamin\fR
requires Gamin (a file alteration monitor) to be installed. If Gamin is not installed, Fail2ban will use auto.
.TP
\fIpolling\fR
uses a polling algorithm which does not require external libraries.
.TP
\fIsystemd\fR
uses systemd python library to access the systemd journal. Specifying \fBlogpath\fR is not valid for this backend and instead utilises \fBjournalmatch\fR from the jails associated filter config.
.TP
\fIauto\fR
will try to use the following backends, in order: pyinotify, gamin, polling
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 \fBactname\fR option can be assigned to the action to avoid duplication e.g.:
The [Init] section allows for action-specific settings. In \fIjail.conf/jail.local\fR 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:
.TP
\fBtimeout\fR
The maximum period of time in seconds that a command can executed, before being killed.
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 \fBactioncheck\fR exits with non-0 status, it is taken as indication that firewall status has changed and fail2ban needs to reinitialize itself (i.e. issue \fBactionstop\fR and \fBactionstart\fR commands).
More than a single command is allowed to be specified. Each command needs to be on a separate line and indented with whitespaces without blank lines. The following example defines
As per \fBfailures\fR, but total of all failures for that ip address across all jails from the fail2ban persistent database. Therefore the database must be set for this tag to function.
.TP
\fBipjailfailures\fR
As per \fBipfailures\fR, but total based on the IPs failures for the current jail.
The string of the log file lines of the matches that generated the ban. Many characters interpreted by shell get escaped. New lines are maintained, so actions should be careful to enclose the tag in quotes.
.TP
\fBipmatches\fR
As per \fBmatches\fR, but includes all lines for the IP which are contained with the fail2ban persistent database. Therefore the database must be set for this tag to function.
.TP
\fBipjailmatches\fR
As per \fBipmatches\fR, but matches are limited for the IP and for the current jail.
Python based actions can also be used, where the file name must be \fI[actionname].py\fR. The Python file must contain a variable \fIAction\fR which points to Python class. This class must implement a minimum interface as described by \fIfail2ban.server.action.ActionBase\fR, which can be inherited from to ease implementation.
For multiline regexs the tag \fI<SKIPLINES>\fR should be used to separate lines. This allows lines between the matched lines to continue to be searched for other failures. The tag can be used multiple times.
is the regex to identify log entries that should be ignored by fail2ban, even if they match failregex.
Using Python "string interpolation" mechanisms, other definitions are allowed and can later be used within other definitions as %(defnname)s. For example.
Similar to actions, filters have an [Init] section which can be overridden in \fIjail.conf/jail.local\fR. The filter [Init] section is limited to the following options:
.TP
\fBmaxlines\fR
specifies the maximum number of lines to buffer to match multi-line regexs. For some log formats this will not required to be changed. Other logs may require to increase this value if a particular log file is frequently written to.
specifies the systemd journal match used to filter the journal entries. See \fBjournalctl(1)\fR and \fBsystemd.journal-fields(7)\fR for matches syntax and more details on special journal fields. This option is only valid for the \fIsystemd\fR backend.
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 \fBTHANKS\fR file shipped with Fail2Ban for a full list.