fail2ban/man/jail.conf.5

352 lines
16 KiB
Groff
Raw Normal View History

.TH JAIL.CONF "10" "October 2013" "Fail2Ban" "Fail2Ban Configuration"
2013-03-16 02:57:42 +00:00
.SH NAME
jail.conf \- configuration for the fail2ban server
.SH SYNOPSIS
.I fail2ban.conf fail2ban.d/*.conf fail2ban.local fail2ban.d/*.local
.I jail.conf jail.d/*.conf jail.local jail.d/*.local
2013-03-16 02:57:42 +00:00
.I action.d/*.conf action.d/*.local action.d/*.py
2013-03-16 02:57:42 +00:00
.I filter.d/*.conf filter.d/*.local
2013-03-16 02:57:42 +00:00
.SH DESCRIPTION
Fail2ban has four configuration file types:
.TP
\fIfail2ban.conf\fR
Fail2Ban global configuration (such as logging)
.TP
\fIfilter.d/*.conf\fR
Filters specifying how to detect authentication failures
.TP
\fIaction.d/*.conf\fR
Actions defining the commands for banning and unbanning of IP address
.TP
\fIjail.conf\fR
Jails defining combinations of Filters with Actions.
2013-03-16 02:57:42 +00:00
2014-01-08 10:46:32 +00:00
.SH "CONFIGURATION FILES FORMAT"
2013-03-16 02:57:42 +00:00
\fI*.conf\fR files are distributed by Fail2Ban. It is recommended that *.conf files should remain unchanged to ease upgrades. If needed, customizations should be provided in \fI*.local\fR files. For example, if you would like to enable the [ssh-iptables-ipset] jail specified in jail.conf, create jail.local containing
2013-03-16 02:57:42 +00:00
.TP
\fIjail.local\fR
2013-03-16 02:57:42 +00:00
[ssh-iptables-ipset]
enabled = true
2013-03-25 02:12:52 +00:00
.PP
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.
2013-03-16 02:57:42 +00:00
.TP
\fIjail.d/\fR and \fIfail2ban.d/\fR
In addition to .local, for jail.conf or fail2ban.conf file there can
2014-01-08 10:46:32 +00:00
be a corresponding \fI.d/\fR directory containing additional .conf
files. The order e.g. for \fIjail\fR configuration would be:
2013-03-16 02:57:42 +00:00
.RS
jail.conf
2014-01-06 23:24:23 +00:00
.RE
.RS
jail.d/*.conf (in alphabetical order)
.RE
.RS
jail.local
2014-01-06 23:24:23 +00:00
.RE
.RS
jail.d/*.local (in alphabetical order).
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.
\fIfail2ban.d/01_custom_log.conf\fR - to use a different log path
.RE
.RS
\fIjail.d/01_enable.conf\fR - to enable a specific jail
.RE
.RS
\fIjail.d/02_custom_port.conf\fR - to change the port(s) of a jail.
.RE
.RE
2014-01-06 23:24:23 +00:00
.RE
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.
.PP
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]:
.TP
.B before
indicates that the specified file is to be parsed before the current file.
.TP
.B after
indicates that the specified file is to be parsed after the current file.
.RE
Using Python "string interpolation" mechanisms, other definitions are allowed and can later be used within other definitions as %(name)s. For example.
.RS
baduseragents = IE|wget
.RE
.RS
failregex = useragent=%(baduseragents)s
.RE
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.
.SH "FAIL2BAN CONFIGURATION FILE(S) (\fIfail2ban.conf\fB)"
These files have one section, [Definition].
The items that can be set are:
.TP
.B loglevel
2014-02-20 23:09:45 +00:00
verbosity level of log output: CRITICAL, ERROR, WARNING, NOTICE, INFO, DEBUG. Default: ERROR
.TP
.B logtarget
log target: filename, SYSLOG, STDERR or STDOUT. Default: STDERR . Only a single 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).
.TP
.B socket
socket filename. Default: /var/run/fail2ban/fail2ban.sock .
This is used for communication with the fail2ban server daemon. Do not remove this file when Fail2ban is running. It will not be possible to communicate with the server afterwards.
.TP
.B pidfile
PID filename. Default: /var/run/fail2ban/fail2ban.pid.
This is used to store the process ID of the fail2ban server.
.TP
.B dbfile
Database filename. Default: /var/lib/fail2ban/fail2ban.sqlite3
This defines where the persistent data for fail2ban is stored. This persistent data allows bans to be reinstated and continue reading log files from the last read position when fail2ban is restarted. A value of \fINone\fR disables this feature.
.TP
.B dbpurgeage
Database purge age in seconds. Default: 86400 (24hours)
This sets the age at which bans should be purged from the database.
2013-10-14 11:28:34 +00:00
.SH "JAIL CONFIGURATION FILE(S) (\fIjail.conf\fB)"
The following options are applicable to any jail. They appear in a section specifying the jail name or in the \fI[DEFAULT]\fR section which defines default values to be used if not specified in the individual section.
2013-03-16 02:57:42 +00:00
.TP
.B filter
name of the filter -- filename of the filter in /etc/fail2ban/filter.d/ without the .conf/.local extension. Only one filter can be specified.
2013-12-13 11:11:58 +00:00
.TP
.B logpath
filename(s) of the log files to be monitored, separated by new lines. Globs -- paths containing * and ? or [0-9] -- can be used however only the files that exist at start up matching this glob pattern will be considered.
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 "\fI*last message repeated 5 time*s\fR" otherwise it will fail to detect. This is called \fIRepeatedMsgReduction\fR in rsyslog and should be \fIOff\fR.
2013-12-13 11:11:58 +00:00
.TP
.B logencoding
encoding of log files used for decoding. Default value of "auto" uses current system locale.
.TP
.B action
action(s) from \fI/etc/fail2ban/action.d/\fR without the \fI.conf\fR/\fI.local\fR extension. Arguments can be passed to actions to override the default values from the [Init] section in the action file. Arguments are specified by:
.RS
.RS
[name=value,name2=value,name3="values,values"]
.RE
Values can also be quoted (required when value includes a ","). More that one action can be specified (in separate lines).
.RE
2013-12-13 11:11:58 +00:00
.TP
.B ignoreip
list of IPs not to ban. They can include a CIDR mask too.
2013-12-29 05:29:59 +00:00
.TP
.B ignorecommand
command that is executed to determine if the current candidate IP for banning should not be banned. IP will not be banned if command returns successfully (exit code 0).
Like ACTION FILES, tags like <ip> are can be included in the ignorecommand value and will be substituted before execution. Currently only <ip> is supported however more will be added later.
2013-03-16 02:57:42 +00:00
.TP
.B bantime
effective ban duration (in seconds).
2013-03-16 02:57:42 +00:00
.TP
.B findtime
time interval (in seconds) before the current time where failures will count towards a ban.
2013-03-16 02:57:42 +00:00
.TP
.B maxretry
number of failures that have to occur in the last \fBfindtime\fR seconds to ban then IP.
2013-03-16 02:57:42 +00:00
.TP
.B backend
2014-01-12 10:16:55 +00:00
backend to be used to detect changes in the logpath. It defaults to "auto" which will try "pyinotify", "gamin", "systemd" 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.
2013-03-16 02:57:42 +00:00
.TP
.B usedns
use DNS to resolve HOST names that appear in the logs. By default it is "warn" which will resolve 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 asymmetric 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 necessarily the same one). Ideally you should 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 altogether (thus ignoring entries where hostname, not an IP is logged)..
2013-12-13 11:11:58 +00:00
.TP
.B failregex
regex (Python \fBreg\fRular \fBex\fRpression) to be added to the filter's failregexes. If this is useful for others using your application please share you regular expression with the fail2ban developers by reporting an issue (see REPORTING BUGS below).
2013-12-13 11:11:58 +00:00
.TP
.B ignoreregex
regex which, if the log line matches, would cause Fail2Ban not consider that line. This line will be ignored even if it matches a failregex of the jail or any of its filters.
2013-03-16 02:57:42 +00:00
.SS Backends
Available options are listed below.
.TP
.B pyinotify
requires pyinotify (a file alteration monitor) to be installed. If pyinotify is not installed, Fail2ban will use auto.
.TP
.B gamin
requires Gamin (a file alteration monitor) to be installed. If Gamin is not installed, Fail2ban will use auto.
.TP
.B polling
uses a polling algorithm which does not require external libraries.
.TP
.B systemd
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.
.SS Actions
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.:
.PP
.nf
[ssh-iptables-ipset]
enabled = true
action = smtp.py[dest=chris@example.com, actname=smtp-chris]
smtp.py[dest=sally@example.com, actname=smtp-sally]
.fi
2013-03-16 02:57:42 +00:00
.SH "ACTION CONFIGURATION FILES (\fIaction.d/*.conf\fB)"
Action files specify which commands are executed to ban and unban an IP address.
2013-03-16 02:57:42 +00:00
Like with jail.conf files, if you desire local changes create an \fI[actionname].local\fR file in the \fI/etc/fail2ban/action.d\fR directory
2013-03-25 02:12:52 +00:00
and override the required settings.
2013-03-16 02:57:42 +00:00
Action files have two sections, \fBDefinition\fR and \fBInit\fR .
2013-03-16 02:57:42 +00:00
The [Init] section enables action-specific settings. In \fIjail.conf/jail.local\fR these can be overridden for a particular jail as options of the action's specification in that jail.
2013-03-16 02:57:42 +00:00
2013-03-25 02:12:52 +00:00
The following commands can be present in the [Definition] section.
2013-03-16 02:57:42 +00:00
.TP
.B actionstart
2013-03-25 02:12:52 +00:00
command(s) executed when the jail starts.
2013-03-16 02:57:42 +00:00
.TP
.B actionstop
2013-03-25 02:12:52 +00:00
command(s) executed when the jail stops.
2013-03-16 02:57:42 +00:00
.TP
.B actioncheck
command(s) ran before any other action. It aims to verify if the environment is still ok.
2013-03-16 02:57:42 +00:00
.TP
.B actionban
2013-03-25 02:12:52 +00:00
command(s) that bans the IP address after \fBmaxretry\fR log lines matches within last \fBfindtime\fR seconds.
2013-03-16 02:57:42 +00:00
.TP
.B actionunban
2013-03-25 02:12:52 +00:00
command(s) that unbans the IP address after \fBbantime\fR.
.PP
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.
.PP
.RE
2013-03-25 02:12:52 +00:00
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).
2013-03-25 02:12:52 +00:00
Tags are enclosed in <>. All the elements of [Init] are tags that are replaced in all action commands. Tags can be added by the
\fBfail2ban-client\fR using the "set <JAIL> action <ACT>" command. \fB<br>\fR is a tag that is always a new line (\\n).
2013-03-16 02:57:42 +00:00
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
2013-03-16 02:57:42 +00:00
two commands to be executed.
2013-03-25 02:12:52 +00:00
actionban = iptables -I fail2ban-<name> --source <ip> -j DROP
echo ip=<ip>, match=<match>, time=<time> >> /var/log/fail2ban.log
2013-03-16 02:57:42 +00:00
2013-03-25 02:12:52 +00:00
.SS "Action Tags"
The following tags are substituted in the actionban, actionunban and actioncheck (when called before actionban/actionunban) commands.
2013-03-16 02:57:42 +00:00
.TP
.B ip
IPv4 IP address to be banned. e.g. 192.168.0.2
.TP
.B failures
number of times the failure occurred in the log file. e.g. 3
2013-03-16 02:57:42 +00:00
.TP
2014-01-12 10:16:55 +00:00
.B ipfailures
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
2014-01-12 10:16:55 +00:00
.B ipjailfailures
As per \fBipfailures\fR, but total based on the IPs failures for the current jail.
2013-03-16 02:57:42 +00:00
.TP
.B time
UNIX (epoch) time of the ban. e.g. 1357508484
.TP
.B matches
concatenated string of the log file lines of the matches that generated the ban. Many characters interpreted by shell get escaped to prevent injection, nevertheless use with caution.
2014-01-12 10:16:55 +00:00
.TP
.B ipmatches
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
2014-01-12 10:16:55 +00:00
.B ipjailmatches\
As per \fBipmatches\fR, but matches are limited for the IP and for the current jail.
2013-03-16 02:57:42 +00:00
.SH "PYTHON ACTION FILES"
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.
2013-03-16 02:57:42 +00:00
.SH "FILTER FILES (\fIfilter.d/*.conf\fB)"
2013-03-16 02:57:42 +00:00
Filter definitions are those in \fI/etc/fail2ban/filter.d/*.conf\fR and \fIfilter.d/*.local\fR.
2013-03-16 02:57:42 +00:00
These are used to identify failed authentication attempts in log files and to extract the host IP address (or hostname if \fBusedns\fR is \fBtrue\fR).
2013-03-16 02:57:42 +00:00
Like action files, filter files are ini files. The main section is the [Definition] section.
2013-03-25 02:12:52 +00:00
There are two filter definitions used in the [Definition] section:
2013-03-16 02:57:42 +00:00
.TP
2014-01-12 10:16:55 +00:00
.B failregex
is the regex (\fBreg\fRular \fBex\fRpression) that will match failed attempts. The tag \fI<HOST>\fR is used as part of the regex and is itself a regex
for IPv4 addresses (and hostnames if \fBusedns\fR). Fail2Ban will work out which one of these it actually is.
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.
2013-03-16 02:57:42 +00:00
.TP
2014-01-12 10:16:55 +00:00
.B ignoreregex
is the regex to identify log entries that should be ignored by Fail2Ban, even if they match failregex.
2013-03-25 02:12:52 +00:00
.PP
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.
.TP
\fBdatepattern\fR
specifies a custom date pattern/regex as an alternative to the default date detectors e.g. %Y-%m-%d %H:%M(?::%S)?. For a list of valid format directives, see Python library documentation for strptime behaviour.
.br
Also, special values of \fIEpoch\fR (UNIX Timestamp), \fITAI64N\fR and \fIISO8601\fR can be used.
.br
\fBNOTE:\fR due to config file string substitution, that %'s must be escaped by an % in config files.
.TP
\fBjournalmatch\fR
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.
2013-03-16 02:57:42 +00:00
.PP
Filters can also have a section called [INCLUDES]. This is used to read other configuration files.
.TP
\fBbefore\fR
2013-03-23 09:19:05 +00:00
indicates that this file is read before the [Definition] section.
2013-03-16 02:57:42 +00:00
.TP
\fBafter\fR
2013-03-23 09:19:05 +00:00
indicates that this file is read after the [Definition] section.
2013-03-16 02:57:42 +00:00
.SH AUTHOR
2013-03-25 02:12:52 +00:00
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 \fBTHANKS\fR file shipped with Fail2Ban for a full list.
2013-03-25 02:12:52 +00:00
.
Manual page written by Daniel Black and Yaroslav Halchenko.
2013-03-16 02:57:42 +00:00
.SH "REPORTING BUGS"
Report bugs to https://github.com/fail2ban/fail2ban/issues
.SH COPYRIGHT
2014-01-08 10:46:32 +00:00
Copyright \(co 2013 the Fail2Ban Team
2013-03-16 02:57:42 +00:00
.br
Copyright of modifications held by their respective authors.
2014-01-08 10:46:32 +00:00
.br
Licensed under the GNU General Public License v2 (GPL) or
(at your option) any later version.
.
2013-03-16 02:57:42 +00:00
.SH "SEE ALSO"
2013-03-25 02:12:52 +00:00
.br
2013-03-16 02:57:42 +00:00
fail2ban-server(1)