ServerHandbook live check: run log ------------------------------------------------------------------------------ Article https://serverhandbook.com/kb/fail2ban-ubuntu-24-04 Check scripts/live/checks/fail2ban-ubuntu-24-04.mjs (sha256 767bb221d4f766fb66fefb485cd0f8eb8c0a9601e8e9a4923eeb28f69cf5bb8a) Ran at 2026-11-11T17:27:07Z (339 s) Result PASS, all 36 claims held Tested on System Ubuntu 24.04.5 LTS Kernel 6.8.0-147-generic Package fail2ban 1.0.2-3ubuntu0.1 Package python3 3.12.3-0ubuntu2.1 Package nftables 1.0.9-1ubuntu0.1 Package openssh-server 1:9.6p1-3ubuntu13.20 Setup A fresh Ubuntu 24.04 server with the UFW firewall on (SSH allowed), reached over SSH as a sudo user. The failed logins came from two other computers on its network, 198.51.100.2 and 192.0.2.2. Every version above was read from the server at run time. Passwords used on the throwaway test server are shown as [password]. How we test: https://serverhandbook.com/how-we-test ------------------------------------------------------------------------------ Claims (36), each with what the run saw ------------------------------------------------------------------------------ 1. ok a bare Ubuntu 24.04 server box (web-server) starts 2. ok (setup) the bot computer reaches the server’s SSH and is refused a login (no key) | admin@203.0.113.10: Permission denied (publickey). 3. ok the starting server has ufw on with SSH allowed | Status: active | | To Action From | -- ------ ---- | OpenSSH ALLOW Anywhere | OpenSSH (v6) ALLOW Anywhere (v6) 4. ok apt update reads the package lists | 340 B] | Get:51 http://archive.ubuntu.com/ubuntu noble-backports/multiverse amd64 Components [212 B] | Get:52 http://archive.ubuntu.com/ubuntu noble-backports/multiverse amd64 c-n-f Metadata [116 B] | Fetched 38.1 MB in 3min 15s (196 kB/s) | Reading package lists... Done | Building dependency tree... Done | Reading state information... Done | 42 packages can be upgraded. Run 'apt list --upgradable' to see them. 5. ok apt install -y fail2ban installs it | ain | grep -oP '@addr6-set-j-w-nft-ap\s+.*\s+\Khandle\s+(\d+)$'; } | while read -r hdl; do`", | Created symlink /etc/systemd/system/multi-user.target.wants/fail2ban.service → /usr/lib/systemd/system/fail2ban.service. | Setting up python3-pyinotify (0.9.6-2ubuntu1) ... | Processing triggers for man-db (2.12.0-4build2) ... | Scanning processes... | Scanning linux images... | | Running kernel seems to be up-to-date. | | No services need to be restarted. | | No containers need to be restarted. | | No user sessions are running outdated binaries. | | No VM guests are running outdated hypervisor (qemu) binaries on this host. 6. ok it pulls in python3-pyasyncore (the module Python 3.12 no longer ships) | Reading package lists... Done | Building dependency tree... Done | Reading state information... Done | The following additional packages will be installed: | python3-pyasyncore python3-pyinotify whois | Suggested packages: | mailx monit sqlite3 python-pyinotify-doc | The following NEW packages will be installed: | fail2ban python3-pyasyncore python3-pyinotify whois | 0 upgraded, 4 newly installed, 0 to remove and 42 not upgraded. | Need to get 496 kB of archives. | After this operation, 2572 kB of additional disk space will be used. | Get:1 http://archive.ubuntu.com/ubuntu noble/main amd64 python3-pyasyncore al 7. ok the service is enabled and active (running) straight after install | ● fail2ban.service - Fail2Ban Service | Loaded: loaded (/usr/lib/systemd/system/fail2ban.service; enabled; preset: enabled) | Active: active (running) since Wed 2026-11-11 17:31:36 UTC; 3s ago | Docs: man:fail2ban(1) | Main PID: 2959 (fail2ban-server) | Tasks: 5 (limit: 2315) | Memory: 20.7M (peak: 21.1M) | CPU: 186ms | CGroup: /system.slice/fail2ban.service | └─2959 /usr/bin/python3 /usr/bin/fail2ban-server -xf start | | Nov 11 17:31:36 web-server systemd[1]: Started fail2ban.service - Fail2Ban …ice. | Nov 11 17:31:36 web-server fail2ban-server[2959]: 2026-11-11 17:31:36,404 fa…to' | Nov 11 17:31:36 web-server fail2ban-server[2959]: Server ready | Hint: Some lines were ellipsized, use -l to show in full. 8. ok the installed version is the fixed update 1.0.2-3ubuntu0.1, not the release’s 1.0.2-3 | fail2ban: | Installed: 1.0.2-3ubuntu0.1 | Candidate: 1.0.2-3ubuntu0.1 | Version table: | *** 1.0.2-3ubuntu0.1 500 | 500 http://archive.ubuntu.com/ubuntu noble-updates/universe amd64 Packages | 100 /var/lib/dpkg/status | 1.0.2-3 500 | 500 http://archive.ubuntu.com/ubuntu noble/universe amd64 Packages 9. ok Ubuntu enables the sshd jail, reads the systemd journal and bans with nftables | [DEFAULT] | banaction = nftables | banaction_allports = nftables[type=allports] | backend = systemd | | [sshd] | enabled = true 10. ok fail2ban-client status lists one jail: sshd | Status | |- Number of jail: 1 | `- Jail list: sshd 11. ok the defaults: 5 tries in 600 s (10 min) gets a 600 s (10 min) ban | 5 | 600 | 600 12. ok the bot’s 5 tries all reach sshd and are refused | admin@203.0.113.10: Permission denied (publickey). | admin@203.0.113.10: Permission denied (publickey). | admin@203.0.113.10: Permission denied (publickey). | admin@203.0.113.10: Permission denied (publickey). | admin@203.0.113.10: Permission denied (publickey). 13. ok sshd logs each try as "Invalid user admin from 198.51.100.2" | Nov 11 17:31:43 web-server sshd[3602]: Invalid user admin from 198.51.100.2 port 59950 | Nov 11 17:31:43 web-server sshd[3667]: Invalid user admin from 198.51.100.2 port 59966 14. ok after 5 failures the sshd jail has banned 198.51.100.2 | Status for the jail: sshd | |- Filter | | |- Currently failed: 1 | | |- Total failed: 6 | | `- Journal matches: _SYSTEMD_UNIT=sshd.service + _COMM=sshd | `- Actions | |- Currently banned: 1 | |- Total banned: 1 | `- Banned IP list: 198.51.100.2 15. ok /var/log/fail2ban.log: NOTICE [sshd] Ban 198.51.100.2 | 2026-11-11 17:31:43,782 fail2ban.actions [2959]: NOTICE [sshd] Ban 198.51.100.2 16. ok the banned computer now gets "Connection refused" (not a login prompt) | ssh: connect to host 203.0.113.10 port 22: Connection refused 17. ok the ban is an nftables set with a reject rule at priority filter - 1, before ufw’s rules | table inet f2b-table { | set addr-set-sshd { | type ipv4_addr | elements = { 198.51.100.2 } | } | | chain f2b-chain { | type filter hook input priority filter - 1; policy accept; | tcp dport 22 ip saddr @addr-set-sshd reject with icmp port-unreachable | } | } 18. ok ufw still lists SSH as allowed: the ban is not a ufw rule | Status: active | | To Action From | -- ------ ---- | OpenSSH ALLOW Anywhere | OpenSSH (v6) ALLOW Anywhere (v6) 19. ok your own login is not affected (only the failing address is banned) | deploy 20. ok fail2ban-client set sshd unbanip prints 1 (one address unbanned) | 1 21. ok the unbanned computer reaches sshd again at once | admin@203.0.113.10: Permission denied (publickey). 22. ok jail.conf itself says YOU SHOULD NOT MODIFY THIS FILE | 11:# YOU SHOULD NOT MODIFY THIS FILE. 23. ok (the jail.local file is exactly as the article shows it) | [DEFAULT] | ignoreip = 127.0.0.1/8 ::1 192.0.2.2 | bantime = 1h 24. ok fail2ban-client reload prints OK | 2026-11-11 17:31:51,058 fail2ban.configreader [4511]: WARNING 'allowipv6' not defined in 'Definition'. Using default one: 'auto' | OK 25. ok the sshd jail now has a 3600 s ban and ignores 192.0.2.2 | 3600 | These IP addresses/networks are ignored: | |- 127.0.0.0/8 | |- ::1 | `- 192.0.2.2 26. ok 6 failed tries from the whitelisted address: fail2ban logs "Ignore 192.0.2.2 by ip" | 2026-11-11 17:31:54,355 fail2ban.filter [2959]: INFO [sshd] Ignore 192.0.2.2 by ip 27. ok …and does not ban it | Status for the jail: sshd | |- Filter | | |- Currently failed: 1 | | |- Total failed: 7 | | `- Journal matches: _SYSTEMD_UNIT=sshd.service + _COMM=sshd | `- Actions | |- Currently banned: 0 | |- Total banned: 1 | `- Banned IP list: 28. ok (the whitelisted computer still reaches sshd) | admin@203.0.113.10: Permission denied (publickey). 29. ok (tested on) the box reports its OS, kernel and the version of 4 package(s) | PRETTY_NAME="Ubuntu 24.04.5 LTS" | VIRT=none | KERNEL=6.8.0-147-generic | PKG fail2ban 1.0.2-3ubuntu0.1 | PKG nftables 1.0.9-1ubuntu0.1 | PKG openssh-server 1:9.6p1-3ubuntu13.20 | PKG python3 3.12.3-0ubuntu2.1 30. ok with the release package 1.0.2-3 the service does not start | failed 31. ok its log says: ERROR No module named 'asynchat' | Nov 11 17:32:17 web-server fail2ban-server[5514]: 2026-11-11 17:32:17,840 fail2ban [5514]: ERROR No module named 'asynchat' 32. ok apt-cache policy shows 1.0.2-3 installed and the fixed 1.0.2-3ubuntu0.1 as the candidate | fail2ban: | Installed: 1.0.2-3 | Candidate: 1.0.2-3ubuntu0.1 | Version table: | 1.0.2-3ubuntu0.1 500 | 500 http://archive.ubuntu.com/ubuntu noble-updates/universe amd64 Packages | *** 1.0.2-3 500 | 500 http://archive.ubuntu.com/ubuntu noble/universe amd64 Packages | 100 /var/lib/dpkg/status 33. ok apt update + apt install fail2ban installs the fixed version | hdl; do`", | /usr/lib/python3/dist-packages/fail2ban/tests/servertestcase.py:1424: SyntaxWarning: invalid escape sequence '\s' | "`{ nft -a list chain inet f2b-table f2b-chain | grep -oP '@addr6-set-j-w-nft-ap\s+.*\s+\Khandle\s+(\d+)$'; } | while read -r hdl; do`", | Processing triggers for man-db (2.12.0-4build2) ... | Scanning processes... | Scanning linux images... | | Running kernel seems to be up-to-date. | | No services need to be restarted. | | No containers need to be restarted. | | No user sessions are running outdated binaries. | | No VM guests are running outdated hypervisor (qemu) binaries on this host. 34. ok fail2ban is active again, and jail.local was kept | active 35. ok systemctl disable --now stops fail2ban and keeps it off after a reboot | Synchronizing state of fail2ban.service with SysV service script with /usr/lib/systemd/systemd-sysv-install. | Executing: /usr/lib/systemd/systemd-sysv-install disable fail2ban | Removed "/etc/systemd/system/multi-user.target.wants/fail2ban.service". 36. ok stopping fail2ban removes its nftables table (no ban is left behind) | table ip filter | table ip6 filter ------------------------------------------------------------------------------ Commands and what they printed (30) ------------------------------------------------------------------------------ $ sudo ufw status Status: active To Action From -- ------ ---- OpenSSH ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere (v6) $ sudo apt update Hit:1 http://archive.ubuntu.com/ubuntu noble InRelease Get:2 http://archive.ubuntu.com/ubuntu noble-updates InRelease [126 kB] Get:3 http://archive.ubuntu.com/ubuntu noble-backports InRelease [126 kB] Get:4 http://archive.ubuntu.com/ubuntu noble/universe amd64 Packages [15.0 MB] Get:5 http://security.ubuntu.com/ubuntu noble-security InRelease [126 kB] Get:6 http://security.ubuntu.com/ubuntu noble-security/main amd64 Packages [1160 kB] Get:7 http://security.ubuntu.com/ubuntu noble-security/main Translation-en [234 kB] Get:8 http://security.ubuntu.com/ubuntu noble-security/main amd64 Components [46.3 kB] Get:9 http://security.ubuntu.com/ubuntu noble-security/universe amd64 Packages [1228 kB] Get:10 http://security.ubuntu.com/ubuntu noble-security/universe Translation-en [248 kB] Get:11 http://security.ubuntu.com/ubuntu noble-security/universe amd64 Components [76.3 kB] Get:12 http://security.ubuntu.com/ubuntu noble-security/universe amd64 c-n-f Metadata [24.2 kB] Get:13 http://security.ubuntu.com/ubuntu noble-security/restricted amd64 Packages [1729 kB] Get:14 http://security.ubuntu.com/ubuntu noble-security/restricted Translation-en [396 kB] Get:15 http://security.ubuntu.com/ubuntu noble-security/multiverse amd64 Packages [45.4 kB] Get:16 http://security.ubuntu.com/ubuntu noble-security/multiverse Translation-en [12.4 kB] Get:17 http://security.ubuntu.com/ubuntu noble-security/multiverse amd64 Components [208 B] Get:18 http://security.ubuntu.com/ubuntu noble-security/multiverse amd64 c-n-f Metadata [468 B] Get:19 http://archive.ubuntu.com/ubuntu noble/universe Translation-en [5982 kB] Get:20 http://archive.ubuntu.com/ubuntu noble/universe amd64 Components [3871 kB] Get:21 http://archive.ubuntu.com/ubuntu noble/universe amd64 c-n-f Metadata [301 kB] Get:22 http://archive.ubuntu.com/ubuntu noble/multiverse amd64 Packages [269 kB] Get:23 http://archive.ubuntu.com/ubuntu noble/multiverse Translation-en [118 kB] Get:24 http://archive.ubuntu.com/ubuntu noble/multiverse amd64 Components [35.0 kB] Get:25 http://archive.ubuntu.com/ubuntu noble/multiverse amd64 c-n-f Metadata [8328 B] Get:26 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 Packages [1444 kB] Get:27 http://archive.ubuntu.com/ubuntu noble-updates/main Translation-en [315 kB] Get:28 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 Components [181 kB] Get:29 http://archive.ubuntu.com/ubuntu noble-updates/universe amd64 Packages [1711 kB] Get:30 http://archive.ubuntu.com/ubuntu noble-updates/universe Translation-en [344 kB] Get:31 http://archive.ubuntu.com/ubuntu noble-updates/universe amd64 Components [388 kB] Get:32 http://archive.ubuntu.com/ubuntu noble-updates/universe amd64 c-n-f Metadata [34.9 kB] Get:33 http://archive.ubuntu.com/ubuntu noble-updates/restricted amd64 Packages [1879 kB] Get:34 http://archive.ubuntu.com/ubuntu noble-updates/restricted Translation-en [429 kB] Get:35 http://archive.ubuntu.com/ubuntu noble-updates/multiverse amd64 Packages [50.7 kB] Get:36 http://archive.ubuntu.com/ubuntu noble-updates/multiverse Translation-en [14.3 kB] Get:37 http://archive.ubuntu.com/ubuntu noble-updates/multiverse amd64 Components [940 B] Get:38 http://archive.ubuntu.com/ubuntu noble-updates/multiverse amd64 c-n-f Metadata [656 B] Get:39 http://archive.ubuntu.com/ubuntu noble-backports/main amd64 Packages [40.6 kB] Get:40 http://archive.ubuntu.com/ubuntu noble-backports/main Translation-en [9172 B] Get:41 http://archive.ubuntu.com/ubuntu noble-backports/main amd64 Components [5736 B] Get:42 http://archive.ubuntu.com/ubuntu noble-backports/main amd64 c-n-f Metadata [368 B] Get:43 http://archive.ubuntu.com/ubuntu noble-backports/universe amd64 Packages [31.0 kB] Get:44 http://archive.ubuntu.com/ubuntu noble-backports/universe Translation-en [18.6 kB] Get:45 http://archive.ubuntu.com/ubuntu noble-backports/universe amd64 Components [12.6 kB] Get:46 http://archive.ubuntu.com/ubuntu noble-backports/universe amd64 c-n-f Metadata [1588 B] Get:47 http://archive.ubuntu.com/ubuntu noble-backports/restricted amd64 Components [212 B] Get:48 http://archive.ubuntu.com/ubuntu noble-backports/restricted amd64 c-n-f Metadata [116 B] Get:49 http://archive.ubuntu.com/ubuntu noble-backports/multiverse amd64 Packages [748 B] Get:50 http://archive.ubuntu.com/ubuntu noble-backports/multiverse Translation-en [340 B] Get:51 http://archive.ubuntu.com/ubuntu noble-backports/multiverse amd64 Components [212 B] Get:52 http://archive.ubuntu.com/ubuntu noble-backports/multiverse amd64 c-n-f Metadata [116 B] Fetched 38.1 MB in 3min 15s (196 kB/s) Reading package lists... Done Building dependency tree... Done Reading state information... Done 42 packages can be upgraded. Run 'apt list --upgradable' to see them. $ sudo apt install -y fail2ban Reading package lists... Done Building dependency tree... Done Reading state information... Done The following additional packages will be installed: python3-pyasyncore python3-pyinotify whois Suggested packages: mailx monit sqlite3 python-pyinotify-doc The following NEW packages will be installed: fail2ban python3-pyasyncore python3-pyinotify whois 0 upgraded, 4 newly installed, 0 to remove and 42 not upgraded. Need to get 496 kB of archives. After this operation, 2572 kB of additional disk space will be used. Get:1 http://archive.ubuntu.com/ubuntu noble/main amd64 python3-pyasyncore all 1.0.2-2 [10.1 kB] Get:2 http://archive.ubuntu.com/ubuntu noble-updates/universe amd64 fail2ban all 1.0.2-3ubuntu0.1 [409 kB] Get:3 http://archive.ubuntu.com/ubuntu noble/main amd64 python3-pyinotify all 0.9.6-2ubuntu1 [25.0 kB] Get:4 http://archive.ubuntu.com/ubuntu noble/main amd64 whois amd64 5.5.22 [51.7 kB] Fetched 496 kB in 4s (118 kB/s) Selecting previously unselected package python3-pyasyncore. (Reading database ... 75072 files and directories currently installed.) Preparing to unpack .../python3-pyasyncore_1.0.2-2_all.deb ... Unpacking python3-pyasyncore (1.0.2-2) ... Selecting previously unselected package fail2ban. Preparing to unpack .../fail2ban_1.0.2-3ubuntu0.1_all.deb ... Unpacking fail2ban (1.0.2-3ubuntu0.1) ... Selecting previously unselected package python3-pyinotify. Preparing to unpack .../python3-pyinotify_0.9.6-2ubuntu1_all.deb ... Unpacking python3-pyinotify (0.9.6-2ubuntu1) ... Selecting previously unselected package whois. Preparing to unpack .../whois_5.5.22_amd64.deb ... Unpacking whois (5.5.22) ... Setting up whois (5.5.22) ... Setting up python3-pyasyncore (1.0.2-2) ... Setting up fail2ban (1.0.2-3ubuntu0.1) ... /usr/lib/python3/dist-packages/fail2ban/tests/fail2banregextestcase.py:224: SyntaxWarning: invalid escape sequence '\s' "1490349000 test failed.dns.ch", "^\s*test \S+" /usr/lib/python3/dist-packages/fail2ban/tests/fail2banregextestcase.py:435: SyntaxWarning: invalid escape sequence '\S' '^'+prefix+'User \S+ not allowed\n' /usr/lib/python3/dist-packages/fail2ban/tests/fail2banregextestcase.py:443: SyntaxWarning: invalid escape sequence '\S' '^'+prefix+'User \S+ not allowed\n' /usr/lib/python3/dist-packages/fail2ban/tests/fail2banregextestcase.py:444: SyntaxWarning: invalid escape sequence '\d' '^'+prefix+'Received disconnect from port \d+' /usr/lib/python3/dist-packages/fail2ban/tests/fail2banregextestcase.py:451: SyntaxWarning: invalid escape sequence '\s' _test_variants('common', prefix="\s*\S+ sshd\[\d+\]:\s+") /usr/lib/python3/dist-packages/fail2ban/tests/fail2banregextestcase.py:537: SyntaxWarning: invalid escape sequence '\[' 'common[prefregex="^svc\[\d+\] connect .+$"' /usr/lib/python3/dist-packages/fail2ban/tests/servertestcase.py:1375: SyntaxWarning: invalid escape sequence '\s' "`{ nft -a list chain inet f2b-table f2b-chain | grep -oP '@addr-set-j-w-nft-mp\s+.*\s+\Khandle\s+(\d+)$'; } | while read -r hdl; do`", /usr/lib/python3/dist-packages/fail2ban/tests/servertestcase.py:1378: SyntaxWarning: invalid escape sequence '\s' "`{ nft -a list chain inet f2b-table f2b-chain | grep -oP '@addr6-set-j-w-nft-mp\s+.*\s+\Khandle\s+(\d+)$'; } | while read -r hdl; do`", /usr/lib/python3/dist-packages/fail2ban/tests/servertestcase.py:1421: SyntaxWarning: invalid escape sequence '\s' "`{ nft -a list chain inet f2b-table f2b-chain | grep -oP '@addr-set-j-w-nft-ap\s+.*\s+\Khandle\s+(\d+)$'; } | while read -r hdl; do`", /usr/lib/python3/dist-packages/fail2ban/tests/servertestcase.py:1424: SyntaxWarning: invalid escape sequence '\s' "`{ nft -a list chain inet f2b-table f2b-chain | grep -oP '@addr6-set-j-w-nft-ap\s+.*\s+\Khandle\s+(\d+)$'; } | while read -r hdl; do`", Created symlink /etc/systemd/system/multi-user.target.wants/fail2ban.service → /usr/lib/systemd/system/fail2ban.service. Setting up python3-pyinotify (0.9.6-2ubuntu1) ... Processing triggers for man-db (2.12.0-4build2) ... Scanning processes... Scanning linux images... Running kernel seems to be up-to-date. No services need to be restarted. No containers need to be restarted. No user sessions are running outdated binaries. No VM guests are running outdated hypervisor (qemu) binaries on this host. $ sudo systemctl status fail2ban --no-pager ● fail2ban.service - Fail2Ban Service Loaded: loaded (/usr/lib/systemd/system/fail2ban.service; enabled; preset: enabled) Active: active (running) since Wed 2026-11-11 17:31:36 UTC; 3s ago Docs: man:fail2ban(1) Main PID: 2959 (fail2ban-server) Tasks: 5 (limit: 2315) Memory: 20.7M (peak: 21.1M) CPU: 186ms CGroup: /system.slice/fail2ban.service └─2959 /usr/bin/python3 /usr/bin/fail2ban-server -xf start Nov 11 17:31:36 web-server systemd[1]: Started fail2ban.service - Fail2Ban …ice. Nov 11 17:31:36 web-server fail2ban-server[2959]: 2026-11-11 17:31:36,404 fa…to' Nov 11 17:31:36 web-server fail2ban-server[2959]: Server ready Hint: Some lines were ellipsized, use -l to show in full. $ apt-cache policy fail2ban fail2ban: Installed: 1.0.2-3ubuntu0.1 Candidate: 1.0.2-3ubuntu0.1 Version table: *** 1.0.2-3ubuntu0.1 500 500 http://archive.ubuntu.com/ubuntu noble-updates/universe amd64 Packages 100 /var/lib/dpkg/status 1.0.2-3 500 500 http://archive.ubuntu.com/ubuntu noble/universe amd64 Packages $ cat /etc/fail2ban/jail.d/defaults-debian.conf [DEFAULT] banaction = nftables banaction_allports = nftables[type=allports] backend = systemd [sshd] enabled = true $ sudo fail2ban-client status Status |- Number of jail: 1 `- Jail list: sshd $ sudo fail2ban-client get sshd maxretry && sudo fail2ban-client get sshd findtime && sudo fail2ban-client get sshd bantime 5 600 600 $ sudo journalctl -u ssh --no-pager | grep 'Invalid user' | tail -n 2 Nov 11 17:31:43 web-server sshd[3602]: Invalid user admin from 198.51.100.2 port 59950 Nov 11 17:31:43 web-server sshd[3667]: Invalid user admin from 198.51.100.2 port 59966 $ sudo fail2ban-client status sshd Status for the jail: sshd |- Filter | |- Currently failed: 1 | |- Total failed: 6 | `- Journal matches: _SYSTEMD_UNIT=sshd.service + _COMM=sshd `- Actions |- Currently banned: 1 |- Total banned: 1 `- Banned IP list: 198.51.100.2 $ sudo grep 'Ban ' /var/log/fail2ban.log 2026-11-11 17:31:43,782 fail2ban.actions [2959]: NOTICE [sshd] Ban 198.51.100.2 $ ssh admin@203.0.113.10 ssh: connect to host 203.0.113.10 port 22: Connection refused $ sudo nft list table inet f2b-table table inet f2b-table { set addr-set-sshd { type ipv4_addr elements = { 198.51.100.2 } } chain f2b-chain { type filter hook input priority filter - 1; policy accept; tcp dport 22 ip saddr @addr-set-sshd reject with icmp port-unreachable } } $ sudo ufw status Status: active To Action From -- ------ ---- OpenSSH ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere (v6) $ whoami deploy $ sudo fail2ban-client set sshd unbanip 198.51.100.2 1 $ ssh admin@203.0.113.10 admin@203.0.113.10: Permission denied (publickey). $ grep -n 'YOU SHOULD NOT MODIFY' /etc/fail2ban/jail.conf 11:# YOU SHOULD NOT MODIFY THIS FILE. $ cat /etc/fail2ban/jail.local [DEFAULT] ignoreip = 127.0.0.1/8 ::1 192.0.2.2 bantime = 1h $ sudo fail2ban-client reload 2026-11-11 17:31:51,058 fail2ban.configreader [4511]: WARNING 'allowipv6' not defined in 'Definition'. Using default one: 'auto' OK $ sudo fail2ban-client get sshd bantime && sudo fail2ban-client get sshd ignoreip 3600 These IP addresses/networks are ignored: |- 127.0.0.0/8 |- ::1 `- 192.0.2.2 $ sudo grep 'Ignore 192.0.2.2' /var/log/fail2ban.log | tail -n 1 2026-11-11 17:31:54,355 fail2ban.filter [2959]: INFO [sshd] Ignore 192.0.2.2 by ip $ sudo fail2ban-client status sshd Status for the jail: sshd |- Filter | |- Currently failed: 1 | |- Total failed: 7 | `- Journal matches: _SYSTEMD_UNIT=sshd.service + _COMM=sshd `- Actions |- Currently banned: 0 |- Total banned: 1 `- Banned IP list: $ sudo systemctl is-active fail2ban failed $ sudo journalctl -u fail2ban --no-pager | grep asynchat | tail -n 1 Nov 11 17:32:17 web-server fail2ban-server[5514]: 2026-11-11 17:32:17,840 fail2ban [5514]: ERROR No module named 'asynchat' $ apt-cache policy fail2ban fail2ban: Installed: 1.0.2-3 Candidate: 1.0.2-3ubuntu0.1 Version table: 1.0.2-3ubuntu0.1 500 500 http://archive.ubuntu.com/ubuntu noble-updates/universe amd64 Packages *** 1.0.2-3 500 500 http://archive.ubuntu.com/ubuntu noble/universe amd64 Packages 100 /var/lib/dpkg/status $ sudo apt update && sudo apt install -y fail2ban Hit:1 http://archive.ubuntu.com/ubuntu noble InRelease Hit:2 http://archive.ubuntu.com/ubuntu noble-updates InRelease Hit:3 http://archive.ubuntu.com/ubuntu noble-backports InRelease Hit:4 http://security.ubuntu.com/ubuntu noble-security InRelease Reading package lists... Done Building dependency tree... Done Reading state information... Done 43 packages can be upgraded. Run 'apt list --upgradable' to see them. Reading package lists... Done Building dependency tree... Done Reading state information... Done Suggested packages: mailx monit sqlite3 The following packages will be upgraded: fail2ban 1 upgraded, 0 newly installed, 0 to remove and 42 not upgraded. Need to get 409 kB of archives. After this operation, 15.4 kB of additional disk space will be used. Get:1 http://archive.ubuntu.com/ubuntu noble-updates/universe amd64 fail2ban all 1.0.2-3ubuntu0.1 [409 kB] Fetched 409 kB in 4s (104 kB/s) (Reading database ... 75558 files and directories currently installed.) Preparing to unpack .../fail2ban_1.0.2-3ubuntu0.1_all.deb ... Unpacking fail2ban (1.0.2-3ubuntu0.1) over (1.0.2-3) ... Setting up fail2ban (1.0.2-3ubuntu0.1) ... /usr/lib/python3/dist-packages/fail2ban/tests/fail2banregextestcase.py:224: SyntaxWarning: invalid escape sequence '\s' "1490349000 test failed.dns.ch", "^\s*test \S+" /usr/lib/python3/dist-packages/fail2ban/tests/fail2banregextestcase.py:435: SyntaxWarning: invalid escape sequence '\S' '^'+prefix+'User \S+ not allowed\n' /usr/lib/python3/dist-packages/fail2ban/tests/fail2banregextestcase.py:443: SyntaxWarning: invalid escape sequence '\S' '^'+prefix+'User \S+ not allowed\n' /usr/lib/python3/dist-packages/fail2ban/tests/fail2banregextestcase.py:444: SyntaxWarning: invalid escape sequence '\d' '^'+prefix+'Received disconnect from port \d+' /usr/lib/python3/dist-packages/fail2ban/tests/fail2banregextestcase.py:451: SyntaxWarning: invalid escape sequence '\s' _test_variants('common', prefix="\s*\S+ sshd\[\d+\]:\s+") /usr/lib/python3/dist-packages/fail2ban/tests/fail2banregextestcase.py:537: SyntaxWarning: invalid escape sequence '\[' 'common[prefregex="^svc\[\d+\] connect .+$"' /usr/lib/python3/dist-packages/fail2ban/tests/servertestcase.py:1375: SyntaxWarning: invalid escape sequence '\s' "`{ nft -a list chain inet f2b-table f2b-chain | grep -oP '@addr-set-j-w-nft-mp\s+.*\s+\Khandle\s+(\d+)$'; } | while read -r hdl; do`", /usr/lib/python3/dist-packages/fail2ban/tests/servertestcase.py:1378: SyntaxWarning: invalid escape sequence '\s' "`{ nft -a list chain inet f2b-table f2b-chain | grep -oP '@addr6-set-j-w-nft-mp\s+.*\s+\Khandle\s+(\d+)$'; } | while read -r hdl; do`", /usr/lib/python3/dist-packages/fail2ban/tests/servertestcase.py:1421: SyntaxWarning: invalid escape sequence '\s' "`{ nft -a list chain inet f2b-table f2b-chain | grep -oP '@addr-set-j-w-nft-ap\s+.*\s+\Khandle\s+(\d+)$'; } | while read -r hdl; do`", /usr/lib/python3/dist-packages/fail2ban/tests/servertestcase.py:1424: SyntaxWarning: invalid escape sequence '\s' "`{ nft -a list chain inet f2b-table f2b-chain | grep -oP '@addr6-set-j-w-nft-ap\s+.*\s+\Khandle\s+(\d+)$'; } | while read -r hdl; do`", Processing triggers for man-db (2.12.0-4build2) ... Scanning processes... Scanning linux images... Running kernel seems to be up-to-date. No services need to be restarted. No containers need to be restarted. No user sessions are running outdated binaries. No VM guests are running outdated hypervisor (qemu) binaries on this host. $ sudo systemctl is-active fail2ban active $ sudo systemctl disable --now fail2ban Synchronizing state of fail2ban.service with SysV service script with /usr/lib/systemd/systemd-sysv-install. Executing: /usr/lib/systemd/systemd-sysv-install disable fail2ban Removed "/etc/systemd/system/multi-user.target.wants/fail2ban.service". $ sudo nft list tables table ip filter table ip6 filter ------------------------------------------------------------------------------ The check's source (scripts/live/checks/fail2ban-ubuntu-24-04.mjs) As it ran. ------------------------------------------------------------------------------ /** * KB: Install fail2ban on Ubuntu 24.04 and protect SSH (ban, unban, whitelist your own address). * * The server is a fresh VM box with the UFW firewall from the ufw article already on (OpenSSH allowed), reached as the * sudo user `deploy`. The failed logins come from two OTHER computers on the server's network: network namespaces on * the VM, each joined to the server by its own virtual cable. The server's end of both cables is 203.0.113.10, so the * other computers type exactly what the article shows (`ssh admin@203.0.113.10`). "bot" is 198.51.100.2 (gets * banned); "office" is 192.0.2.2 (the reader's own address, whitelisted later). Their packets go through the server's * real kernel, nftables and ufw, and sshd logs them as remote logins, so fail2ban sees exactly what it sees on a VPS; * and the runner's own address is never banned. Every claim below is one the article makes. */ import { bareBox, reportBox } from '../lib.mjs' export const meta = {} const SERVER = '203.0.113.10' const BOT = '198.51.100.2' const OFFICE = '192.0.2.2' const sleep = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms) /** The ssh a reader's other computer runs (key-less, so the server says "Permission denied (publickey)"). */ const SSH_FLAGS = '-o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=5' const check = (ctx) => bareBox(ctx, async ({ sudoUser }) => { const { run, L } = sudoUser() const other = (ns, cmd) => L(`sudo ip netns exec ${ns} ${cmd} 2>&1`) const tryLogin = (ns) => other(ns, `ssh ${SSH_FLAGS} admin@${SERVER} true`).split('\n').pop() // ── setup: the firewall from the ufw article, and the two other computers ───────────────── L('sudo ufw allow OpenSSH >/dev/null && sudo ufw --force enable >/dev/null') for (const [ns, addr] of [['bot', BOT], ['office', OFFICE]]) { L( [ `sudo ip netns add ${ns}`, `sudo ip link add v-${ns} type veth peer name eth0 netns ${ns}`, `sudo ip addr add ${SERVER} peer ${addr} dev v-${ns}`, `sudo ip link set v-${ns} up`, `sudo ip netns exec ${ns} ip addr add ${addr} peer ${SERVER} dev eth0`, `sudo ip netns exec ${ns} ip link set eth0 up`, `sudo ip netns exec ${ns} ip link set lo up`, ].join(' && '), ) } const reach = tryLogin('bot') ctx.check('(setup) the bot computer reaches the server’s SSH and is refused a login (no key)', /Permission denied \(publickey\)/.test(reach), reach) // ── before you start ───────────────────────────────────────────────────────────────────── const ufw = run('sudo ufw status', { id: 'ufw-start' }) ctx.check('the starting server has ufw on with SSH allowed', /^Status: active$/m.test(ufw.out) && /OpenSSH\s+ALLOW/.test(ufw.out), ufw.out) // ── step 1: install ────────────────────────────────────────────────────────────────────── const upd = run('sudo apt update', { id: 'apt-update', timeout: 600000 }) ctx.check('apt update reads the package lists', upd.exit === 0 && /Reading package lists/.test(upd.out), upd.out.slice(-400)) const inst = run('sudo apt install -y fail2ban', { id: 'apt-install', timeout: 900000 }) ctx.check('apt install -y fail2ban installs it', inst.exit === 0 && /Setting up fail2ban/.test(inst.out), inst.out.slice(-600)) ctx.check('it pulls in python3-pyasyncore (the module Python 3.12 no longer ships)', /python3-pyasyncore/.test(inst.out), inst.out.slice(0, 600)) const st = run('sudo systemctl status fail2ban --no-pager', { id: 'service-status' }) ctx.check('the service is enabled and active (running) straight after install', /enabled;/.test(st.out) && /Active: active \(running\)/.test(st.out), st.out) const pol = run('apt-cache policy fail2ban', { id: 'policy' }) ctx.check('the installed version is the fixed update 1.0.2-3ubuntu0.1, not the release’s 1.0.2-3', /Installed: 1\.0\.2-3ubuntu0\.1/.test(pol.out), pol.out) // ── step 2: what Ubuntu turns on ───────────────────────────────────────────────────────── const deb = run('cat /etc/fail2ban/jail.d/defaults-debian.conf', { id: 'defaults-debian' }) ctx.check('Ubuntu enables the sshd jail, reads the systemd journal and bans with nftables', /^\[sshd\]\s*\nenabled = true/m.test(deb.out) && /^backend = systemd$/m.test(deb.out) && /^banaction = nftables$/m.test(deb.out), deb.out) const jails = run('sudo fail2ban-client status', { id: 'client-status' }) ctx.check('fail2ban-client status lists one jail: sshd', /Number of jail:\s+1/.test(jails.out) && /Jail list:\s+sshd/.test(jails.out), jails.out) const conf = run(`sudo fail2ban-client get sshd maxretry && sudo fail2ban-client get sshd findtime && sudo fail2ban-client get sshd bantime`, { id: 'get-defaults' }) ctx.check('the defaults: 5 tries in 600 s (10 min) gets a 600 s (10 min) ban', /^5\n600\n600$/.test(conf.out), conf.out) // ── step 3: watch it ban ───────────────────────────────────────────────────────────────── const tries = [] for (let i = 0; i < 5; i++) tries.push(tryLogin('bot')) ctx.check('the bot’s 5 tries all reach sshd and are refused', tries.every((t) => /Permission denied/.test(t)), tries.join('\n')) sleep(3000) const inv = run(`sudo journalctl -u ssh --no-pager | grep 'Invalid user' | tail -n 2`, { id: 'invalid-user' }) ctx.check('sshd logs each try as "Invalid user admin from 198.51.100.2"', new RegExp(`Invalid user admin from ${BOT.replace(/\./g, '\\.')} port \\d+`).test(inv.out), inv.out) const jail = run('sudo fail2ban-client status sshd', { id: 'jail-banned' }) ctx.check('after 5 failures the sshd jail has banned 198.51.100.2', /Currently banned:\s+1/.test(jail.out) && new RegExp(`Banned IP list:\\s+${BOT.replace(/\./g, '\\.')}`).test(jail.out), jail.out) const banlog = run(`sudo grep 'Ban ' /var/log/fail2ban.log`, { id: 'ban-log' }) ctx.check('/var/log/fail2ban.log: NOTICE [sshd] Ban 198.51.100.2', /NOTICE\s+\[sshd\] Ban 198\.51\.100\.2/.test(banlog.out), banlog.out) const refused = tryLogin('bot') ctx.capture(`ssh admin@${SERVER}`, refused, { id: 'banned-ssh' }) ctx.check('the banned computer now gets "Connection refused" (not a login prompt)', /ssh: connect to host 203\.0\.113\.10 port 22: Connection refused/.test(refused), refused) const nft = run('sudo nft list table inet f2b-table', { id: 'nft-table' }) ctx.check('the ban is an nftables set with a reject rule at priority filter - 1, before ufw’s rules', /elements = \{ 198\.51\.100\.2 \}/.test(nft.out) && /hook input priority filter - 1/.test(nft.out) && /reject with icmp port-unreachable/.test(nft.out), nft.out) const ufwStill = run('sudo ufw status', { id: 'ufw-during-ban' }) ctx.check('ufw still lists SSH as allowed: the ban is not a ufw rule', /OpenSSH\s+ALLOW/.test(ufwStill.out) && !/198\.51/.test(ufwStill.out), ufwStill.out) const mine = run('whoami', { id: 'still-me' }) ctx.check('your own login is not affected (only the failing address is banned)', /deploy$/.test(mine.out), mine.out) // ── step 4: unban ──────────────────────────────────────────────────────────────────────── const unban = run(`sudo fail2ban-client set sshd unbanip ${BOT}`, { id: 'unban' }) ctx.check('fail2ban-client set sshd unbanip prints 1 (one address unbanned)', unban.out.split('\n').pop() === '1', unban.out) const back = tryLogin('bot') ctx.capture(`ssh admin@${SERVER}`, back, { id: 'unbanned-ssh' }) ctx.check('the unbanned computer reaches sshd again at once', /Permission denied \(publickey\)/.test(back), back) // ── step 5: your own settings in jail.local (never jail.conf) ──────────────────────────── const head = run(`grep -n 'YOU SHOULD NOT MODIFY' /etc/fail2ban/jail.conf`, { id: 'do-not-modify' }) ctx.check('jail.conf itself says YOU SHOULD NOT MODIFY THIS FILE', /YOU SHOULD NOT MODIFY THIS FILE/.test(head.out), head.out) L(`printf '%s\\n' '[DEFAULT]' 'ignoreip = 127.0.0.1/8 ::1 ${OFFICE}' 'bantime = 1h' | sudo tee /etc/fail2ban/jail.local >/dev/null`) const local = run('cat /etc/fail2ban/jail.local', { id: 'jail-local' }) ctx.check('(the jail.local file is exactly as the article shows it)', local.out === `[DEFAULT]\nignoreip = 127.0.0.1/8 ::1 ${OFFICE}\nbantime = 1h`, local.out) const reload = run('sudo fail2ban-client reload', { id: 'reload' }) ctx.check('fail2ban-client reload prints OK', /^OK$/m.test(reload.out), reload.out) const got = run('sudo fail2ban-client get sshd bantime && sudo fail2ban-client get sshd ignoreip', { id: 'get-local' }) ctx.check('the sshd jail now has a 3600 s ban and ignores 192.0.2.2', /^3600$/m.test(got.out) && /192\.0\.2\.2/.test(got.out), got.out) for (let i = 0; i < 6; i++) tryLogin('office') sleep(3000) const ign = run(`sudo grep 'Ignore ${OFFICE}' /var/log/fail2ban.log | tail -n 1`, { id: 'ignore-log' }) ctx.check('6 failed tries from the whitelisted address: fail2ban logs "Ignore 192.0.2.2 by ip"', /\[sshd\] Ignore 192\.0\.2\.2 by ip/.test(ign.out), ign.out) const after = run('sudo fail2ban-client status sshd', { id: 'jail-after-ignore' }) ctx.check('…and does not ban it', /Currently banned:\s+0/.test(after.out), after.out) const officeIn = tryLogin('office') ctx.check('(the whitelisted computer still reaches sshd)', /Permission denied \(publickey\)/.test(officeIn), officeIn) reportBox( ctx, L, 'A fresh Ubuntu 24.04 server with the UFW firewall on (SSH allowed), reached over SSH as a sudo user. The failed logins came from two other computers on its network, 198.51.100.2 and 192.0.2.2.', ['fail2ban', 'python3', 'nftables', 'openssh-server'], ) // ── troubleshooting: the release package, "No module named 'asynchat'" ────────────────── // reproduce what an early 24.04 server has: the package from the release pocket (noble), before the fix L('sudo DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --allow-downgrades fail2ban=1.0.2-3 >/dev/null 2>&1; sudo systemctl restart fail2ban; sleep 3') const broken = run('sudo systemctl is-active fail2ban', { id: 'broken-active' }) ctx.check('with the release package 1.0.2-3 the service does not start', /^(failed|activating|inactive)$/m.test(broken.out), broken.out) const err = run(`sudo journalctl -u fail2ban --no-pager | grep asynchat | tail -n 1`, { id: 'asynchat' }) ctx.check('its log says: ERROR No module named \'asynchat\'', /ERROR\s+No module named 'asynchat'/.test(err.out), err.out) const pol2 = run('apt-cache policy fail2ban', { id: 'policy-broken' }) ctx.check('apt-cache policy shows 1.0.2-3 installed and the fixed 1.0.2-3ubuntu0.1 as the candidate', /Installed: 1\.0\.2-3\n/.test(pol2.out) && /Candidate: 1\.0\.2-3ubuntu0\.1/.test(pol2.out), pol2.out) const fix = run('sudo apt update && sudo apt install -y fail2ban', { id: 'fix-install', timeout: 900000 }) ctx.check('apt update + apt install fail2ban installs the fixed version', fix.exit === 0 && /Unpacking fail2ban \(1\.0\.2-3ubuntu0\.1\)/.test(fix.out), fix.out.slice(-600)) const ok = run('sudo systemctl is-active fail2ban', { id: 'fixed-active' }) ctx.check('fail2ban is active again, and jail.local was kept', ok.out.split('\n').pop() === 'active' && /3600/.test(L('sudo fail2ban-client get sshd bantime')), ok.out) // ── undo ───────────────────────────────────────────────────────────────────────────────── const stop = run('sudo systemctl disable --now fail2ban', { id: 'disable' }) ctx.check('systemctl disable --now stops fail2ban and keeps it off after a reboot', stop.exit === 0 && /Removed/.test(stop.out), stop.out) const tables = run('sudo nft list tables', { id: 'nft-tables-after' }) ctx.check('stopping fail2ban removes its nftables table (no ban is left behind)', !/f2b-table/.test(tables.out), tables.out) }) export default check