How to Block a Country from Your WordPress Website Using cPanel

With a surge in the numbers of attacks on websites, it’s vital to take essential steps. I remember when I faced a hard time with my website, it was because of the code injection.

Have you ever monitored your website’s visitors? Your security plugin may collect the login attempts, and it’s important to check if multiple attempts are made from the same country.

You can block an IP address from accessing your website, but when you notice any suspicious country, you should prevent the whole country from accessing your site.

Well, you will be happy to know that, you can block a whole country using .htaccess, by adding the IP address ranges.

You should also understand that if you target a bigger country, there may be hundreds of IP ranges. Although mostly, you require to block a small country.

Blocking the US is the worst idea because if you can’t get traffic from the US, your website can’t last long in the international market.

In this article, you’re going to learn the most convenient way to block a country.

Have You Learned About the .htacces File

When you manage a WordPress site, you must learn the efficient use of .htaccess; it’s one of the essential files you may need once in a while.

I hope you know how to edit .htaccess.

Follow these steps.

Step 1:

Open your cPanel account and search for the file manager; you can find it under Files.

How to Block a Country from Your WordPress Website Using cPanel

The layout of your web hosting’s cPanel may be different, but the options remain similar. The primary web hosting companies Bluehost, Siteground, Digital Ocean, Inmotionhosting, etc. have alike cPanel.

Step 2:

Make sure you open the publc_html directory, not the home directory.

You can navigate to the root directory through the vertical navigation menu.

How to Block a Country from Your WordPress Website Using cPanel

Step 3:

Search for the .htaccess file, if you don’t find it, it’s because you haven’t enabled an option to see hidden files.

How to Block a Country from Your WordPress Website Using cPanel

Go to Settings at the top-right corner of cPanel, open and make sure you choose the checkbox to see hidden files.

Step 4:

Once you find the .htaccess file, right-click to edit, or you can use the traditional Edit option from the main navigation menu of cPanel.

Step 5:

A popup appears to authenticate, click on the Edit button and a new tab opens for you.

How to Block a Country from Your WordPress Website Using cPanel

Step 6:

Before you proceed, you must obtain the IP ranges for the country you want to block.

I recommend you useIP2Location, scroll down, and you can see the list of countries, choose the one you want to block.

How to Block a Country from Your WordPress Website Using cPanel

Selecting one output format from the drop-down menu is essential. Choose .htaccess deny; it consists of Apache as a prefix.

Click on the Download button, and you can find a text document on your computer downloads, open it and see the IP ranges of the country.

Step 7:

You need to copy the IP ranges and paste those into your .htaccess file.

 

Note: In the IP text file available on your computer, you find a few lines to display the IP2Location references, you don’t need to copy those lines. Start copying from the first IP address range line.

Let me show you an example.

Order Deny,allow
deny from 31.22.48.0/20
deny from 31.44.64.0/20
deny from 31.171.152.0/21
deny from 31.210.13.120/30
deny from 31.222.40.0/21
deny from 37.26.64.0/21
deny from 37.26.80.0/21
allow from all

The numbers of lines may vary, depending on the country you choose to block.

In the text document of IP addresses, you may also see <limit>; you don’t need those. Follow the example.

Copy and paste such code to .htaccess and click Save Changes from the top-right corner. Congrats, you have successfully prevented your selected country from accessing from WordPress site.

It may seem a little bit confusing, but the example will help you clear your doubts. For a country like the US, there may be 150+ IP address ranges.

Do You Still Have a Doubt

I remember when I blocked a country because there were so many brute force attack from that country. When you find something suspicious from the similar IP address ranges, you should check if the attacks are happening from the same country.

I hope you can easily add the suspicious IP address and block them to secure your WordPress website. It’s vital to learn such advanced WordPress security tricks.

Conclusion

If you’re a regular contributor to WordPress forums, you many websites are vulnerable. People ask for the help, to secure the data.

I am sure; you don’t want to lose your hard work. Well, if you’re going to secure your website, make sure you monitor the login attempts and bounce rate.

Check out these top 3 WordPress hosting services:

HostArmada
$1.79 /mo
Starting price
Visit HostArmada
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.5
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.0
IONOS
$1.00 /mo
Starting price
Visit IONOS
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.0
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.3
Ultahost
$2.90 /mo
Starting price
Visit Ultahost
Rating based on expert review
  • User Friendly
    4.3
  • Support
    4.8
  • Features
    4.5
  • Reliability
    4.0
  • Pricing
    4.8

How to Disable File Editing in the WordPress Admin Panel

This how-to guide explains to stop file editing from the WordPress admin panel t
3 min read
Arvind Singh
Arvind Singh
Hosting Expert

How to Stop Access to Sensitive Files of Your WordPress Website

This how-to guide explains to add another security layer to the sensitive files
3 min read
Arvind Singh
Arvind Singh
Hosting Expert

How to Disable the XML-RPC WordPress File Using cPanel

This how-to guide teaches you to disable the XML-RPC WordPress file to reduce th
3 min read
Arvind Singh
Arvind Singh
Hosting Expert

How to Block Hackers Using cPanel From Scanning Your Website's Authors

This how-to guide helps you understand the concept of protecting authors' names
3 min read
Arvind Singh
Arvind Singh
Hosting Expert
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top