However - I noticed that on one of my sites, I was still getting automated attacks from one of the IPs in that list and that left me confused.
Why is that the case?
Isn’t the IPtable suppose to drop any hits to the server?
Or is it going to only drop hits that are made directly to the IP address of the server?
Or is the reason that the website domain is behind Cloudflare that IPtables firewall isn’t seeing the real IP of the website visitor?
However, i’m not sure about this one - I’m assuming that if the apache access logs are showing the real IP of the user then Cloudflare IPtables should see the real ip as well, right?
No, the web server sees the real IP because it extracts it from a header (CF-Connecting-IP) sent by Cloudflare. And no, iptables doesn’t see the real IP, it only sees Cloudflare’s IP. If you want to block that IP, you should create a deny rule on the web server, which is a pain, or better, block it on Cloudflare’s end.
Ok perfect, thank you! This clarifies a lot. This gives me peace of mind that the solution I’ve developed is the best way to move forward →
I’ve implemented the block on apache level. It doesn’t make sense to use Cloudflare because Cloudflare IP Lists only allow up to 10,000 entries per IP list and the IP list has more than 100,000 entries.
So - i’ve created an automated script that updates the IP list every day and used the Web Templates to configure Apache to deny hits to any IP in that list. The script also has test feature to allow you to test if it works or not.
Will share the process shortly, I’m writing a blog post on it
Rewritemap from what i’ve researched is pretty performant. And to further improve the performance - i’m going to change the implementation from txt to dbm file instead.
For a list with more than 100,000 IPs, keep in mind that every HTTP request will be checked. Well, Apache2 loads that list into memory so it shouldn’t be an issue, it could still cause slowness when restarting/reloading Apache2.
Using the DBM format will indeed be more efficient.
I don’t really use Apache myself, so go ahead, I’d be interested to know how well it performs on a medium to high traffic site.
I forgot to say that if the IP list contains networks like 203.0.113.0/24 (as they usually do) that RewriteCond won’t work.
Thankfully the list I have doesn’t have these CIDR notation
My sites don’t get so much traffic. I’m interested in testing this solution to ensure that i’m creating a solution that’s useful not just for me but others as well. My goal is to first ensure that this works with txt version properly.
Can you please help me understand, how much traffic according to you is medium to high traffic.
Personally for me - i’m confident that this solution is a good solution because →
I’m caching the site’s HTML on Cloudflare completely
I have rate limiting rules set on Cloudflare
So the hits on the apache are quite low for me. But - as I said - your inputs will help me refine this approach and make a more generic solution that can be applied by others.
In hestiacp, edit the domain and select the blocklist template for webserver
run the script… ~/tools/abuseipblocker.sh update
Test if you are getting blocked by apache or not by running - ~/tools/abuseipblocker.sh test
the test script will unblock you as well. But if it works then you’ve done everything correctly.
Add a cron to update the iplist regularly by running this command ~/tools/abuseipblocker.sh update
Please note - This is the fully functioning version, the rest of the repo has another advanced version that i’m working on, which will use nginx instead of Apache. Unfortunately that nginx version isn’t working properly yet - so stick with the instructions shared here and use abuseipblock-original-dbm.sh script only.