"But then I started thinking, "Cloudflare is pretty powerful" and enables you to do a lot of stuff, for FREE even."
I had a customer recently ask how they could block certain countries from accessing their website.
My automatic reaction, and started typing out a response, was that isn't possible with the type of platform that was referenced. But then I started thinking, "Cloudflare is pretty powerful" and enables you to do a lot of stuff, for FREE even.
We use Cloudflare's DNS for our home network which provides a certain amount of security & speed, and I point all of my websites to Cloudflare since it provides so many options. Domain forwarding? Got it. Free, no-nonsense SSL? Got it. Email forwarding from a fake email address to your personal email address? Got it. Hide your website's IP via proxy? Got it. Blocking countries and IPs from accessing your website? Got it. ALL for free. I often wonder how Cloudflare makes money.
So back to the subject, how do you block certain countries (or IP addresses) from accessing your website, such as those that are notorious for hosting bots & hacking?
I'm not going to go into creating a Cloudflare account and pointing your domain to it and setting that all up, but once you do have it all set up it's really, really easy (this is in the new dashboard interface as of this post date).
- Log into Cloudflare and select the domain you want to have blocked from certain countries.
- Select SECURITY from the left sidebar.
- Select SECURITY RULES
- CREATE RULE > IP ACCESS RULES.
- Select the IP, IP range, country name, or ASN field.
- Start typing the country to search.
- Leave the ACTION drop down to BLOCK.
- For ZONE, you can either select "This website", or "All websites in this account".
- Select CREATE.
Suggested blocklist: AF, BY, CN, IR, KP, PS, RU, RS, SY, TR, VN
That's it!
You can also do the opposite and whitelist only the countries you want to have access to your website.