This question already has an answer here:

How can I block specific countries accessing Magento 2 site?

marked as duplicate by Jai, Manashvi Birla, Shoaib Munir, sv3n, saravanavelu May 27 at 9:06

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • please explain breifly – Rk Rathod May 27 at 5:47

You can block access to specific countries either in .htaccess or free Magento extensions available

  1. Find the reliable list of IP's for the country you want to block from IP2location

    1: https://www.ip2location.com/free/visitor-blocker. Input the country name and generate the IP's list for the country you want to block. Open the .htaccess file and copy the code from downloaded file similar to the lines below

    order deny,allow deny from deny from deny from  allow from all

Save the changes and the IP's from these countries will be denied access to Magento store.

  1. Else use this free extension to configure the countries to be blocked in the backend so the module does other work to restrict access for specific countries https://www.mageworx.com/geo-lock-magento2-extension.html
  • blocking countries in application or http web server is a bad idea, firewall is the proper place for this task. – MagenX May 27 at 8:12

Every country is assigned a range of IP addresses. You can allow or deny your website from being accessed from a specific IP or a list of IP addresses by using the .htaccess method.

Not the answer you're looking for? Browse other questions tagged or ask your own question.