As traffic is the driving force of any website, owners often welcome an increase in the number of visitors. However, these surges can sometimes be caused by hackers and bots. As a website administrator, you can usually trace these attacks to specific countries. If traffic from these countries is not relevant to the operation of your website, blocking them is the best option. This way you will safeguard your website and protect visitors from harm.
If you’re not sure how to do this, you’ve come to the right place. Read on to learn how to block a country using Cloudflare.
Why block a country from your website?
Security is the most common reason for preventing users from visiting your website. Every website is somewhat vulnerable to malicious traffic and security attacks. The most frequent attacks are:
- XSS attacks, which can compromise the private information of website users.
- DDoS attacks, which take a website offline temporarily or permanently.
- Phishing attacks, which can compromise the sensitive information of website users.
- Injection attacks, which target the server database directly and reveal user input and hidden data.
- Directory traversal attacks, which can compromise access to the website, databases, and configuration files.
If most of these attacks come from one or more specific countries, blocking them will save you and your website a lot of trouble.
Another reason for geoblocking is having a country-specific website. Let’s say you have an online store that only serves people living in one country. If that’s the case, blocking other countries can protect your server resources from being drained by useless traffic.
Finally, copyright, license terms, and other legal obligations may require blocking certain countries from accessing your website content.
How to know which countries to block
Although conversations about cyberattacks mainly revolve around China and Russia, each website is different. There’s no need to guess as you can quickly check site analytics to determine where threats are coming from.
- Login in your Cloudflare account.

- Select the domain whose analytics you want to view at the top of your page.

- Tap the “Analysis” icon from the list of blue icons at the top of the page.

- Go to the “Security” tab.

- Navigate to the “Threats by Country” dashboard.

This dashboard is an interactive map that highlights the countries where threats to your website originated. Cloudflare Firewall provides most of the metrics for this tab.
To see where most attacks are coming from, see the “Countries/regions with top threats” data table.
Cloudflare How to block a country
There are several ways to block a country on your website, including using ModSecurity or .htaccess files. However, if you don’t have access to your web server, using Cloudflare Firewall can be helpful.
For this method to work, you must have a Cloudflare account. Additionally, the account must be enabled for the domain for which you want to block traffic. Finally, the geo-blocking feature works best if you’re on Enterprise plan.
Once everything is set up, blocking a country in Cloudflare using the built-in Firewall feature is relatively simple:
- Login in your Cloudflare account.

- If you own multiple domains, select the domain you want this rule to apply to at the top of the page.

- Click the “Security” icon from the list at the top of your page.

- Tap the “Firewall Rules” tab.

- Press the blue “Create a firewall rule” button.

- Enter a descriptive name in the “Rule Name” field, for example, “Block faulty countries.”

- Navigate to the “When incoming requests match…” section.

- Under “Field,” select “Country.”

- Once the remaining fields in the section are no longer grayed out, set the “Operator” field to “is in.”

- Tap the “Value” tab to display a list of countries.

- Select each country whose access to your website you want to block.

- Click the “O” button next to the list of countries.

- Go to the “Then…” section.

- Under “Choose an action,” select “Block.”

- Once you have set up all the countries, press the “Deploy” button.

The Firewall rule has already been created. All traffic from the countries you have selected will be blocked.
However, the established rule is not finite. You can always edit it to add or remove a country. Here’s what you should do:
- Navigate to the “Firewall Rules” tab.

- Scroll down to the list of rules.

- Tap the wrench icon to the right of the rule you want to edit.

- Go to the “Value” field in the “When incoming requests match…” section.

To block a new country, tap the “Value” field and select the country from the drop-down list. If you want to unblock a country, simply tap the “x” sign next to its name.
Once you are happy with the updated list, press “Save” in the lower right corner of the screen.
If you want to block traffic from specific countries periodically, you can create a separate rule for them. Then, when you want to unlock the countries, you can disable the button next to the wrench icon. This disables the Firewall rule until you decide to enable it again.
Additionally, you can also delete a rule entirely if you no longer need it. Simply press the “x” button to the far right of the rule names.
How to make sure the firewall is working
If you are not sure whether you have configured the Firewall rule correctly, you can check the Firewall statistics periodically. Here’s what you should do:
- Tap the “Security” icon from the list at the top of your page.

- Go to the “Overview” tab.

- Scroll down to “Activity Log.”

In the “Activity Log”, you can see the following tabs:
- Date
- Action taken
- Country
- IP adress
- Service
You can search for the countries you have blocked in the “Country” tab. If you successfully blocked that country, the “Action Taken” tab next to it will show “Block.”
Security First
Protecting a website from malicious bots and hackers is the main reason why administrators consider blocking a country on their website. Whether or not you’re considering geoblocking for the same reason, Cloudflare offers you an easy way to achieve your goals.
The best aspect of using a firewall is knowing that it does not affect your website or its traffic in a detrimental way. It simply blocks requests coming from unwanted countries before they can cause a problem.