NCAE Mapping Hub
Overview Scoreboard Data Roles Exercised Checklists Lessons Skill Drills Practice Terminal Progress
published priority 16 20 min. 30 XP.

fail2ban. Automatic Banning of Brute-Force IPs

fail2ban is the single easiest way to shut down SSH brute-force attacks during NCAE. Install enable done. This lesson covers the three config files you care about, the one crucial whitelist entry (scoring engine), and how to unban when you accidentally lock someone out.

Objectives

Quick reference

CommandPurpose
apt-get install -y fail2ban Install
systemctl enable --now fail2ban Start + enable on boot
fail2ban-client status Which jails are active?
fail2ban-client status sshd Currently banned IPs for a jail
fail2ban-client unban <IP> Remove ban manually
fail2ban-client reload Apply config changes
tail -f /var/log/fail2ban.log Live view

Common pitfalls

How it works (walkthrough)

# /etc/fail2ban/jail.local  (NEVER edit jail.conf. always the .local override)
[DEFAULT]
bantime  = 10m
findtime = 10m
maxretry = 5
# Whitelist scoring engine + localhost so they're never banned:
ignoreip = 127.0.0.1/8 ::1 <SCORING_ENGINE_IP>/32

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

[apache-auth]
enabled = true
port    = http,https
logpath = %(apache_error_log)s

Skill drills

  1. 1. File you edit to configure fail2ban (not jail.conf)?
    /etc/fail2ban/jail.local
  2. 2. Config key that whitelists IPs from banning?
    ignoreip
  3. 3. Command to see which IPs are banned in the sshd jail?
    fail2ban-client status sshd
  4. 4. Command to remove a ban manually?
    fail2ban-client unban <IP>
  5. 5. What's the default bantime (on most distros)?
    10 minutes (600 seconds)

NCAE scoreboard patterns this lesson prevents