JAIL.CONF(5)
π JAIL.CONF(5) β Fail2Ban Configuration π
okay so this is the jail.conf(5) page, aka the Fail2Ban Configuration manual, and honestly? it's a whole vibe. it's the map to every config file fail2ban has, and bestie, we're gonna walk through all of it together. grab a matcha π
π NAME π
jail.conf β the configuration for the fail2ban server. that's the whole name section, short and slay π
β¨ SYNOPSIS β¨
here's the file lineup, in the order the page gives it:
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
π¦ DESCRIPTION π¦
Fail2ban has four configuration file types, and each one has a job:
fail2ban.confβ the Fail2Ban global configuration (think stuff like logging).filter.d/*.confβ Filters, which specify how to detect authentication failures.action.d/*.confβ Actions, which define the commands for banning and unbanning of IP address.jail.confβ Jails, which define combinations of Filters with Actions.
it's giving assembly line: filter spots the problem, action does something about it, jail puts them together π
π CONFIGURATION FILES FORMAT π
so *.conf files are the ones distributed by Fail2Ban itself. it is recommended that *.conf files should remain unchanged to ease upgrades β like, do not touch the stock ones, bestie, future you will thank you π
if you need customizations, they 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:
in jail.local:
[ssh-iptables-ipset]
enabled = true
in .local files you 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. it's an overlay situation, we love a layering moment π«Ά
π
jail.d/ and fail2ban.d/ π
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:
jail.conf
jail.d/*.conf (in alphabetical order)
jail.local
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.
fail2ban.d/01_custom_log.conf - to use a different log path
jail.d/01_enable.conf - to enable a specific jail
jail.d/02_custom_port.conf - to change the port(s) of a jail.
so yes, the numbers in the front of the filename are basically the queue order. main character energy for 01, quietly iconic for 02 β¨
π§ sections & values π§
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.
π [INCLUDES] π
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]:
beforeβ indicates that the specified file is to be parsed before the current file.afterβ indicates that the specified file is to be parsed after the current file.
π interpolation, it's giving python π
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.
# filter.d/test.conf:
[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>"]
likeβ¦ the way that you can extend instead of overwrite? obsessed. no cap π₯
π comments π
comments: use # for comment lines and '; ' (space is important) for inline comments. that space is doing SO much work, do not skip it π
π FAIL2BAN CONFIGURATION FILE(S) (fail2ban.conf) π
the items that can be set in section [Definition] are:
loglevelβ verbosity level of log output:CRITICAL,ERROR,WARNING,NOTICE,INFO,DEBUG,TRACEDEBUG,HEAVYDEBUGor corresponding numeric value (50-5). Default:INFO(equal 20).logtargetβ log target: filename,SYSLOG,STDERRorSTDOUT. Default:STDOUTif not set infail2ban.conf/fail2ban.local.
Note. If fail2ban running as systemd-service, for logging to the systemd-journal, thelogtargetcould be set toSTDOUT. Only a single log target can be specified. If you changelogtargetfrom the default value and you are usinglogrotateβ also adjust or disable rotation in the corresponding configuration file (e.g./etc/logrotate.d/fail2banon Debian systems).
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. seriously, hands off the socket bestie πpidfileβ PID filename. Default:/var/run/fail2ban/fail2ban.pid. This is used to store the process ID of the fail2ban server.allowipv6β option to allow IPv6 interface βauto,yes(on,true,1) orno(off,false,0). Default:auto. This value can be used to declare fail2ban whether IPv6 is allowed or not.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 ofNonedisables this feature.dbmaxmatchesβ Max number of matches stored in database per ticket. Default:10. This option sets the max number of matched log-lines could be stored per ticket in the database. This also affects values resolvable via tags<ipmatches>and<ipjailmatches>in actions.dbpurgeageβ Database purge age in seconds. Default:86400(24hours). This sets the age at which bans should be purged from the database.
the config parameters of section [Thread] are:
stacksizeβ Stack size of each thread in fail2ban. Default:0(platform or configured default). This specifies the stack size (in KiB) to be used for subsequently created threads, and must be0or a positive integer value of at least32.
β JAIL CONFIGURATION FILE(S) (jail.conf) β
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.
it is also possible to specify or to overwrite any option of filter file directly in jail (see section FILTER FILES).
filterβ name of the filter β filename of the filter in/etc/fail2ban/filter.d/without the.conf/.localextension. Only one filter can be specified.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"*last message repeated 5 time*s"otherwise it will fail to detect. This is calledRepeatedMsgReductionin rsyslog and should beOff.
skip_if_nologsβ if no logpath matches found, skip the jail by start of fail2ban ifskip_if_nologsset totrue, otherwise (default:false) start of fail2ban will fail with an error"Have not found any log file", unless the backend isautoand the jail is able to switch backend to systemd (seeautoin section Backends below).systemd_if_nologsβ if no logpath matches found, switch backendautoto systemd (see Backends section), unless disabled withsystemd_if_nologs = false(defaulttrue).logencodingβ encoding of log files used for decoding. Default value of"auto"uses current system locale.logtimezoneβ Force the time zone for log lines that don't have one.
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
banactionβ banning action (defaultiptables-multiport) typically specified in the[DEFAULT]section for all jails. This parameter will be used by the standard substitution ofactionand can be redefined central in the[DEFAULT]section insidejail.local(to apply it to all jails at once) or separately in each jail, where this substitution will be used.banaction_allportsβ the same asbanactionbut for some "allports" jails like"pam-generic"or"recidive"(defaultiptables-allports).
and that's part 1, bestie β more coming π
okay so the action option pulls action(s) from /etc/fail2ban/action.d/ without the .conf/.local extension. You can pass arguments to actions to override the default values from the [Init] section in the action file. Arguments are specified by:
[name=value,name2=value,name3="values,values"]
Values can also be quoted (required when the value includes a , or space). More than one action can be specified (in separate lines). The action-specific arguments can also affect conditional parameters, so for instance to submit different values to different chains, firstly pass the argument affecting all chains, e.g. blocktype, then for the IPv6 chain, e.g. blocktype?family=inet6. Examples:
# pass blocktype to DROP for all chains:
banaction_allports = iptables-ipset[type=allports, blocktype=DROP]
# pass different blocktype for IPv4 and IPv6 chains:
banaction = iptables-ipset[type=multiport, blocktype="REJECT --reject-with icmp-host-unreachable", blocktype?family=inet6="REJECT --reject-with icmp6-host-unreachable"]
ignoreselfβ boolean value (defaulttrue) that says banning your own IP addresses should be prevented. πignoreipβ list of IPs not to ban. They can also include a CIDR mask or be DNS (FQDN), or even a raw string (if the jail is banning IDs instead of IPs). This option works alongsideignoreself(iftrue) and doesn't need to contain the running host's own DNS/IPs. It can also contain a filename (prefixed withfile:) with entries to ignore, which will be lazy loaded to the runtime on demand by the first ban and automatically reloaded by update after a small latency. β¨ignorecommandβ command that is executed to determine if the current candidate IP for banning (or failure-ID for raw IDs) should not be banned. This option operates alongside theignoreselfandignoreipoptions. It is executed first, only if neitherignoreselfnorignoreipmatch the criteria. The IP will not be banned if the command returns successfully (exit code0). Like ACTION FILES, tags like<ip>can be included in theignorecommandvalue and will be substituted before execution.ignorecacheβ provide cache parameters (default disabled) for the ignore failure check (caching of the result fromignoreip,ignoreselfandignorecommand), syntax:
ignorecache = key="<F-USER>@<ip-host>", max-count=100, max-time=5m
ignorecommand = if [ "<F-USER>" = "technical" ] && [ "<ip-host>" = "my-host.example.com" ]; then exit 0; fi;
exit 1
This will cache the result of ignorecommand (so it does not call it repeatedly) for 5 minutes (cache time) for a maximum of 100 entries (cache size), using values substituted like user@host as cache-keys. Set option ignorecache to an empty value to disable the cache. π
bantimeβ effective ban duration (in seconds or time abbreviation format).findtimeβ time interval (in seconds or time abbreviation format) before the current time where failures will count towards a ban.maxretryβ number of failures that have to occur in the lastfindtimeseconds to ban the IP.backendβ backend to be used to detect changes in thelogpath. It defaults to"auto", which will try"pyinotify"before"polling"and may switch to"systemd"if no files matchinglogpathare found (see section Backends below). Any of these can be specified."pyinotify"is only valid on Linux systems with the"pyinotify"Python libraries. π¦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 a hostname, not an IP, is logged)..
bestie, the DNS warning is real β don't skip it just because it's giving "maybe fine" energy. π
prefregexβ regex (Python regular expression) to parse a common part contained in every message (seeprefregexin section FILTER FILES for details).failregexβ regex (Python regular expression) to be added to the filter's failregexes (seefailregexin section FILTER FILES for details). If this is useful for others using your application, please share your regular expression with the fail2ban developers by reporting an issue (see REPORTING BUGS below).ignoreregexβ regex which, if the log line matches, would cause Fail2Ban not to consider that line. This line will be ignored even if it matches afailregexof the jail or any of its filters.maxmatchesβ max number of matched log-lines the jail would hold in memory per ticket. By default it is the same value asmaxretryof the jail (or default). This option also affects values resolvable via tag<matches>in actions.
β¨ Backends β¨
Available options are listed below.
autoβ automatically selects the best suitable backend, starting with file-based ones likepyinotifyorpollingto monitor thelogpathmatching files, but it can also automatically switch to backendsystemdwhen the following is true:- no files matching
logpathfound for this jail; - no
systemd_if_nologs = falseis specified for the jail; - option
journalmatchis set for the jail or its filter (otherwise it'd be too heavy to allow all auto-jails, even if they have never been foreseen for journal monitoring);
- no files matching
Option skip_if_nologs will be ignored if we could switch backend to systemd.
pyinotifyβ requirespyinotify(a file alteration monitor) to be installed. The backend would receive modification events from a built-in Linux kernel inotify feature used to watch for changes on tracking files and directories, and therefore is better suitable for monitoring of logfiles than polling. π₯pollingβ uses a polling algorithm which does not require additional libraries.systemdβ uses the systemd python library to access the systemd journal. Specifyinglogpathis not valid for this backend and instead utilisesjournalmatchfrom the jail's associated filter config. Multiple systemd-specific flags can be passed to the backend, includingjournalpathandjournalfiles, to explicitly set the path to a directory or set of files,journalflags, which by default is1(LOCAL_ONLY) and opens the journal on the local machine only, can be set to4(SYSTEM_ONLY) withjournalflags=4to exclude user session files, ornamespace. Note thatjournalflags,journalpath,journalfilesandnamespaceare exclusive. See the python-systemd documentation for other settings and further details.
Examples:
backend = systemd[journalpath=/run/log/journal/machine-1]
backend = systemd[journalfiles="/path/to/system.journal, /path/to/user.journal"]
backend = systemd[journalflags=4, rotated=on]
To avoid a "too many open files" situation (descriptors exhaustion), fail2ban will ignore rotated journal files by default and has its own specific parameter rotated (default false), so it'd automatically retrieve the non-rotated set of journalfiles corresponding to journalflags (and journalpath if set). Thus the systemd backend works by default similar to file-based backends and can find only actual (not rotated) messages and could seek (findtime etc) maximally to the time point of the last rotation only. The same is valid for fail2ban-regex systemd-journal ..., so it will ignore messages from rotated journal files by default. To search across the whole journal you shall use fail2ban-regex systemd-journal[rotated=on] .... π
π Actions π
Each jail can be configured with only a single filter, but may have multiple actions. By default, the name of an 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]
πΈ TIME ABBREVIATION FORMAT πΈ
The time entries in fail2ban configuration (like findtime or bantime) can be provided as an integer in seconds or as a string using the special abbreviation format (e.g. 600 is the same as 10m). π°οΈ
Abbreviation tokens:
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 character is optional, so day as well as days can be used. π
You can combine multiple tokens in the format (separated with a space or without a separator), e.g.: 1y 6mo or 1d12h30m. Note that tokens m as well as mm mean minutes β for month use the abbreviation mo or mon. π«Ά
The time format can be tested using fail2ban-client:
fail2ban-client --str2sec 1d12h
π ACTION CONFIGURATION FILES (action.d/*.conf) π
okay bestie, so action files are the ones that specify which commands actually get executed to ban and unban an IP address. like the jail decides someone's being sus, and the action file is the one holding the shell commands that do the actual blocking. π
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. no cap, that's the move so your tweaks survive updates.
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.
actionstartβ command(s) executed when the jail starts.actionstopβ command(s) executed when the jail stops.actioncheckβ command(s) ran before any other action. It aims to verify if the environment is still ok.actionbanβ command(s) that bans the IP address aftermaxretrylog lines matches within lastfindtimeseconds.actionunbanβ command(s) that unbans the IP address afterbantime.
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:
timeoutβ 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 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
β¨ Action Tags β¨
The following tags are substituted in the actionban, actionunban and actioncheck (when called before actionban/actionunban) commands.
ipβ IPv4 or IPv6 IP address to be banned. e.g.192.168.0.2or2001:db8::1familyβ IP address family as a string. e.g.inet4orinet6ip-revβ Reverse DNS PTR record for the IP address, or empty string if unavailable.ip-hostβ Hostname resolved from the IP address.fidβ Failure ID (ticket identifier) for this ban event.failuresβ Number of times the failure occurred in the log file for this specific ticket. e.g.3timeβ UNIX (epoch) time of the ban. e.g.1357508484bantimeβ Effective ban duration in seconds for this ticket.bancountβ Number of times this IP address has been banned (cumulative count).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.restoredβ Flag indicating whether the ticket was restored from database (1) or is a new ban (0). Can be used in actions to skip certain operations for restored bans.F-*β Free-form match tags captured from the filter using<F-TAG>...</F-TAG>syntax infailregex. For example, if filter captures<F-USER>john</F-USER>, the tag<F-USER>will contain"john"and can be used in action commands.ipfailuresβ As perfailures, 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.ipjailfailuresβ As peripfailures, but total based on the IP's failures for the current jail only.ipmatchesβ As permatches, but includes all lines for the IP which are contained within the fail2ban persistent database across all jails. Therefore the database must be set for this tag to function.ipjailmatchesβ As peripmatches, but matches are limited to the IP and the current jail only.raw-ticketβ String representation of the raw ticket object. Primarily useful for debugging purposes.jail.bannedβ Number of currently banned IP addresses in the jail at the time of this action.jail.banned_totalβ Total cumulative number of bans that have occurred in this jail since fail2ban started.jail.foundβ Number of current failure tickets in the jail's fail manager.jail.found_totalβ Total cumulative number of failures that have been detected in this jail since fail2ban started.
π PYTHON ACTION FILES π
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 FILES (filter.d/*.conf) β¨
Okay bestie, filter definitions are the ones chilling in /etc/fail2ban/filter.d/*.conf and filter.d/*.local.
They're the little detectives that identify failed authentication attempts in log files and 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.
π΅οΈββοΈ The standard [Definition] crew π΅οΈββοΈ
There are several standard filter definitions used in the [Definition] section:
prefregexβ is the regex (regular expression) to parse a common part contained in every message, which is applied afterdatepatternfound a match, before the search for anyfailregexorignoreregexwould start. If this regex doesn't match, the process starts immediately with the next message and search for anyfailregexdoes not occur. Ifprefregexcontains<F-CONTENT>...</F-CONTENT>, the part of the message enclosed between these tags will be extracted and thereafter used as the whole message for search withfailregexorignoreregex.
For example:
prefregex = ^%(__prefix_line)s (?:ERROR|FAILURE) <F-CONTENT>.+</F-CONTENT>$
failregex = ^user not found
^authentication failed
^unknown authentication method
You can use prefregex in order to:
- specify one common regex to match some common part present in every message (do avoid unneeded match in every
failregexif you have more as one); - cut some interesting part of the message only (to simplify
failregex) enclosed between tags<F-CONTENT>and</F-CONTENT>; - gather some failure identifier (e. g. some prefix matched by
<F-MLFID>...<F-MLFID/>tag) to identify several messages belonging to the same session, where a connect message containing IP followed by failure message(s) that are not contain IP; this provides a new multi-line parsing method as replacement for old (slow an ugly) multi-line parsing using buffering window (maxlines > 1and<SKIPLINES>); - ignore some wrong, too long or even unneeded messages (a.k.a. parasite log traffic) which can be also present in journal, before
failregexsearch would take place.
failregexβ is the regex (regular expression) that will match failed attempts. The standard replacement tags can be used as part of the regex:<HOST>β common regex for IP addresses and hostnames (ifusednsis enabled). Fail2Ban will work out which one of these it actually is.<ADDR>β regex for IP addresses (both families).<IP4>β regex for IPv4 addresses.<IP6>β regex for IPv6 addresses.<DNS>β regex to match hostnames.<CIDR>β helper regex to match CIDR (simple integer form of net-mask).<SUBNET>β regex to match sub-net addresses (in form of IP/CIDR, also single IP is matched, so part/CIDRis optional).<F-ID>...</F-ID>β free regex capturing group targeting identifier used for ban (instead of IP address or hostname).<F-*>...</F-*>β free regex capturing named group stored in ticket, which can be used in action. For example<F-USER>[^@]+</F-USER>matches and stores a user name, that can be used in action with interpolation tag<F-USER>.<F-ALT_*n>...</F-ALT_*n>β free regex capturing alternative named group stored in ticket. For example first found matched value defined in regex as<F-ALT_USER>,<F-ALT_USER1>or<F-ALT_USER2>would be stored as<F-USER>(if direct match is not found or empty).
Every of the abovementioned tags can be specified in prefregex and in failregex, thereby if specified in both, the value matched in failregex overwrites a value matched in prefregex. All standard tags like IP4 or IP6 can be also specified with custom regex using <F-*>...</F-*> syntax, for example (?:ip4:<F-IP4>\S+</F-IP4>|ip6:<F-IP6>\S+</F-IP6>). Tags <ADDR>, <HOST> and <SUBNET> would also match the IP address enclosed in square brackets.
NOTE: thefailregexwill be applied to the remaining part of the message afterprefregexprocessing (if specified), which in turn takes place afterdatepatternprocessing (whereby the string of timestamp matching the best pattern, cut out from the message).
For multiline regexs (parsing with maxlines greater that 1) the tag <SKIPLINES> can 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. This is obsolete handling and if the lines contain some common identifier, better would be to use new handling (with tags <F-MLFID>...<F-MLFID/>).
ignoreregexβ is the regex to identify log entries that should be ignored by Fail2Ban, even if they matchfailregex.maxlinesβ 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.datepatternβ 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 forstrptimebehaviour.
NOTE: due to config file string substitution, that%'s must be escaped by an%in config files.
Also, special values of Epoch (UNIX Timestamp), TAI64N and ISO8601 can be used as datepattern. Normally the regexp generated for datepattern additionally gets word-start and word-end boundaries to avoid accidental match inside of some word in a message. There are several prefixes and words with special meaning that could be specified with custom datepattern to control the resulting regex:
{DEFAULT}β can be used to add default date patterns of fail2ban.{DATE}β can be used as part of regex that will be replaced with default date patterns.{^LN-BEG}β prefix (similar to^) changing word-start boundary to line-start boundary (ignoring up to 2 characters). If used as value (not as a prefix), it will also set all default date patterns (similar to{DEFAULT}), but anchored at begin of message line.{UNB}β prefix to disable automatic word boundaries in regex.{NONE}β value would allow one to find failures totally without date-time in log message. Filter will use now as a timestamp (or last known timestamp from previous line with timestamp).
journalmatchβ specifies the systemd journal match used to filter the journal entries. Seejournalctl(1)andsystemd.journal-fields(7)for matches syntax and more details on special journal fields. This option is only applied by thesystemdandautobackends and it is mandatory for automatic switch tosystemdbyautobackend.
Similar to actions, filters may have an [Init] section also (optional since v.0.10). All parameters of both sections [Definition] and [Init] can be overridden (redefined or extended) in jail.conf or jail.local (or in related filter.d/filter-name.local). Every option supplied in the jail to the filter overwrites the value specified in [Init] section, which in turn would overwrite the value in [Definition] section. Besides the standard settings of filter both sections can be used to initialize filter-specific options.
Filters can also have a section called [INCLUDES]. This is used to read other configuration files.
beforeβ indicates that this file is read before the[Definition]section.afterβ indicates that this file is read after the[Definition]section.
π AUTHOR π
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.
π REPORTING BUGS π
Report bugs to https://github.com/fail2ban/fail2ban/issues
π COPYRIGHT π
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.
π SEE ALSO π
π That's the whole manual, bestie β brought to you by Fail2Ban, November 2015, for JAIL.CONF(5). Mwah! πβ¨
π¦ where this page comes from
- arch rolling: fail2ban 1.1.1-1 Β· GPL-2.0-or-later
- nixpkgs unstable: fail2ban 1.1.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms