1JAIL.CONF(5) Fail2Ban Configuration JAIL.CONF(5)
2
3
4
6 jail.conf - configuration for the fail2ban server
7
9 fail2ban.conf fail2ban.d/*.conf fail2ban.local fail2ban.d/*.local
10
11 jail.conf jail.d/*.conf jail.local jail.d/*.local
12
13 action.d/*.conf action.d/*.local action.d/*.py
14
15 filter.d/*.conf filter.d/*.local
16
17
19 Fail2ban has four configuration file types:
20
21
22 fail2ban.conf
23 Fail2Ban global configuration (such as logging)
24
25 filter.d/*.conf
26 Filters specifying how to detect authentication failures
27
28 action.d/*.conf
29 Actions defining the commands for banning and unbanning of IP
30 address
31
32 jail.conf
33 Jails defining combinations of Filters with Actions.
34
35
36
38 *.conf files are distributed by Fail2Ban. It is recommended that
39 *.conf files should remain unchanged to ease upgrades. If needed, cus‐
40 tomizations should be provided in *.local files. For example, if you
41 would like to enable the [ssh-iptables-ipset] jail specified in
42 jail.conf, create jail.local containing
43
44
45 jail.local
46 [ssh-iptables-ipset]
47
48 enabled = true
49
50
51 In .local files specify only the settings you would like to change and
52 the rest of the configuration will then come from the corresponding
53 .conf file which is parsed first.
54
55
56 jail.d/ and fail2ban.d/
57
58 In addition to .local, for jail.conf or fail2ban.conf file there
59 can be a corresponding .d/ directory containing additional .conf
60 files. The order e.g. for jail configuration would be:
61
62 jail.conf
63 jail.d/*.conf (in alphabetical order)
64 jail.local
65 jail.d/*.local (in alphabetical order).
66
67 i.e. all .local files are parsed after .conf files in the origi‐
68 nal configuration file and files under .d directory. Settings
69 in the file parsed later take precedence over identical entries
70 in previously parsed files. Files are ordered alphabetically,
71 e.g.
72
73 fail2ban.d/01_custom_log.conf - to use a different log path
74 jail.d/01_enable.conf - to enable a specific jail
75 jail.d/02_custom_port.conf - to change the port(s) of a jail.
76
77 Configuration files have sections, those specified with [section name],
78 and name = value pairs. For those name items that can accept multiple
79 values, specify the values separated by spaces, or in separate lines
80 space indented at the beginning of the line before the second value.
81
82
83 Configuration files can include other (defining common variables) con‐
84 figuration files, which is often used in Filters and Actions. Such
85 inclusions are defined in a section called [INCLUDES]:
86
87
88 before indicates that the specified file is to be parsed before the
89 current file.
90
91 after indicates that the specified file is to be parsed after the cur‐
92 rent file.
93
94 Using Python "string interpolation" mechanisms, other definitions are
95 allowed and can later be used within other definitions as %(name)s.
96
97 Fail2ban has more advanced syntax (similar python extended interpola‐
98 tion). This extended interpolation is using %(section/parameter)s to
99 denote a value from a foreign section.
100 Besides cross section interpolation the value of parameter in [DEFAULT]
101 section can be retrieved with %(default/parameter)s.
102 Fail2ban supports also another feature named %(known/parameter)s (means
103 last known option with name parameter). This interpolation makes possi‐
104 ble to extend a stock filter or jail regexp in .local file (opposite to
105 simply set failregex/ignoreregex that overwrites it), e.g.
106
107 baduseragents = IE|wget|%(my-settings/baduseragents)s
108 failregex = %(known/failregex)s
109 useragent=%(baduseragents)s
110
111 Additionally to interpolation %(known/parameter)s, that does not works
112 for filter/action init parameters, an interpolation tag <known/parame‐
113 ter> can be used (means last known init definition of filters or
114 actions with name parameter). This interpolation makes possible to
115 extend a parameters of stock filter or action directly in jail inside
116 jail.conf/jail.local file without creating a separately fil‐
117 ter.d/*.local file, e.g.
118
119 # filter.d/test.conf:
120 [Init]
121 test.method = GET
122 baduseragents = IE|wget
123 [Definition]
124 failregex = ^%(__prefix_line)\s+"<test.method>"\s+test\s+regexp\s+-\s+useragent=(?:<baduseragents>)
125
126 # jail.local:
127 [test]
128 # use filter "test", overwrite method to "POST" and extend known bad agents with "badagent":
129 filter = test[test.method=POST, baduseragents="badagent|<known/baduseragents>"]
130
131 Comments: use '#' for comment lines and '; ' (space is important) for
132 inline comments. When using Python2.X, '; ' can only be used on the
133 first line due to an Python library bug.
134
135
137 The items that can be set in section [Definition] are:
138
139 loglevel
140 verbosity level of log output: CRITICAL, ERROR, WARNING, NOTICE,
141 INFO, DEBUG, TRACEDEBUG, HEAVYDEBUG or corresponding numeric
142 value (50-5). Default: ERROR (equal 40)
143
144 logtarget
145 log target: filename, SYSLOG, STDERR or STDOUT. Default: STDOUT
146 if not set in fail2ban.conf/fail2ban.local
147 Note. If fail2ban running as systemd-service, for logging to the
148 systemd-journal, the logtarget could be set to STDOUT
149 Only a single log target can be specified. If you change log‐
150 target from the default value and you are using logrotate --
151 also adjust or disable rotation in the corresponding configura‐
152 tion file (e.g. /etc/logrotate.d/fail2ban on Debian systems).
153
154 socket socket filename. Default: /var/run/fail2ban/fail2ban.sock
155 This is used for communication with the fail2ban server daemon.
156 Do not remove this file when Fail2ban is running. It will not be
157 possible to communicate with the server afterwards.
158
159 pidfile
160 PID filename. Default: /var/run/fail2ban/fail2ban.pid
161 This is used to store the process ID of the fail2ban server.
162
163 dbfile Database filename. Default: /var/lib/fail2ban/fail2ban.sqlite3
164 This defines where the persistent data for fail2ban is stored.
165 This persistent data allows bans to be reinstated and continue
166 reading log files from the last read position when fail2ban is
167 restarted. A value of None disables this feature.
168
169 dbmaxmatches
170 Max number of matches stored in database per ticket. Default: 10
171 This option sets the max number of matched log-lines could be
172 stored per ticket in the database. This also affects values
173 resolvable via tags <ipmatches> and <ipjailmatches> in actions.
174
175 dbpurgeage
176 Database purge age in seconds. Default: 86400 (24hours)
177 This sets the age at which bans should be purged from the data‐
178 base.
179
180 The config parameters of section [Thread] are:
181
182
183 stacksize
184 Stack size of each thread in fail2ban. Default: 0 (platform or
185 configured default)
186 This specifies the stack size (in KiB) to be used for subse‐
187 quently created threads, and must be 0 or a positive integer
188 value of at least 32.
189
190
192 The following options are applicable to any jail. They appear in a sec‐
193 tion specifying the jail name or in the [DEFAULT] section which defines
194 default values to be used if not specified in the individual section.
195
196 filter name of the filter -- filename of the filter in
197 /etc/fail2ban/filter.d/ without the .conf/.local extension.
198 Only one filter can be specified.
199
200 logpath
201 filename(s) of the log files to be monitored, separated by new
202 lines.
203 Globs -- paths containing * and ? or [0-9] -- can be used how‐
204 ever only the files that exist at start up matching this glob
205 pattern will be considered.
206
207 Optional space separated option 'tail' can be added to the end
208 of the path to cause the log file to be read from the end, else
209 default 'head' option reads file from the beginning
210
211 Ensure syslog or the program that generates the log file isn't
212 configured to compress repeated log messages to "*last message
213 repeated 5 time*s" otherwise it will fail to detect. This is
214 called RepeatedMsgReduction in rsyslog and should be Off.
215
216 logencoding
217 encoding of log files used for decoding. Default value of "auto"
218 uses current system locale.
219
220 logtimezone
221 Force the time zone for log lines that don't have one.
222
223 If this option is not specified, log lines from which no
224 explicit time zone has been found are interpreted by fail2ban in
225 its own system time zone, and that may turn to be inappropriate.
226 While the best practice is to configure the monitored applica‐
227 tions to include explicit offsets, this option is meant to han‐
228 dle cases where that is not possible.
229
230 The supported time zones in this option are those with fixed
231 offset: Z, UTC[+-]hhmm (you can also use GMT as an alias to
232 UTC).
233
234 This option has no effect on log lines on which an explicit time
235 zone has been found. Examples:
236
237 logtimezone = UTC
238 logtimezone = UTC+0200
239 logtimezone = GMT-0100
240
241
242 banaction
243 banning action (default iptables-multiport) typically specified
244 in the [DEFAULT] section for all jails.
245 This parameter will be used by the standard substitution of
246 action and can be redefined central in the [DEFAULT] section
247 inside jail.local (to apply it to all jails at once) or sepa‐
248 rately in each jail, where this substitution will be used.
249
250 banaction_allports
251 the same as banaction but for some "allports" jails like "pam-
252 generic" or "recidive" (default iptables-allports).
253
254 action action(s) from /etc/fail2ban/action.d/ without the .conf/.local
255 extension.
256 Arguments can be passed to actions to override the default val‐
257 ues from the [Init] section in the action file. Arguments are
258 specified by:
259
260 [name=value,name2=value,name3="values,values"]
261
262 Values can also be quoted (required when value includes a ",").
263 More that one action can be specified (in separate lines).
264
265 ignoreself
266 boolean value (default true) indicates the banning of own IP
267 addresses should be prevented
268
269 ignoreip
270 list of IPs not to ban. They can include a DNS resp. CIDR mask
271 too. The option affects additionally to ignoreself (if true) and
272 don't need to contain own DNS resp. IPs of the running host.
273
274 ignorecommand
275 command that is executed to determine if the current candidate
276 IP for banning (or failure-ID for raw IDs) should not be banned.
277 The option affects additionally to ignoreself and ignoreip and
278 will be first executed if both don't hit.
279 IP will not be banned if command returns successfully (exit code
280 0). Like ACTION FILES, tags like <ip> are can be included in
281 the ignorecommand value and will be substituted before execu‐
282 tion.
283
284 ignorecache
285 provide cache parameters (default disabled) for ignore failure
286 check (caching of the result from `ignoreip`, `ignoreself` and
287 `ignorecommand`), syntax:
288
289 ignorecache = key="<F-USER>@<ip-host>", max-count=100, max-time=5m
290 ignorecommand = if [ "<F-USER>" = "technical" ] && [ "<ip-host>" = "my-host.example.com" ]; then exit 0; fi;
291 exit 1
292 This will cache the result of ignorecommand (does not call it
293 repeatedly) for 5 minutes (cache time) for maximal 100 entries
294 (cache size), using values substituted like "user@host" as
295 cache-keys. Set option ignorecache to empty value disables the
296 cache.
297
298 bantime
299 effective ban duration (in seconds or time abbreviation format).
300
301 findtime
302 time interval (in seconds or time abbreviation format) before
303 the current time where failures will count towards a ban.
304
305 maxretry
306 number of failures that have to occur in the last findtime sec‐
307 onds to ban then IP.
308
309 backend
310 backend to be used to detect changes in the logpath.
311 It defaults to "auto" which will try "pyinotify", "gamin", "sys‐
312 temd" before "polling". Any of these can be specified. "pyino‐
313 tify" is only valid on Linux systems with the "pyinotify" Python
314 libraries. "gamin" requires the "gamin" libraries.
315
316 usedns use DNS to resolve HOST names that appear in the logs. By
317 default it is "warn" which will resolve hostnames to IPs however
318 it will also log a warning. If you are using DNS here you could
319 be blocking the wrong IPs due to the asymmetric nature of
320 reverse DNS (that the application used to write the domain name
321 to log) compared to forward DNS that fail2ban uses to resolve
322 this back to an IP (but not necessarily the same one). Ideally
323 you should configure your applications to log a real IP. This
324 can be set to "yes" to prevent warnings in the log or "no" to
325 disable DNS resolution altogether (thus ignoring entries where
326 hostname, not an IP is logged)..
327
328 failregex
329 regex (Python regular expression) to be added to the filter's
330 failregexes (see failregex in section FILTER FILES for details).
331 If this is useful for others using your application please share
332 you regular expression with the fail2ban developers by reporting
333 an issue (see REPORTING BUGS below).
334
335 ignoreregex
336 regex which, if the log line matches, would cause Fail2Ban not
337 consider that line. This line will be ignored even if it
338 matches a failregex of the jail or any of its filters.
339
340 maxmatches
341 max number of matched log-lines the jail would hold in memory
342 per ticket. By default it is the same value as maxretry of jail
343 (or default). This option also affects values resolvable via
344 tag <matches> in actions.
345
346
347 Backends
348 Available options are listed below.
349
350 pyinotify
351 requires pyinotify (a file alteration monitor) to be installed.
352 If pyinotify is not installed, Fail2ban will use auto.
353
354 gamin requires Gamin (a file alteration monitor) to be installed. If
355 Gamin is not installed, Fail2ban will use auto.
356
357 polling
358 uses a polling algorithm which does not require external
359 libraries.
360
361 systemd
362 uses systemd python library to access the systemd journal. Spec‐
363 ifying logpath is not valid for this backend and instead
364 utilises journalmatch from the jails associated filter config.
365
366
367 Actions
368 Each jail can be configured with only a single filter, but may have
369 multiple actions. By default, the name of a action is the action file‐
370 name, and in the case of Python actions, the ".py" file extension is
371 stripped. Where multiple of the same action are to be used, the actname
372 option can be assigned to the action to avoid duplication e.g.:
373
374 [ssh-iptables-ipset]
375 enabled = true
376 action = smtp.py[dest=chris@example.com, actname=smtp-chris]
377 smtp.py[dest=sally@example.com, actname=smtp-sally]
378
379
381 The time entries in fail2ban configuration (like findtime or bantime)
382 can be provided as integer in seconds or as string using special abbre‐
383 viation format (e. g. 600 is the same as 10m).
384
385
386 Abbreviation tokens:
387
388 years?, yea?, yy?
389 months?, mon?
390 weeks?, wee?, ww?
391 days?, da, dd?
392 hours?, hou?, hh?
393 minutes?, min?, mm?
394 seconds?, sec?, ss?
395
396 The question mark (?) means the optional character, so day as well as days can be used.
397
398 You can combine multiple tokens in format (separated with space resp.
399 without separator), e. g.: 1y 6mo or 1d12h30m.
400 Note that tokens m as well as mm means minutes, for month use abbrevia‐
401 tion mo or mon.
402
403 The time format can be tested using fail2ban-client:
404
405 fail2ban-client --str2sec 1d12h
406
407
409 Action files specify which commands are executed to ban and unban an IP
410 address.
411
412 Like with jail.conf files, if you desire local changes create an
413 [actionname].local file in the /etc/fail2ban/action.d directory and
414 override the required settings.
415
416 Action files have two sections, Definition and Init .
417
418 The [Init] section enables action-specific settings. In
419 jail.conf/jail.local these can be overridden for a particular jail as
420 options of the action's specification in that jail.
421
422 The following commands can be present in the [Definition] section.
423
424 actionstart
425 command(s) executed when the jail starts.
426
427 actionstop
428 command(s) executed when the jail stops.
429
430 actioncheck
431 command(s) ran before any other action. It aims to verify if the
432 environment is still ok.
433
434 actionban
435 command(s) that bans the IP address after maxretry log lines
436 matches within last findtime seconds.
437
438 actionunban
439 command(s) that unbans the IP address after bantime.
440
441 The [Init] section allows for action-specific settings. In
442 jail.conf/jail.local these can be overwritten for a particular jail as
443 options to the jail. The following are special tags which can be set in
444 the [Init] section:
445
446 timeout
447 The maximum period of time in seconds that a command can exe‐
448 cuted, before being killed.
449
450 Commands specified in the [Definition] section are executed through a
451 system shell so shell redirection and process control is allowed. The
452 commands should return 0, otherwise error would be logged. Moreover if
453 actioncheck exits with non-0 status, it is taken as indication that
454 firewall status has changed and fail2ban needs to reinitialize itself
455 (i.e. issue actionstop and actionstart commands). Tags are enclosed in
456 <>. All the elements of [Init] are tags that are replaced in all
457 action commands. Tags can be added by the fail2ban-client using the
458 "set <JAIL> action <ACT>" command. <br> is a tag that is always a new
459 line (\n).
460
461 More than a single command is allowed to be specified. Each command
462 needs to be on a separate line and indented with whitespace(s) without
463 blank lines. The following example defines two commands to be executed.
464
465 actionban = iptables -I fail2ban-<name> --source <ip> -j DROP
466 echo ip=<ip>, match=<match>, time=<time> >>
467 /var/log/fail2ban.log
468
469
470 Action Tags
471 The following tags are substituted in the actionban, actionunban and
472 actioncheck (when called before actionban/actionunban) commands.
473
474 ip IPv4 IP address to be banned. e.g. 192.168.0.2
475
476 failures
477 number of times the failure occurred in the log file. e.g. 3
478
479 ipfailures
480 As per failures, but total of all failures for that ip address
481 across all jails from the fail2ban persistent database. There‐
482 fore the database must be set for this tag to function.
483
484 ipjailfailures
485 As per ipfailures, but total based on the IPs failures for the
486 current jail.
487
488 time UNIX (epoch) time of the ban. e.g. 1357508484
489
490 matches
491 concatenated string of the log file lines of the matches that
492 generated the ban. Many characters interpreted by shell get
493 escaped to prevent injection, nevertheless use with caution.
494
495 ipmatches
496 As per matches, but includes all lines for the IP which are con‐
497 tained with the fail2ban persistent database. Therefore the
498 database must be set for this tag to function.
499
500 ipjailmatches
501 As per ipmatches, but matches are limited for the IP and for the
502 current jail.
503
504
506 Python based actions can also be used, where the file name must be
507 [actionname].py. The Python file must contain a variable Action which
508 points to Python class. This class must implement a minimum interface
509 as described by fail2ban.server.action.ActionBase, which can be inher‐
510 ited from to ease implementation.
511
512
514 Filter definitions are those in /etc/fail2ban/filter.d/*.conf and fil‐
515 ter.d/*.local.
516
517 These are used to identify failed authentication attempts in log files
518 and to extract the host IP address (or hostname if usedns is true).
519
520 Like action files, filter files are ini files. The main section is the
521 [Definition] section.
522
523 There are two filter definitions used in the [Definition] section:
524
525 failregex
526 is the regex (regular expression) that will match failed
527 attempts. The standard replacement tags can be used as part of
528 the regex:
529
530 <HOST> - common regex for IP addresses and hostnames (if
531 usedns is enabled). Fail2Ban will work out which one of
532 these it actually is.
533
534 <ADDR> - regex for IP addresses (both families).
535
536 <IP4> - regex for IPv4 addresses.
537
538 <IP6> - regex for IPv6 addresses (also IP enclosed in
539 brackets).
540
541 <DNS> - regex to match hostnames.
542
543 <CIDR> - helper regex to match CIDR (simple integer form
544 of net-mask).
545
546 <SUBNET> - regex to match sub-net adresses (in form of
547 IP/CIDR, also single IP is matched, so part /CIDR is
548 optional).
549
550 For multiline regexs the tag <SKIPLINES> should be used to separate
551 lines. This allows lines between the matched lines to continue to be
552 searched for other failures. The tag can be used multiple times.
553
554
555 ignoreregex
556 is the regex to identify log entries that should be ignored by
557 Fail2Ban, even if they match failregex.
558
559
560
561 Similar to actions, filters have an [Init] section which can be over‐
562 ridden in jail.conf/jail.local. Besides the filter-specific settings,
563 the filter [Init] section can be used to set following standard
564 options:
565
566 maxlines
567 specifies the maximum number of lines to buffer to match multi-
568 line regexs. For some log formats this will not required to be
569 changed. Other logs may require to increase this value if a par‐
570 ticular log file is frequently written to.
571
572 datepattern
573 specifies a custom date pattern/regex as an alternative to the
574 default date detectors e.g. %Y-%m-%d %H:%M(?::%S)?. For a list
575 of valid format directives, see Python library documentation for
576 strptime behaviour.
577 Also, special values of Epoch (UNIX Timestamp), TAI64N and
578 ISO8601 can be used.
579 NOTE: due to config file string substitution, that %'s must be
580 escaped by an % in config files.
581
582 journalmatch
583 specifies the systemd journal match used to filter the journal
584 entries. See journalctl(1) and systemd.journal-fields(7) for
585 matches syntax and more details on special journal fields. This
586 option is only valid for the systemd backend.
587
588 Similar to actions [Init] section enables filter-specific settings. All
589 parameters specified in [Init] section can be redefined or extended in
590 jail.conf/jail.local.
591
592 Filters can also have a section called [INCLUDES]. This is used to read
593 other configuration files.
594
595
596 before indicates that this file is read before the [Definition] sec‐
597 tion.
598
599
600 after indicates that this file is read after the [Definition] section.
601
602
604 Fail2ban was originally written by Cyril Jaquier
605 <cyril.jaquier@fail2ban.org>. At the moment it is maintained and fur‐
606 ther developed by Yaroslav O. Halchenko <debian@onerussian.com>, Daniel
607 Black <daniel.subs@internode.on.net> and Steven Hiscocks <steven-
608 fail2ban@hiscocks.me.uk> along with a number of contributors. See
609 THANKS file shipped with Fail2Ban for a full list. Manual page written
610 by Daniel Black and Yaroslav Halchenko.
611
613 Report bugs to https://github.com/fail2ban/fail2ban/issues
614
616 Copyright © 2013 the Fail2Ban Team
617 Copyright of modifications held by their respective authors.
618 Licensed under the GNU General Public License v2 (GPL) or (at your
619 option) any later version.
620
622 fail2ban-server(1)
623
624
625
626Fail2Ban November 2015 JAIL.CONF(5)