SECURING A DEBIAN SERVER WITH FAIL2BAN
As soon as a server becomes reachable from the Internet, it usually does not take long before the first unfriendly visitors arrive. This is no longer limited to occasional SSH login attempts. Automated scanners continuously check whether WordPress, phpMyAdmin, forgotten .env files, Git repositories, PHP debugging tools, known vulnerabilities or other exploitable services are available. And when I…
Securing a Linux server against automated attacks is crucial once it becomes accessible from the Internet. Unwanted visitors often begin with harmless requests but can escalate to harmful exploits. Fail2Ban is a useful tool that helps mitigate these threats without overloading server resources.
Fail2Ban operates by monitoring system logs for suspicious activity, such as repeated failed login attempts or repeated requests for non-existent files. When an IP address exceeds predefined limits, it is automatically blocked by the firewall for a specified period. While Fail2Ban does not replace proper server configuration or secure passwords, it effectively prevents automated scanners from wasting time attempting to exploit a server.
On a Debian server with Apache, Fail2Ban is easily installed using the package manager. After enabling and starting the Fail2Ban service, a quick check confirms its active status. The default installation includes several filters for Apache, but custom rules can be added to tailor the system to specific needs.
For instance, a custom filter can be created to detect and count Apache 403 and 404 errors. By setting a threshold for the number of matching errors within a time frame, an IP address can be automatically blocked if the limit is exceeded. The values for the threshold, time frame, and ban duration can be adjusted based on the specific website's needs.
Some requests, however, are more obvious signs of an attack. For example, an external visitor should not be searching for sensitive files like /.env, /.git/config, or /wp-config.php. These files can be specifically monitored and blocked using Fail2Ban rules. By adding custom jail configurations for these specific patterns, the server remains protected from potential exploits without unnecessary interference with legitimate visitors.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.