WitMovil.El Blog de un DevOps
WitMovil.

Explorando la automatización, la tecnología móvil y la ingeniería de software eficiente.

Sistemas Operativos
Explorar
TechCodeAutomation
Nosotros
Acerca deContactoDonar
Conectar
Nuntius GitHub LinkedIn

© 2026 WitMovil

BY NUNTIUS.DEV

PrivacidadTérminosAnti-Spam

Hecho con Next.js & PocketBase

Volver al inicio

Step-by-Step Guide to Install Fail2Ban for Server Security

Jeyson Orozco
Escrito porJeyson Orozco
Ko-fi
20 de marzo de 2024
Linux
Step-by-Step Guide to Install Fail2Ban for Server Security

Fail2Ban is a must-have tool for safeguarding servers from brute-force attacks by blocking suspicious IPs automatically. In this detailed guide, we’ll walk you through every step to install, configure, and optimize Fail2Ban for automatic restarts in case of failure. Learn how to effectively enhance your VPS security with seamless IP blocking, ensuring continuous protection for your server. With clear instructions and practical tips, this guide ensures your website remains secure the right way. Stay ahead of potential threats and protect your online presence with Fail2Ban.



Tabla de Contenido

Toggle
  • 1. Install Fail2Ban
  • 2. Set Up Default Configuration
  • 3. Enable Fail2Ban on Boot
  • 4. Configure Automatic Restart
  • 5. Verify Configuration Fail2ban

1. Install Fail2Ban

To get started, update your package manager and install Fail2Ban:

Code
sudo apt update sudo apt install fail2ban

2. Set Up Default Configuration

Make a copy of the default configuration file to avoid losing changes during updates:

Code
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local

Edit the copied file to enable SSH protection:

Code
sudo nano /etc/fail2ban/jail.local
Paso 1
— Captura de pantalla 01 —

Update the [sshd] section as follows:

Code
[sshd] enabled = true port = ssh logpath = %(sshd_log)s backend = systemd

3. Enable Fail2Ban on Boot

Ensure Fail2Ban starts with your server:

Code
sudo systemctl enable fail2ban

Start and check its status:

Code
sudo systemctl start fail2ban sudo systemctl status fail2ban

4. Configure Automatic Restart

Prevent Fail2Ban from staying down in case of failure. Create an override file:

Code
sudo mkdir -p /etc/systemd/system/fail2ban.service.d/ sudo nano /etc/systemd/system/fail2ban.service.d/override.conf

Add the following lines to enable auto-restart:

Code
[Service] Restart=always RestartSec=5

Reload systemd and restart Fail2Ban:

Code
sudo systemctl daemon-reload sudo systemctl restart fail2ban

5. Verify Configuration Fail2ban

To check active jails and their statuses:

Code
sudo fail2ban-client status

For detailed information about the SSH jail:

Code
sudo fail2ban-client status sshd

With these steps, your server will be protected against brute force attacks and Fail2Ban will be set to automatically restart if it fails.

Related Questions
How can I fix the configuration error in /etc/fail2ban/jail.local
What should I do if the Fail2ban service does not start correctly
How can I check the Fail2ban logs for errors
What does error code 255/EXCEPTION mean in Fail2ban
How can I restart the Fail2ban service without errors