Fail2ban Ban brute-force attackers
Light · Postcard
102 × 152 mm · PDF
Dark · Postcard
102 × 152 mm · PDF
Ink saver · Postcard
102 × 152 mm · PDF
Light · A4 landscape
297 × 210 mm · PDF
Dark · A4 landscape
297 × 210 mm · PDF
Ink saver · A4 landscape
297 × 210 mm · PDF
Light · A3 landscape
420 × 297 mm · PDF
Dark · A3 landscape
420 × 297 mm · PDF
Ink saver · A3 landscape
420 × 297 mm · PDF
Start here
sudo fail2ban-client status
sudo fail2ban-client status <jail>
sudo fail2ban-client set <jail> unbanip
<ip>
sudo fail2ban-client set <jail> banip
<ip>
sudo fail2ban-client reload
fail2ban-regex <log> <filter>
sudo fail2ban-client -t
sudo systemctl status fail2ban
Concepts
- Log or journal watched by a jail
- Failure one match per IP
- Ban action runs
- Unban action undoes it
Service and config check
sudo systemctl enable --now fail2ban
sudo systemctl status fail2ban
sudo fail2ban-client ping
sudo fail2ban-client -t
sudo fail2ban-client reload
sudo fail2ban-client reload <jail>
Status and bans
sudo fail2ban-client status
sudo fail2ban-client status <jail>
sudo fail2ban-client banned
sudo fail2ban-client banned <ip>
sudo fail2ban-client set <jail> banip
<ip>
sudo fail2ban-client set <jail> unbanip
<ip>
sudo fail2ban-client unban <ip>
sudo fail2ban-client unban --all
Jails at runtime
sudo fail2ban-client start <jail>
sudo fail2ban-client stop <jail>
sudo fail2ban-client set <jail> bantime
<time>
sudo fail2ban-client set <jail> maxretry
<n>
sudo fail2ban-client set <jail> addignoreip
<ip>
Config files
/etc/fail2ban/jail.local
/etc/fail2ban/filter.d/
[DEFAULT]enabled = truebantime = 1hfindtime = 10mmaxretry = 5ignoreip = 127.0.0.1/8 ::1 <ip>
logpath = /var/log/auth.log
banaction = nftables
bantime.increment = true
Filters and testing
fail2ban-regex <logfile>
<filter-or-regex>
fail2ban-regex <logfile>
/etc/fail2ban/filter.d/sshd.conf
fail2ban-regex systemd-journal <filter>
fail2ban-regex '<log line>'
'<regex>'
fail2ban-regex --print-all-missed <logfile>
<filter>
<HOST>Logs
sudo tail -f /var/log/fail2ban.log
sudo grep Ban /var/log/fail2ban.log
sudo fail2ban-client flushlogs
Recipes
# from another route (console, other IP)sudo fail2ban-client status sshdsudo fail2ban-client set sshd unbanip <ip>sudo fail2ban-client set sshd addignoreip <ip>
# /etc/fail2ban/filter.d/myapp.conf[Definition]failregex = ^.* login failed for .* from <HOST>$fail2ban-regex /var/log/myapp.log myappfail2ban-regex --print-all-missed /var/log/myapp.log myapp
# /etc/fail2ban/jail.d/myapp.local[myapp]enabled = truefilter = myapplogpath = /var/log/myapp.logmaxretry = 3sudo fail2ban-client reload



