Fail2ban is a common security tool that monitors authentication logs and temporarily bans IP addresses that show malicious patterns (for example, repeated failed SSH logins).
This article covers a typical setup for Ubuntu/Debian. Commands may differ on other distributions.
sudo apt update
sudo apt -y install fail2ban
Do not edit jail.conf directly. Create jail.local instead:
sudo nano /etc/fail2ban/jail.local
Example configuration for SSH (sshd):
[sshd]
enabled = true
port = ssh
maxretry = 5
findtime = 10m
bantime = 1h
Tip: If you have a fixed IP, you can whitelist it using ignoreip (be careful with this setting).
sudo systemctl enable --now fail2ban
sudo systemctl restart fail2ban
sudo fail2ban-client status
sudo fail2ban-client status sshd
sudo fail2ban-client set sshd unbanip 203.0.113.10