sync-allow-ips-to-fail2ban
Sync IPs from allow-ips-manual.conf to fail2ban ignoreip
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 4
- Forks
- 1
01 前言 Front Matter
- name
- sync-allow-ips-to-fail2ban
- version
- 1.0.0
- description
- Sync IPs from allow-ips-manual.conf to fail2ban ignoreip
03 SKILL.md 正文
Sync Allow IPs to fail2ban
Trigger
User says "add/remove an allow IP" or "sync IPs to fail2ban".
Workflow — 3 steps (always do ALL):
Step 1 — Create/update the source script
Script lives at ~/.hermes/scripts/local-sync-allow-ips-to-fail2ban.sh:
#!/bin/bash
# Reads IPs from /etc/nginx/allow-ips-manual.conf, strips 127.0.0.1/::1,
# updates ignoreip in /etc/fail2ban/jail.local, reloads fail2ban.
ALLOW_FILE="/etc/nginx/allow-ips-manual.conf"
JAIL_LOCAL="/etc/fail2ban/jail.local"
# Extract IPs/CIDRs (skip comments, strip "allow " and ";")
IPS=$(grep -oP 'allow \K[^;]+' "$ALLOW_FILE" | grep -v '^127\.0\.0\.1$' | grep -v '^::1$' | tr '\n' ' ')
# Build new ignoreip line
NEW_IGNORE="ignoreip = 127.0.0.1/8 ::1 $IPS"
# Replace in jail.local
sed -i "s/^ignoreip = .*/$NEW_IGNORE/" "$JAIL_LOCAL"
# Reload fail2ban
fail2ban-client reload
Make it executable:
chmod +x ~/.hermes/scripts/local-sync-allow-ips-to-fail2ban.sh
Step 2 — Add an allow IP
Append the IP or CIDR to /etc/nginx/allow-ips-manual.conf (one per line):
allow 203.0.113.45;
allow 198.51.100.0/24;
Then run the sync script to propagate to fail2ban:
bash ~/.hermes/scripts/local-sync-allow-ips-to-fail2ban.sh
Step 3 — Verify
Confirm both layers picked up the IP:
# nginx layer — should show the allow line
grep -c "allow 203.0.113.45" /etc/nginx/allow-ips-manual.conf
# fail2ban layer — ignoreip should contain it
grep "^ignoreip" /etc/fail2ban/jail.local
# fail2ban reload succeeded
fail2ban-client status | grep -i "number of jail"
Pitfalls
- Never add
127.0.0.1or::1to the manual file — they're always inignoreipby construction; adding them is harmless but noisy. - The allow file is nginx
allowdirectives, not raw IPs — the extractor strips theallowprefix and trailing;. A malformed line (missing;) silently drops the IP. sedreplaces the wholeignoreipline — if jail.local is absent or lacks anignoreipline, the script no-ops; create the line first withsed -i "s/^ignoreip = .*/ignoreip = 127.0.0.1\/8 ::1/" "$JAIL_LOCAL".- fail2ban reload is required — editing jail.local without
fail2ban-client reloadhas no effect until the next service restart. - Daily threat-pipeline cron (5AM) deploys blocked IPs from
deploy/nginx/blocked_ips.add— this allow-list flow is the complementary whitelist; keep them separate.
Related
threat-defense-pipeline— the blocking side (fail2ban jails + nginx IP blocking)linux-server-hardening— broader server security posture
04 同仓库更多 Skills
macbook-linux-maintenance
Legacy MacBook Linux fixes: GPU wedge, reboot hang, thermal.
governance-regression-triage
Triage a host's governance issues: what changed.
enforcement-immutability
Use when enforcement files lose their immutable flag.
steadfaste-fleet-repo-deploy
Use when committing to the steadfaste-fleet repo.
steadfaste-fleet-maintenance
Maintain an installed Steadfaste Fleet instance — update both the upstream Hermes Agent and the fleet repo layer, merge diverged histories, sync skills safely, and troubleshoot common issues. Covers the dual-update workflow (hermes update + fleet-update.sh), encrypted brain data backup, mycortex import, and recovery techniques.
fleet-preflight
DEPRECATED alias — merged into survey-before-action (2026-08-20). Load survey-before-action instead; its "Repo-Specific Pre-Flight" section covers git search, Hermes boundary, and deployment verification.