Protecting Your Server
Ubuntu/Debian
What is Fail2ban?
Fail2ban is a powerful security tool that acts as a digital security guard for your server. It constantly watches your system's log files looking for suspicious behavior, like someone trying to guess your password over and over again. This type of repeated guessing is called a brute-force attack, and it is one of the most common ways hackers try to break into systems.
When Fail2ban spots a bad actor making too many failed login attempts, it takes immediate action. It automatically blocks their IP address using your server's firewall rules. This means the attacker is completely locked out and cannot try to log in again until a certain amount of time has passed, keeping your server safe.
One of the best things about Fail2ban is that it works in the background without needing your constant attention. Once you set it up, it automatically handles the blocking and unblocking of IP addresses. It is highly customizable, allowing you to choose exactly how many strikes an attacker gets and how long they stay banned.
Prerequisites
- A server running a modern version of Ubuntu (like 22.04 or 24.04) or Debian (like 11 or 12).
- A user account with
sudo(administrator) privileges. - A basic understanding of how to use the command-line terminal.
- An active internet connection to download the required software.
Step-by-Step Installation
Update the System and Install Fail2ban
sudo apt update && sudo apt upgrade -y sudo apt install fail2ban python3-systemd -y
Enable and Start the Service
sudo systemctl enable --now fail2ban
sudo systemctl status fail2ban
Create the Local Configuration File
sudo nano /etc/fail2ban/jail.local
Configure the Global Settings and SSH Jail
[DEFAULT] # Tell Fail2ban to read from the modern systemd journal backend = systemd # Whitelist localhost and your own static IP (Space separated) ignoreip = 127.0.0.1/8 ::1 192.168.1.100 # How long an IP is banned (1h = 1 hour) bantime = 1h # The time window Fail2ban watches for failed attempts findtime = 10m # Number of failed attempts allowed before banning maxretry = 5 # Optional: Only uncomment on UBUNTU if you actively use UFW. # Do NOT uncomment on Debian. # banaction = ufw [sshd] # Turn on the SSH protection rules enabled = true # Change 'ssh' to your custom port number if you do not use port 22 port = ssh filter = sshd # Stricter rules for SSH logins maxretry = 3 bantime = 2h
Restart Fail2ban to Apply Changes
sudo systemctl restart fail2ban
Verify Your Configuration
sudo fail2ban-client status sudo fail2ban-client status sshd
sudo fail2ban-client set sshd unbanip 192.168.1.50
CTCservers Recommended Tutorials
Web, Network
Step-by-Step Guide: Install AMD ROCm on Ubuntu with RX 6600 GPU
Learn how to quickly and easily set up AMD ROCm on Ubuntu for your RX 6600 GPU, enabling powerful machine learning, AI workloads, and GPU-accelerated computing right on your system.
Web, Network, Linux, Mysql, Ubuntu
LAMP Setup Guide 2026: Ubuntu & Debian | CTCservers
Install a secure LAMP stack on Debian or Ubuntu. Follow our step-by-step guide to configure Linux, Apache, MySQL, and PHP for your web server.
Web, Network, Ubuntu
Deploy Phi-3 with Ollama on Ubuntu GPU | CTCservers
Learn how to easily deploy the Phi-3 LLM on an Ubuntu 24.04 GPU server using Ollama and WebUI. Follow our step-by-step tutorial for seamless AI hosting.
Discover CTCservers Dedicated Server Locations
CTCservers servers are available around the world, providing diverse options for hosting websites. Each region offers unique advantages, making it easier to choose a location that best suits your specific hosting needs.