Setting up Fail2ban: block brute-force attacks automatically
After a few days on the internet, take a look at journalctl -u ssh : hundreds of login attempts from foreign IPs, one every second. As long as your SSH is switched to key login , none of them gets in – but it clutters the log and eats resources. Fail2ban reads along with these logs and bans automatically whoever tries too often without success. What are we building? By the end, Fail2ban 1.1 on…
In today's increasingly connected world, it's easy to fall victim to brute-force attacks on your server. The <source> material discusses how Fail2ban, an automated system, can help mitigate such threats by monitoring SSH login attempts and blocking offending IP addresses after repeated failures.
The key points are that Fail2ban reads the SSH log files and implements a three-step process: filter, jail, and action. The filter detects failed login attempts, the jail counts and manages these attempts according to predefined rules (bantime, findtime, maxretry), and the action takes effect - typically by adding the offending IP to a firewall blocklist for a set duration.
To set up Fail2ban, the source advises installing the software using apt, configuring it in jail.local to ensure your own IP is whitelisted, and then applying the changes by reloading the Fail2ban service. Key configuration parameters include setting bantime (ban duration), findtime (window for counting attempts), and maxretry (maximum allowed failed attempts within the timeframe). Most importantly, the ignoreip setting ensures your personal IP address is excluded from being banned.
The article also covers checking the status of Fail2ban, viewing active jails and their details, and manually unban or ban IP addresses as needed using the fail2ban-client command line tool. Finally, it mentions that Debian 13 systems utilize the systemd journal as the default log source, eliminating the need for manual log path configuration.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.