wiki:fail2ban_examples
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
wiki:fail2ban_examples [2022/11/11 11:34] – [See also] add web archive link to ip range block howto antisa | wiki:fail2ban_examples [2024/03/06 13:02] (current) – add example of dry run antisa | ||
---|---|---|---|
Line 13: | Line 13: | ||
logpath | logpath | ||
- | This will create a '' | + | This will create a '' |
- | | + | < |
- | failregex = client=< | + | [Definition] |
+ | failregex = ^< | ||
+ | |||
+ | ignoreregex = | ||
| | ||
- | ignoreregex = | + | datepattern = ^[^\[]*\[({DATE}) |
- | + | </ | |
- | | + | |
**< | **< | ||
Line 27: | Line 29: | ||
action is defined already in /// | action is defined already in /// | ||
</ | </ | ||
+ | |||
+ | Restart fail2ban: | ||
+ | systemctl restart fail2ban.service | ||
This will now ban http request for 60 seconds from any client if it tries to access the site on port 80 more than 4 times within 60s. It will create a new iptables chain named f2b-bloKKKED. Truncated '' | This will now ban http request for 60 seconds from any client if it tries to access the site on port 80 more than 4 times within 60s. It will create a new iptables chain named f2b-bloKKKED. Truncated '' | ||
Line 42: | Line 47: | ||
</ | </ | ||
- | ==== Troubleshooting | + | <WRAP center round important 60%> |
+ | If you are using shorewall the above chain will be deleted on shorewall restart. Consider using the shorewall action instead of iptables then. | ||
+ | </ | ||
+ | |||
+ | ===== Testing | ||
+ | |||
+ | ==== regex ==== | ||
Use '' | Use '' | ||
< | < | ||
Line 61: | Line 73: | ||
Failregex: 42 total | Failregex: 42 total | ||
|- #) [# of hits] regular expression | |- #) [# of hits] regular expression | ||
- | | 1) [42] client=< | + | | 1) [42] ^< |
`- | `- | ||
Line 78: | Line 90: | ||
< | < | ||
- | "08/Nov/2022:15:36:30 +0100" client=10.21.21.1 method=GET request="GET / HTTP/ | + | 10.21.21.1 - - [27/Dec/2022:11:57:15 +0100] "GET / HTTP/ |
- | "08/Nov/2022:15:37:35 +0100" client=10.21.21.1 method=GET request="GET / HTTP/ | + | 10.21.21.1 |
</ | </ | ||
+ | ==== dry run ==== | ||
+ | Use action '' | ||
+ | |||
+ | [bottest] | ||
+ | enabled | ||
+ | maxretry = 4 | ||
+ | findtime = 60s | ||
+ | bantime | ||
+ | action | ||
+ | # | ||
+ | logpath | ||
+ | | ||
+ | Then '' | ||
+ | |||
+ | ====== Troubleshooting ====== | ||
+ | |||
+ | |||
+ | You can check the logfile of fail2ban in /// | ||
+ | |||
+ | fail2ban-client --loglevel DEBUG start | ||
+ | |||
+ | then check the log file again. | ||
+ | ===== Timezone issue ===== | ||
+ | If you have a [[https:// | ||
+ | 2022-12-27 11: | ||
+ | 2022-12-27 11: | ||
+ | |||
+ | check your filter' | ||
+ | |||
+ | ===== Not banning after action change ===== | ||
+ | If you changed the action to be used in jail, for example from iptables to shorewall it might not work even after restart, workaround is to (re)move the sqlite database and restart e.g. | ||
+ | |||
+ | mv / | ||
====== Tested on ====== | ====== Tested on ====== | ||
* fail2ban 0.11.2 | * fail2ban 0.11.2 | ||
Line 91: | Line 136: | ||
* https:// | * https:// | ||
* man 5 jail.conf | * man 5 jail.conf | ||
+ | * [[http:// | ||
+ | * [[https:// | ||
wiki/fail2ban_examples.1668166490.txt.gz · Last modified: 2022/11/11 11:34 by antisa