If you manage your DNS records through Cloudflare, then controlling IP addresses of visitors from specific countries is just a matter of specifying WAF (Web Application Firewall) rules. Let me show you, how to completely ban specific countries from accessing your website. As a purely random example, we will pick Russia and Belarus as target countries.
Pick a Website
Assuming you are currently logged into your Cloudflare dashboard, from the main page, pick one of your active websites where you want to apply the country limitation.
Accessing Web Application Firewall
On the sidebar, go to Security - WAF and click on the Create firewall rule button.
Adding new Rule and Deployment
Fill all of the mandatory fields, give your new rule a name. In my example for tutorial purposes I have picked purely random name like Ban Reds to give it some meaning.
Now specify criteria for incomming requests:
- for the
Field
selectCountry
- for the
Operator
selectis in
(but if you have just a single target then you can also useequals
) - for the
Value
, simply pickRussian Federation
andBelarus
Finally define what should happen if an incomming request matches these criteria, in our case we simply want to block access. Save changes by clicking Deploy firewall rule.
The following screen shows your newly deployed rule.
This is everything. Obviously there are VPNs or similar services to bypass such a limitation, but this should be a nice starting point anyway.