Knowledge base / Security & DDoS

Blocking brute-force attacks with fail2ban or CrowdSec

Both tools read your logs and block IPs that keep failing to log in or abuse your services.

fail2ban

Simple and local. Install the package, then create /etc/fail2ban/jail.local:

[DEFAULT]
bantime  = 1h
findtime = 10m
maxretry = 5
ignoreip = 127.0.0.1/8 ::1 YOUR.OFFICE.IP

[sshd]
enabled = true

Then systemctl enable --now fail2ban and check with fail2ban-client status sshd.

CrowdSec

Works the same way, but shares attacker IPs with a community, so known attackers are blocked before they hit you. Install the agent plus a "bouncer" that does the blocking (for example the firewall bouncer):

cscli collections list
cscli decisions list

Tips