Automatically unban legitimate search engine bots that were banned by Fail2Ban.
This tool verifies bots using FCrDNS (Forward-confirmed reverse DNS):
- Reverse DNS lookup: IP -> hostname (PTR)
- Hostname suffix validation against an allowlist
- Forward DNS lookup: hostname -> IP list
- Confirmation that the original IP is in the forward lookup results
If all checks pass, the script unbans the IP from the target jail.
fail2ban-unban-verified-bots.sh
googlebot.comgoogle.comsearch.msn.comapplebot.apple.comyandex.ruyandex.netyandex.com
You can edit ALLOWED_PTR_SUFFIXES in the script to match your needs.
bashfail2ban-client- DNS tools:
- preferred:
dig - fallback:
hostfor reverse DNS andgetentfor forward DNS
- preferred:
In the script:
LOGFILE: log destination (default:/var/log/fail2ban-unban-verified-bots.log)JAILS: list of jails to scan- empty array = all Fail2Ban jails
- example:
JAILS=(nginx-botsearch nginx-http-auth)
Run manually (usually as root):
sudo bash fail2ban-unban-verified-bots.shRun every 15 minutes:
*/15 * * * * /path/to/fail2ban-unban-verified-bots.sh[2026-03-10 12:34:56] UNBAN jail=nginx-botsearch ip=66.249.66.1 ptr=crawl-66-249-66-1.googlebot.com
- The script only unbans IPs that pass all FCrDNS checks.
- This reduces false positives while keeping protection active for unknown or spoofed crawlers.