Fail2ban and IP Reputation: Ban Smarter (SSH Brute Force Included)
Fail2ban has no IP reputation check. We added a custom action that looks up each banned IP once and escalates abusers. Nine SSH guessers scored 32 to 63.

On 4 December 2026 we looked up nine addresses that two public lists reported for SSH password guessing. All nine came back threat.is_abusive: true and labelled as malicious scanners, yet they scored 32 to 63: seven review, two step_up, none block. We picked them from public lists of the kind that also feed our data, so the flags were expected; the finding is the score. A script that escalated only on recommended_action: "block" would have escalated none of them, so ours keys on the flags.
In a Debian 13 container with fail2ban 1.1.0, the action moved 124.174.7.42 into a one-week jail covering every TCP port about two seconds after the normal sshd ban, and left a Censys scanner on the normal ban.
Below: the sshd baseline, where reputation plugs in, what the API returned, the files we tested, the web-jail ignorecommand, repeat offenders and the limits. If you are still deciding what one address did, start with how to investigate an IP address.
Does fail2ban check IP reputation? No, it counts failures in your logs
Fail2ban only counts what your own logs show. Here is a line of the kind it reads, in the format OpenSSH 9.8 and later write (we wrote it into a test log; the address never connected to us):
2026-12-04T18:13:49.512309+00:00 web1 sshd-session[2101]: Failed password for invalid user admin from 124.174.7.42 port 40150 ssh2
A jail ties a filter, a log source and an action (usually a firewall rule) to three numbers. When maxretry failures from one address land within findtime, the action bans it for bantime. The shipped jail.conf defaults are 5 failures, 10 minutes and 10 minutes.
Reputation is what other servers saw from that address. Fail2ban sees only yours.
SSH brute force protection first: keys, then a current sshd jail
SSH brute force protection starts with turning passwords off: set PasswordAuthentication no in sshd_config and log in with keys, and password guessing has nothing to guess. OpenSSH 9.8 also added PerSourcePenalties, which its release notes say "is on by default": the server will "block client addresses that repeatedly fail authentication".
Fail2ban still stops the noise at the firewall. On Debian 13 the package already enables the sshd jail with the systemd journal backend and nftables; we checked the installed defaults-debian.conf. This is all we would add:
[sshd]
enabled = true
backend = systemd
bantime = 1h
bantime.increment = true
bantime.maxtime = 1w
fail2ban-client -t accepted it on 1.1.0; with no journal in our container, we did not run it. On Debian 12 and Ubuntu 24.04 (fail2ban 1.0.2), keep backend = systemd if /var/log/auth.log does not exist, and set banaction yourself, since we did not check those packages' defaults. OpenSSH 9.8 split sshd into a listener and a per-session binary, sshd-session, and the 1.1.x sshd filter matches both names. bantime.increment needs fail2ban 0.11.1 or later.
With keys only, guessing gets nobody in, so for SSH reputation decides how long and how wide a ban is, not whether.
Where reputation plugs into fail2ban: ignorecommand before the ban, an action after it
A per-address reputation check fits at two hooks. ignorecommand can only spare an address, and an action runs only after the ban, so reputation can change how long and how wide a ban is, not whether the first ban happens. Both behaviours come from reading the fail2ban source (filter.py, actions.py and action.py at the 1.1.1 tag), and our run matched them:
ignorecommandruns before a failure counts. Exit 0 spares the address. Exit 1 lets the failure count. Any other code, a crash or a timeout is logged as an error and the failure counts. It runs for every matched log line unless you setignorecache, and only afterignoreselfandignoreipdid not match.- A custom action (
actionban) runs after the ban is recorded. If it fails, fail2ban logs "Failed to execute ban jail" and the ban stays; we saw both in our run. The other actions still run.
The hard part is a lock. Every shell command fail2ban runs, in every jail, goes through one lock (_cmd_lock in action.py), with a 60 second default timeout. A reputation call that hangs holds up every other ban action and ignorecommand while it hangs, so the script needs its own short timeout: curl --max-time 2, our choice.
What the API says about SSH password guessers: abusive, but not "block"
All nine carried the abuse flag, and none scored block. On 4 December 2026, 2,873 addresses were on both of two public SSH password-guessing lists; taking every 350th gave nine. They did not come from our own logs, and nine is a sample, not a measurement of SSH attackers. Here is the trace address, trimmed from a keyless lookup at 18:05 UTC:
{
"ip": "124.174.7.42",
"asn": {
"org": "VOLCANO-ENGINE - Beijing Volcano Engine Technology Co., Ltd.",
"asn_type": "hosting"
},
"geo": { "country_code": "CN" },
"detection": {
"is_hosting": true,
"scanner_type": "malicious",
"abuse_confidence": 0.7
},
"threat": {
"is_abusive": true,
"is_scanner": true,
"is_botnet": false,
"is_bogon": false,
"threat_types": ["abusive", "scanner"]
},
"scoring": { "fraud_score": 63, "recommended_action": "step_up" }
}
All nine, looked up between 18:05 and 18:27 UTC. Seven are not on hosting networks, so we give the network, not the address:
- 124.174.7.42, Volcano Engine, CN, hosting: 63,
step_up - 27.0.135.12, Kaopu Cloud, CN, hosting: 63,
step_up - An address on Viettel, VN: 38,
review - A home line in Thailand, address withheld: 38,
review - An address on TIME-HOST, RU: 35,
review - An address on internetbilisim, TR: 35,
review - An address on Uzbektelekom, UZ: 35,
review - An address on KX NexG, KR: 32,
review - An address on OFFICE LIMITED, GB: 32,
review
The arithmetic is in our scoring code. On an address where nothing else in our scoring fires (not a hosting network, no spam, botnet or home-line signal), an abuse listing adds 18 to 28.5 points and a malicious scanner label about 14. Together they stay under about 43, inside review, which runs to 50; block starts above 75. The Korean address had an abuse_confidence of 0.6: 18 plus 14.4 is 32.4, and it returned 32. The hosting addresses reach 63 because hosting weights add to it. For what reputation means in general, see what IP reputation is. To check one address yourself, use the IP lookup tool.
So the bands, tuned for signups, logins and checkouts, under-call SSH guessers. That is our judgment from nine samples, and why we key the escalation on is_abusive, is_botnet or a malicious scanner label, not on recommended_action.
Scanners need the opposite care. The Shodan address 89.248.172.16 and the Censys address 162.142.125.10 both scored 0, allow, with is_scanner: true, scanner_type: "benign" and is_abusive: false. So is_scanner alone must not escalate. See should you block internet scanners.
A fail2ban custom action that escalates known abusers
Let fail2ban decide whether to ban, and reputation how long and how wide. The action file, /etc/fail2ban/action.d/geoiphub-reputation.conf, runs one script per ban:
[Definition]
norestored = 1
actionstart =
actionstop =
actioncheck =
actionban = /usr/local/bin/geoiphub-reputation <ip>
actionunban =
[Init]
timeout = 5
norestored = 1 skips bans fail2ban restores after a restart, so a restart does not repeat the lookups. The 5 second timeout sits above the script's 2 second curl limit. The script, /usr/local/bin/geoiphub-reputation:
#!/bin/sh
ip="$1"
case "$ip" in ""|*[!0-9a-fA-F.:]*) exit 0 ;; esac
cache=/var/cache/geoiphub
log=/var/log/fail2ban-reputation.log
file="$cache/$ip.json"
mkdir -p "$cache"
if [ -z "$(find "$file" -mmin -1440 2>/dev/null)" ]; then
set --
[ -r /etc/fail2ban/geoiphub.key ] && set -- -H "x-api-key: $(cat /etc/fail2ban/geoiphub.key)"
code=$(curl -s --max-time 2 -o "$file.tmp" -w '%{http_code}' "$@" "https://api.geoiphub.com/v1/lookup/$ip")
if [ "$code" != 200 ] || ! jq -e . "$file.tmp" >/dev/null 2>&1; then
rm -f "$file.tmp"
echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) lookup-failed $ip http=$code" >> "$log"
exit 0
fi
mv "$file.tmp" "$file"
fi
if jq -e '(.threat.is_bogon | not) and (.threat.is_abusive or .threat.is_botnet or .detection.scanner_type == "malicious")' "$file" >/dev/null; then
echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) escalate $ip" >> "$log"
fi
exit 0
What it does:
- It refuses anything that is not an IPv4 or IPv6 address.
- It reuses a cached answer younger than 24 hours (our choice), otherwise makes one lookup with a 2 second limit. The API key comes from a root-only file, never the action line: in the fail2ban source a command that fails or times out is written to the log in full at error level, and at trace log levels every command is (we saw the latter with
loglevel = TRACEDEBUG). - On any non-200 answer, timeout or unreadable body, it logs
lookup-failedand exits 0. The sshd ban already stands, so this skips only the escalation. - It escalates when the address is abusive, part of a botnet or labelled a malicious scanner, and is not a private or reserved address (
threat.is_bogon). A LAN client that mistypes a password should not get a week-long ban. - It always exits 0 and never calls
unbanip.
The escalation is a line in a log file that a second jail reads. The filter, /etc/fail2ban/filter.d/geoiphub-reputation.conf, which fail2ban-regex matched against our escalation line:
[Definition]
failregex = ^ escalate <HOST>$
Then the jails in /etc/fail2ban/jail.local. maxretry = 3 is our test value; backend = polling and logpath were needed only because our container had no journal. The lookup action comes after the firewall action, because actions run in order and the firewall block should not wait on the lookup:
[sshd]
enabled = true
backend = polling
logpath = /var/log/auth.log
maxretry = 3
action = %(action_)s
geoiphub-reputation
[reputation]
enabled = true
filter = geoiphub-reputation
logpath = /var/log/fail2ban-reputation.log
backend = polling
maxretry = 1
findtime = 1d
bantime = 1w
banaction = %(banaction_allports)s
Budget: one lookup per new ban, so the free key's 1,500 lookups a day cover 1,500 new bans. Keyless calls work for testing; the API sent x-ratelimit-limit: 30 on ours. The fields are in the API reference.
What happened when we ran it in a fail2ban container
The escalation, the scanner contrast and the outage behaved as designed. We ran it on 4 December 2026 in a debian:trixie container (fail2ban 1.1.0-8, curl 8.14.1, jq 1.7.1, nftables 1.1.3), polling a log file with three failed-password lines per address. The lookups were live.
124.174.7.42 was banned by [sshd], looked up, and banned by [reputation] 1.8 seconds later:
2026-12-04 18:13:50,196 fail2ban.actions [4359]: NOTICE [sshd] Ban 124.174.7.42
2026-12-04 18:13:52,012 fail2ban.actions [4359]: NOTICE [reputation] Ban 124.174.7.42
2026-12-04 18:13:54,144 fail2ban.actions [4359]: NOTICE [sshd] Ban 162.142.125.10
2026-12-04 18:13:58,150 fail2ban.actions [4359]: NOTICE [sshd] Ban 27.0.135.12
2026-12-04 18:14:00,070 fail2ban.actions [4359]: NOTICE [reputation] Ban 27.0.135.12
2026-12-04 18:14:02,525 fail2ban.actions [4359]: NOTICE [sshd] Ban 192.0.2.46
2026-12-04 18:14:06,538 fail2ban.actions [4359]: NOTICE [sshd] Ban 71.6.199.23
The Censys address got the 10 minute sshd ban and nothing more. So did 192.0.2.46, a documentation address we added to test the bogon check. For 71.6.199.23 we first pointed api.geoiphub.com at an unroutable address in /etc/hosts: the sshd ban happened, and the script logged the failure two seconds later without escalating:
2026-12-04T18:13:50Z escalate 124.174.7.42
2026-12-04T18:13:59Z escalate 27.0.135.12
2026-12-04T18:14:08Z lookup-failed 71.6.199.23 http=000
Status for the jail: reputation
|- Filter
| |- Currently failed: 0
| |- Total failed: 2
| `- File list: /var/log/fail2ban-reputation.log
`- Actions
|- Currently banned: 2
|- Total banned: 2
`- Banned IP list: 124.174.7.42 27.0.135.12
In nftables the sshd rule matched TCP port 22; the reputation rule matched every TCP port (meta l4proto tcp), not UDP.
We also tried a shortcut: an actionban that runs fail2ban-client set reputation banip <ip> directly. It hung. The reputation ban was logged within 0.1 seconds, but the client call did not return. Fail2ban killed it after 60 seconds, ran it again, and killed it again 60 seconds later: about two minutes per ban. An sshd ban logged meanwhile had its lookup run one second after the second kill, as the shared lock predicts. The log-file jail avoids it. In a later run, a restart restored the reputation ban from fail2ban's database, and the restored sshd ban did not repeat the lookup.
fail2ban ignorecommand: spare verified crawlers on web jails, never on sshd
Use ignorecommand only to spare addresses you have proven friendly, such as a verified crawler on a web jail. Fail2ban's own apache-fakegooglebot script exits 0 when reverse and forward DNS confirm Googlebot. Ours asks the API and exits 0 only when threat.crawler.verified is true; everything else, including errors and timeouts, exits 1:
#!/bin/sh
body=$(curl -sf --max-time 2 "https://api.geoiphub.com/v1/lookup/$1") || exit 1
printf '%s' "$body" | jq -e '.threat.crawler.verified == true' >/dev/null && exit 0
exit 1
ignorecommand = /usr/local/bin/geoiphub-crawler-ignore <ip>
ignorecache = key="<ip>", max-count=100, max-time=5m
We adapted ignorecache from the man page example, put both lines on a small web jail with a wp-login.php filter and wrote five probe lines each from 66.249.66.1 (Googlebot, crawler.verified: true that day) and 124.174.7.42. Googlebot was not banned; 124.174.7.42 was. With ignorecache the script ran once for Googlebot's five lines; a copy of the jail without it ran the script five times. With the API unreachable, the script exited 1 after about 2 seconds and the uncached jail banned Googlebot: the safe direction. Budget one lookup per address per cache window. We ran this script keyless; on a busy web jail, read the key file the same way the action script does, or a rate-limited lookup exits 1 and the crawler is banned. ignorecache and the full set of action tags in ignorecommand need fail2ban 0.10.4 or later.
Never use ignorecommand on sshd. A clean reputation plus failed passwords is still an attacker, or your own user, who belongs in ignoreip. Crawler verification covers 19 official range files from 10 operators; other crawlers are banned like anyone. To check one by hand, verify Googlebot by reverse and forward DNS.
Permanent bans, recidive and the AbuseIPDB action
For repeat offenders, prefer growing bans over bantime = -1, which never expires. bantime.increment multiplies the ban on each repeat; the shipped jail.conf comments give the formula as ban.Time * (1<<(ban.Count if ban.Count<20 else 20)) * banFactor. Set bantime.maxtime as a ceiling. It reads ban history from fail2ban's database, so keep dbpurgeage (1 day by default) at least as long as you want repeat offenders remembered.
The shipped recidive jail reads fail2ban's own log; in Debian 13's jail.conf it bans for 1w over a findtime of 1d on all ports, maxretry 5, and is off until enabled. Reputation complements both: it acts on the first ban, not on a repeat.
The AbuseIPDB action reports a ban when it happens. Its file warns that "Reporting an IP of abuse is a serious complaint" and recommends it only for recidive, for jails with a high maxretry, and for filters "that have a low likelihood of receiving human errors".
What a reputation check can't fix
Reputation picks which bans get longer and wider. What it does not change:
- The first attempts reach sshd. The action runs only after
maxretryfailures. - Slow, distributed guessing slips past. A botnet under
maxretryper address escapes per-address bans; reputation helps only if the address was already listed. - Lists lag and expire. Our abuse flag from public lists clears about two weeks after they drop the address.
- Long bans hit the next user of a home or shared address. IPv6 attackers can move inside one /64, so ban the /64, not the address.
- We tested in a container, on fail2ban 1.1.0 with a log file and polling, not on a production host with journald.
To try it, copy the files, run fail2ban-regex /var/log/auth.log /etc/fail2ban/filter.d/sshd.conf against your own log, ban a test address with fail2ban-client set sshd banip, and watch fail2ban-client status reputation.
Frequently Asked Questions
Does fail2ban check AbuseIPDB before banning?
No. The shipped abuseipdb action sends a report when fail2ban bans the address; it never asks AbuseIPDB anything first.
What exit code should a fail2ban ignorecommand return?
0 to spare the address, 1 to let the failure count. In the fail2ban source any other code, a crash or the 60 second timeout is logged as an error and the failure still counts toward a ban.
Does a failed actionban unban the IP?
No. Fail2ban records the ban first and then runs each action. In our test a failing action was logged as an error and the address stayed banned.
How do I ban repeat offenders permanently in fail2ban?
bantime = -1 bans forever. bantime.increment (fail2ban 0.11.1 and later) multiplies the ban on each repeat; set bantime.maxtime so it stops growing. The recidive jail gives a week-long ban to addresses fail2ban keeps banning. Unlike -1, each of those bans expires.
Will a GeoIPHub outage stop fail2ban from banning?
Not with this action. The sshd ban is recorded before the lookup. With the GeoIPHub API unreachable in our test, the ban still happened and only the escalation was skipped.
How many lookups does this use?
The action uses one per ban, and none for an address looked up in the last 24 hours. The crawler ignorecommand uses one per address per 5 minute cache window. GeoIPHub's free plan includes 1,500 lookups a day with every field.
Should fail2ban ban Shodan and Censys?
The Shodan and Censys addresses we looked up scored 0 and are labelled benign scanners. In our test the Censys address got the normal sshd ban and no escalation.
The team behind the GeoIPHub API
Written by the GeoIPHub team, the people who build the GeoIPHub IP intelligence API and its scanner. Drafts are prepared with AI assistance and edited by the team; API examples are real lookups against the live API unless labelled illustrative.


