Skip to main content

๐Ÿ”ง Handling BunnyCDN IP Blocked by Fail2Ban / iptables



๐ŸŽฏ Tujuan

Mengidentifikasi dan memperbaiki kondisi di mana IP BunnyCDN terblokir oleh:

  • iptables

  • fail2ban

Yang menyebabkan:

  • โŒ CDN error 504 Gateway Timeout

  • โŒ Asset (CSS/JS) gagal load


๐Ÿงฉ Prasyarat

  • Akses root / sudo

  • File list IP Bunny: bunny_ips.txt


๐Ÿชœ STEP 1 โ€” Tambahkan IP Bunny ke file

Buat / update file:

nano bunny_ips.txt

Isi dengan IP Bunny (1 IP per baris):

89.187.188.227
89.187.188.228
...

๐Ÿชœ STEP 2 โ€” Cek IP yang diblok oleh iptables

Gunakan command berikut:

for ip in $(cat bunny_ips.txt); do
  sudo iptables -L -n -w | grep $ip && echo "BLOCKED: $ip"
done

๐Ÿ“Œ Catatan:

  • Gunakan -w untuk menghindari error:

    xtables lock
    

๐Ÿชœ STEP 3 โ€” Cek IP yang diblok oleh Fail2Ban

sudo grep -f bunny_ips.txt /var/log/fail2ban.log > blocked-f2b.log

๐Ÿ‘‰ Hasil:

  • file blocked-f2b.log berisi IP yang pernah di-ban


๐Ÿชœ STEP 4 โ€” Kumpulkan IP yang aktif terblokir di iptables

Dump rules:

sudo iptables -L -n -w > iptables_rules.txt

Filter IP Bunny:

grep -f bunny_ips.txt iptables_rules.txt > blocked-bunny-cdn.log

๐Ÿชœ STEP 5 โ€” Unban IP dari Fail2Ban

Unban semua IP Bunny:

for ip in $(cat bunny_ips.txt); do
  sudo fail2ban-client set apache-badbots unbanip $ip
done

๐Ÿ“Œ Jika ada jail lain, cek:

fail2ban-client status

๐Ÿชœ STEP 6 โ€” Tambahkan IP ke whitelist Fail2Ban

Edit file:

nano /etc/fail2ban/jail.local

๐Ÿ”น Tambahkan di [apache-badbots] atau [DEFAULT]

Contoh:

[DEFAULT]
ignoreip = 127.0.0.1/8 ::1 104.45.64.239/32 \
89.187.188.227/32 \
89.187.188.228/32 \
...

๐Ÿ“Œ Tips:

  • Gunakan \ untuk multi-line

  • Hindari 1 line terlalu panjang


๐Ÿชœ STEP 7 โ€” Validasi konfigurasi Fail2Ban

sudo fail2ban-client -d
sudo fail2ban-client -t

๐Ÿ‘‰ Pastikan:

  • tidak ada error config


๐Ÿชœ STEP 8 โ€” Restart & Verifikasi Fail2Ban

sudo systemctl restart fail2ban

๐Ÿ” Cek status:

sudo systemctl status fail2ban
sudo fail2ban-client status
sudo fail2ban-client status apache-badbots

๐Ÿงช STEP 9 โ€” Testing

Test via CDN:

curl -I https://cotecna-cdn.b-cdn.net/css/app.min.css

Expected:

HTTP/1.1 200 OK

๐Ÿšจ Troubleshooting tambahan

โ— Masih kena block?

Cek jail lain:

fail2ban-client status

โ— Masih 504?

Cek:

  • Nginx log:

tail -f /var/log/nginx/error.log
  • Origin connectivity:

curl -I http://localhost

๐Ÿ’ก Best Practice (Highly Recommended)

โœ… 1. Jangan hanya pakai /32

Gunakan kombinasi:

  • /32 โ†’ IP spesifik

  • /16 โ†’ range CDN


โœ… 2. Pertimbangkan disable badbots

sudo nano /etc/fail2ban/jail.local
[apache-badbots]
enabled = false

โœ… 3. CDN-aware security

Lebih baik:

  • proteksi bot di CDN (Bunny Shield / WAF)

  • bukan di origin


๐ŸŽฏ Kesimpulan

Checklist akhir:

  • โœ… IP Bunny tidak diblok iptables

  • โœ… IP Bunny tidak diban fail2ban

  • โœ… Sudah di whitelist

  • โœ… Fail2Ban sudah restart

  • โœ… CDN return 200 OK


๐Ÿš€ Bonus (Optional Automation)

Kalau mau otomatis:

awk '{print $1"/32 \\"}' bunny_ips.txt

๐Ÿ‘‰ langsung jadi format ignoreip


Kalau mau, gue bisa bantu bikin:

  • script auto sync IP Bunny (cron)

  • atau integrasi dengan API Bunny biar gak manual lagi