Guides Guides 5 min read 984 words

Cloudflare Block Country: Set Up and Test a Rule

Use a Cloudflare block country rule to filter traffic by location. Follow the current setup, test matched requests, and avoid blocking useful visitors.

To block a country in Cloudflare, create a custom security rule that matches the request's Country field and applies the Block action. The website hostname must be proxied through Cloudflare: changing DNS providers alone does not put every request through its security controls.

We recommend defining the reason for the restriction before deploying it. A country rule is a broad access decision, not proof that a visitor is malicious. This guide covers the current dashboard workflow, verification, rollback, and the server-side alternative discussed in our earlier country-blocking article.

What a country rule actually matches

Cloudflare's documented country-blocking example uses ip.src.country. The rule evaluates the country associated with the request's source IP address. It does not identify a person's citizenship, home address, or intentions. Treat its result as a network-location signal rather than an identity check.

This distinction matters when reviewing complaints or deciding whether a restriction is suitable. A location condition cannot replace authentication for a private area. Nor should we describe it as a guarantee that unwanted automation will disappear: requests that do not match the condition will not be blocked by this particular rule.

First confirm that the relevant website record is proxied. Our Cloudflare proxy guide explains that prerequisite; our Cloudflare setup guide covers the wider domain setup. Keep a separate way to reach your Cloudflare account so that a website access restriction does not prevent you from correcting it.

Create the rule in the current dashboard

  1. Sign in to Cloudflare and select the website you intend to protect. Check the domain before making changes.
  2. Open Security rules. Select Create rule, then Custom rules. Older screenshots may show a WAF navigation path instead.
  3. Enter a descriptive Rule name. Describe the restriction rather than using a generic name that will be hard to recognize later.
  4. Under When incoming requests match, choose Country as the field and is in as the operator. Select only the countries required by your policy.
  5. Review the resulting condition. In the expression editor, Cloudflare's own single-country example is (ip.src.country in {"KP"}). This illustrates syntax, not our recommendation to block that location.
  6. Under Then take action, choose Block when you are ready to enforce a hard restriction.
  7. Select Deploy to activate the rule, or Save as Draft if it is not ready.

Cloudflare recommends validating a new rule before enforcing it. Enterprise customers can use Log; on plans without that action, its documentation suggests starting with Managed Challenge, reviewing Security Events, and then switching to Block. A challenge is not the same as a country ban, so do not leave it in place while claiming that every matching request is refused.

Illustration of a stop sign standing on a globe.
Cloudflare published custom-rule reference showing empty Field and Operator selectors; no country is selected.
Cropped reference from Cloudflare’s published custom-rule guide, checked 13 November 2026. Empty controls are shown; no country rule was deployed or tested. Source: https://developers.cloudflare.com/waf/custom-rules/create-dashboard/
Cloudflare published custom-rule reference showing the empty Choose action selector.
Cropped reference from Cloudflare’s published custom-rule guide, checked 13 November 2026. Empty controls are shown; no country rule was deployed or tested. Source: https://developers.cloudflare.com/waf/custom-rules/create-dashboard/

Choose scope from evidence, not country lists

We do not publish a universal list of countries every website should block. Start with the affected service and the requests you actually need to control. A public information site and a private administrative endpoint need different policies. Restricting the entire website is a larger decision than protecting one troublesome route.

Before deploying, list legitimate integrations that need access: monitoring, APIs, and other automated clients should be part of the review. Check the conditions against those requests rather than assuming a geographic rule understands their purpose. Our guide to blocking bots helps separate automation controls from simple location filtering.

Country restrictions can form part of a business access policy, but this article does not establish whether they satisfy any particular legal obligation. Do not turn a dashboard setting into a compliance claim without a separate assessment.

Verify the match and keep an undo path

After deployment, inspect Security Events for requests matched by the new rule. Confirm both the rule and the action, rather than inferring success from a fall in aggregate traffic. Check a permitted visitor journey as well: a rule can match the intended country yet still have an unsuitable scope.

If the results are wrong, return to the same rule and disable it while you review the condition. Record the previous configuration before editing so you can restore the intended policy. Make one rule change at a time; changing several controls together makes it harder to identify which one caused an access problem.

If no expected requests match, check the hostname's proxy status and the actual request condition. A DNS-only website connection bypasses Cloudflare's HTTP proxy, so a security rule at that proxy cannot govern it. Also review other security rules rather than treating one newly deployed rule as the whole access policy.

What about blocking countries with .htaccess?

Our earlier server-side guide used GeoIP directives. Do not copy those instructions as a portable Apache recipe: country lookup requires server support and data that a plain access-control condition does not supply. Ask the host which geolocation integration is installed before adapting any module-specific configuration.

Apache's current access-control guide documents Require ip and combinations such as RequireAll for addresses and networks. It also warns that legacy Allow, Deny, and Order directives are deprecated. IP ranges are not themselves a maintained country database. For more context, read what an .htaccess file controls. If you are also checking which company manages the domain, our domain lookup tool serves a different purpose: it is not a visitor geolocation test.

Country-blocking FAQ

Does changing nameservers enable the restriction?

No. The website traffic must actually pass through the Cloudflare proxy, and the matching custom rule must be deployed.

Is a country match evidence of an attack?

No. It identifies a request property used by the rule, not the visitor's intent. Review events and legitimate access requirements before choosing a broad block.

Sources