Hello. Can you help me block specific countries from accessing my website.
Thank you.
Sincerely,
Chris Anthony
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.
Hello there,
You can use CSF in order to block a country, you can use the
CC_DENY
option which accepts two-letter country codes such as US, GB and etc.In order to list more than one country you just need to separate them using commas:
CC_DENY = "AB,CD,EF"
You may find a list of ISO 3166-1 alpha-2 code at https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
If you’re not familiar with CSF or you want to install it on CentOS or Ubuntu droplet check out this mini tutorial:
For CentOS:
https://www.digitalocean.com/community/questions/how-to-install-and-configure-config-server-firewall-csf-on-centos
For Ubuntu:
https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-config-server-firewall-csf-on-ubuntu
Hope that this helps!
I recommend you setting up your website with Cloudflare, I believe that they have a feature that allows you to block certain countries from accessing your website.
How detailed do you want the list. If you want to do mass blocking you could use https://www.iana.org/assignments/ipv4-address-space/ipv4-address-space.xml
For instance if you want to block all APNIC (Asia Pacific ips) firewall off all the APNIC /8 entries.
http://www.ip2location.com/free/visitor-blocker lets you do it by country but that take a lot of time to compile a list unless you are targeting only a couple countries.
Of course they could always use a proxy to bypass this.