detecting-port-scanning-with-fail2ban

Configures Fail2ban jails, filters, and iptables rules to detect and ban port scanning activity.

954|172|Updated Mar 13, 2026
One-click install
npx skills add https://github.com/xalgord/xalgorix --skill detecting-port-scanning-with-fail2ban
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: detecting-port-scanning-with-fail2ban
Source: https://github.com/xalgord/xalgorix/tree/main/internal/tools/skills/data/network-security/detecting-port-scanning-with-fail2ban
Command: npx skills add https://github.com/xalgord/xalgorix --skill detecting-port-scanning-with-fail2ban

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Internet-facing servers are constantly probed by port scanners and brute-force bots, and manually reviewing logs to block offending IPs does not scale. This Skill automates detection of port scans, SSH brute force, and HTTP vulnerability probing, then bans the source IPs at the firewall level.

Core Features & Use Cases

  • Custom Detection Filters: Creates Fail2ban filters for port scans, Nmap reconnaissance, and HTTP vulnerability probing against Nginx access logs.
  • Automated IP Banning: Configures jails with iptables ban actions, escalating ban durations, and a recidive jail for repeat offenders.
  • Alerting & Reporting: Adds webhook notifications (e.g., Slack) on ban events and a daily cron-based summary report of banned IPs.
  • Use Case: A public web server receiving thousands of daily bot probes for /wp-admin and /.env paths can automatically ban scanners after 10 hits in 5 minutes, escalate repeat offenders to 7-day bans, and notify the security team in real time.

Quick Start

Set up Fail2ban on my Ubuntu server to detect port scans and SSH brute force attempts, ban offending IPs with iptables, and send Slack alerts when bans occur.

Frequently Asked Questions about detecting-port-scanning-with-fail2ban

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I detect port scans with Fail2ban?

Create iptables rules that log SYN packets to closed ports with a PORTSCAN_DETECTED prefix, then write a Fail2ban filter matching that prefix and a jail pointing at /var/log/kern.log. Validate matches with fail2ban-regex before enabling the jail.

How to block SSH brute force attacks automatically on Linux?

Enable the built-in sshd jail in jail.local with maxretry 3, findtime 300, and a bantime of 7200 seconds. Fail2ban parses /var/log/auth.log for failed logins and bans the source IP using iptables-multiport.

Why is my Fail2ban jail not banning any IPs?

Common causes are a backend mismatch (backend = systemd reads the journal, not /var/log/kern.log), log entries never being written because an earlier iptables ACCEPT rule matched, or a filter regex that matches zero lines. Run fail2ban-regex against the actual log file to confirm non-zero matches.

Can Fail2ban detect slow or distributed port scans?

No. Fail2ban is per-source and log-driven, so nmap -T1 slow scans evade short findtime windows and distributed scans across many source IPs cannot be correlated. Pair it with a network IDS and widen findtime or add a long-window jail for slow scans.

How do I make Fail2ban bans persist after a reboot?

Install iptables-persistent and run netfilter-persistent save to preserve the iptables rules across reboots. Fail2ban itself recreates its chains on service start, but custom logging chains like PORTSCAN must be restored from saved rules.