DOC: pass through jail.conf.5 -- unification and some restructuring/shortening

pull/570/head
Yaroslav Halchenko 2014-01-06 23:30:13 -05:00
parent 5bd8ba0c6f
commit 16f55d2d56
1 changed files with 132 additions and 117 deletions

View File

@ -12,15 +12,25 @@ jail.conf \- configuration for the fail2ban server
.I filter.d/*.conf filter.d/*.local .I filter.d/*.conf filter.d/*.local
.SH DESCRIPTION .SH DESCRIPTION
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. Fail2ban has four configuration file types:
.SH "CONFIGUATION FILES" .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.
There are *.conf files that are distributed by fail2ban and *.local file that contain user customizations.
It is recommended that *.conf files should remain unchanged. If needed, customizations should be provided in *.local files. .SH "CONFIGUATION FILES FORMAT"
For instance, if you would like to customize the [ssh-iptables-ipset] jail, create a jail.local to extend jail.conf
(the configuration for the fail2ban server). The jail.local file will be the following if you only need to enable \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
it as follows:
.TP .TP
\fIjail.local\fR \fIjail.local\fR
@ -29,132 +39,156 @@ it as follows:
enabled = true enabled = true
.PP .PP
Override only the settings you need to change and the rest of the configuration will come from the corresponding 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.
*.conf file.
\fIfilter.d/\fR and \fIaction.d/\fR .TP
These directories contains \fI*.conf\fR and \fI*.local\fR files that contain filter and action configurations.
\fI.local\fR files are read first and only need to set the directives that are different from the \fI.conf\fR file.
Directives not overwritten are read from the \fI.conf\fR file.
.RS
\fIjail.d/\fR and \fIfail2ban.d/\fR \fIjail.d/\fR and \fIfail2ban.d/\fR
.RS
In addition to .local, for any jail.conf or fail2ban.conf file there can be a corresponding
\fI.d/\fR directory to contain additional .conf files that will be read after the
appropriate .local file. Last parsed file will take precidence over
identical entries, parsed alphabetically, e.g.
In addition to .local, for jail.conf or fail2ban.conf file there can
be a corresponding \fI.d/\fR directory containining additional .conf
files. The order e.g. for \fIjail\fR configuration would be:
.RS
jail.conf
.RE
.RS
jail.d/*.conf (in alphabetical order)
.RE
.RS
jail.local
.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 .RS
\fIjail.d/01_enable.conf\fR - to enable a specific jail \fIjail.d/01_enable.conf\fR - to enable a specific jail
.RE .RE
.RS .RS
\fIjail.d/02_custom_port.conf\fR - containing specific configuration entry to change the port of the jail specified in the configuration \fIjail.d/02_custom_port.conf\fR - to change the port(s) of a jail.
.RE
.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 .RE
.RS .RS
\fIfail2ban.d/01_custom_log.conf\fR - containing specific configuration entry to use a different log path. failregex = useragent=%(baduseragents)s
.RE
.RE .RE
The order \fIjail\fR configuration is parsed is: 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.
jail.conf , .SH "FAIL2BAN CONFIGURATION FILE(S) (\fIfail2ban.conf\fR)"
jail.d/*.conf (in alphabetical order),
jail.local, followed by
jail.d/*.local (in alphabetical order).
Likewise for fail2ban configuration except the filenames/directories begin with "fail2ban" and not "jail".
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.
.SH "FAIL2BAN CONFIGURATION FILES"
These files have one section, [Definition]. These files have one section, [Definition].
The items that can be set are: The items that can be set are:
.TP .TP
\fBloglevel\fR .B loglevel
Set the log level output. , 1 = ERROR, 2 = WARN, 3 = INFO, 4 = DEBUG. Default: 1 verbosity level of log output: 1 = ERROR, 2 = WARN, 3 = INFO, 4 = DEBUG. Default: 1
.TP .TP
\fBlogtarget\fR .B logtarget
Set the log target. This could be a file, SYSLOG, STDERR or STDOUT. Only one log target can be specified. 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 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. corresponding configuration file (e.g. /etc/logrotate.d/fail2ban on Debian systems).
.TP .TP
\fBsocket\fR .B socket
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 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 .TP
\fBpidfile\fR .B pidfile
Set the PID file. This is used to store the process ID of the fail2ban server. PID filename. Default: /var/run/fail2ban/fail2ban.pid.
# Values: [ FILE ] Default: /var/run/fail2ban/fail2ban.pid This is used to store the process ID of the fail2ban server.
.SH "JAIL CONFIGURATION FILES" .SH "JAIL CONFIGURATION FILE(S) (\fIjail.conf\fR)"
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 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.
.TP .TP
\fBfilter\fR .B filter
The filename of the filter in /etc/fail2ban/filter.d/ without the .conf/.local extension. Only one filter can be specified. name of the filter -- filename of the filter in /etc/fail2ban/filter.d/ without the .conf/.local extension. Only one filter can be specified.
.TP .TP
\fBlogpath\fR .B logpath
This is the log filename(s). 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. filename(s) of the log files to be monitored. Globs -- paths containing * and ? or [0-9] -- can be used however only the files that exist at startup matching this glob pattern will be considered.
.TP .TP
\fBaction\fR .B action
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. 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 [name=value,name2=value]. Values can also be quoted. More that one action can be specified (in separate lines).
.TP .TP
\fBignoreip\fR .B ignoreip
A list of IPs not to ban. These can include a CIDR mask too. list of IPs not to ban. They can include a CIDR mask too.
.TP .TP
\fBignorecommand\fR .B ignorecommand
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. 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 ignore command value and will be substitued before execution. Currently only <ip> is supported however more will be added later. 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.
.TP .TP
\fBbantime\fR .B bantime
effective ban duration (measured in seconds). effective ban duration (in seconds).
.TP .TP
\fBfindtime\fR .B findtime
time interval (in seconds) before the current time where failures will count towards a ban. time interval (in seconds) before the current time where failures will count towards a ban.
.TP .TP
\fBmaxretry\fR .B maxretry
number of failures that can occur in the last \fBfindtime\fR seconds before a ban of that IP will result. number of failures that have to occur in the last \fBfindtime\fR seconds to ban then IP.
.TP .TP
\fBbackend\fR .B backend
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. backend to be 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.
.TP .TP
\fBusedns\fR .B usedns
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. 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)..
.TP .TP
\fBfailregex\fR .B failregex
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). 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).
.TP .TP
\fBignoreregex\fR .B ignoreregex
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. 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.
.SH "ACTION CONFIGURATION FILES"
Action files specify which commands are executed to ban and unban an IP address. They are located under \fI/etc/fail2ban/action.d\fR. .SH "ACTION CONFIGURATION FILES (\fIaction.d/*.conf\fR)"
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 \fI[actionname].local\fR file in the \fI/etc/fail2ban/action.d\fR directory 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
and override the required settings. and override the required settings.
Action files are ini files that have two sections, \fBDefinition\fR and \fBInit\fR . Action files have two sections, \fBDefinition\fR and \fBInit\fR .
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 [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.
The following commands can be present in the [Definition] section. The following commands can be present in the [Definition] section.
.TP .TP
\fBactionstart\fR .B actionstart
command(s) executed when the jail starts. command(s) executed when the jail starts.
.TP .TP
\fBactionstop\fR .B actionstop
command(s) executed when the jail stops. command(s) executed when the jail stops.
.TP .TP
\fBactioncheck\fR .B actioncheck
the command ran before any other action. It aims to verify if the environment is still ok. command(s) ran before any other action. It aims to verify if the environment is still ok.
.TP .TP
\fBactionban\fR .B actionban
command(s) that bans the IP address after \fBmaxretry\fR log lines matches within last \fBfindtime\fR seconds. command(s) that bans the IP address after \fBmaxretry\fR log lines matches within last \fBfindtime\fR seconds.
.TP .TP
\fBactionunban\fR .B actionunban
command(s) that unbans the IP address after \fBbantime\fR. command(s) that unbans the IP address after \fBbantime\fR.
.RE
Commands specified in the [Definition] section are executed through a system shell so shell redirection and process control is allowed. The commands should 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). 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).
@ -162,7 +196,7 @@ return 0, otherwise error would be logged. Moreover if \fBactioncheck\fR exits
Tags are enclosed in <>. All the elements of [Init] are tags that are replaced in all action commands. Tags can be added by the 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 setctag command. \fB<br>\fR is a tag that is always a new line (\\n). \fBfail2ban-client\fR using the setctag command. \fB<br>\fR 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 whitespaces without blank lines. The following example defines 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. two commands to be executed.
actionban = iptables -I fail2ban-<name> --source <ip> -j DROP actionban = iptables -I fail2ban-<name> --source <ip> -j DROP
@ -171,53 +205,34 @@ two commands to be executed.
.SS "Action Tags" .SS "Action Tags"
The following tags are substituted in the actionban, actionunban and actioncheck (when called before actionban/actionunban) commands. The following tags are substituted in the actionban, actionunban and actioncheck (when called before actionban/actionunban) commands.
.TP .TP
\fBip\fR .B ip
An IPv4 ip address to be banned. e.g. 192.168.0.2 IPv4 IP address to be banned. e.g. 192.168.0.2
.TP .TP
\fBfailures\fR .B failures
The number of times the failure occurred in the log file. e.g. 3 number of times the failure occurred in the log file. e.g. 3
.TP .TP
\fBtime\fR .B time
The unix (epoch) time of the ban. e.g. 1357508484 UNIX (epoch) time of the ban. e.g. 1357508484
.TP .TP
\fBmatches\fR .B matches
The concatenated string of the log file lines of the matches that generated the ban. Many characters interpreted by shell get escaped. 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.
.SH FILTER FILES .SH FILTER FILES (\fIfilter.d/*.conf\fR)
Filter definitions are those in \fI/etc/fail2ban/filter.d/*.conf\fR and \fIfilter.d/*.local\fR. Filter definitions are those in \fI/etc/fail2ban/filter.d/*.conf\fR and \fIfilter.d/*.local\fR.
These are used to identify failed authentication attempts in logs and to extract the host IP address (or hostname if \fBusedns\fR is \fBtrue\fR). 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).
Like action files, filter files are ini files. The main section is the [Definition] section. 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: There are two filter definitions used in the [Definition] section:
.TP .TP
\fBfailregex\fR .B failregex
is the regex (\fBreg\fRular \fBex\fRpression) that will match failed attempts. The tag <HOST> is used as part of the regex and is itself a regex regex that will match failed attempts. The tag <HOST> is used as part of the regex and is itself a regex
for IPv4 addresses and hostnames. fail2ban will work out which one of these it actually is. for IPv4 addresses (and hostnames if \fBusedns\fR). Fail2Ban will work out which one of these it actually is.
.TP .TP
\fBignoreregex\fR .B ignoreregex
is the regex to identify log entries that should be ignored by fail2ban, even if they match failregex. 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.
baduseragents = IE|wget
failregex = useragent=%(baduseragents)s
.PP
Filters can also have a section called [INCLUDES]. This is used to read other configuration files.
.TP
\fBbefore\fR
indicates that this file is read before the [Definition] section.
.TP
\fBafter\fR
indicates that this file is read after the [Definition] section.
.SH AUTHOR .SH AUTHOR
Fail2ban was originally written by Cyril Jaquier <cyril.jaquier@fail2ban.org>. Fail2ban was originally written by Cyril Jaquier <cyril.jaquier@fail2ban.org>.
@ -227,7 +242,7 @@ Manual page written by Daniel Black and Yaroslav Halchenko.
.SH "REPORTING BUGS" .SH "REPORTING BUGS"
Report bugs to https://github.com/fail2ban/fail2ban/issues Report bugs to https://github.com/fail2ban/fail2ban/issues
.SH COPYRIGHT .SH COPYRIGHT
Copyright \(co 2013 Daniel Black Copyright \(co 2013 Daniel Black and the Fail2Ban Team
.br .br
Copyright of modifications held by their respective authors. Copyright of modifications held by their respective authors.
Licensed under the GNU General Public License v2 (GPL). Licensed under the GNU General Public License v2 (GPL).