Filter Traffic by Country Using Cloudflare
Cloudflare allows you to set up firewall rules to filter traffic based on geographic origin. This is useful for allowing, blocking, or challenging traffic from specific countries.
Prerequisites
- Access to your Cloudflare account
- A domain properly configured in Cloudflare
1. Log in to Cloudflare
- Go to the Cloudflare Dashboard
- Log in with your credentials
- Select the domain you want to configure
2. Go to Firewall Rules
- In the left-hand menu, click Security > WAF (Web Application Firewall)
- Select Firewall Rules
3. Create a new rule
- Click Create a Firewall Rule
- Give your rule a descriptive name, e.g., Filter Country - Italy
4. Configure the rule conditions
- In the Field section, select:
Country
- In the operator column, choose:
- is: to include traffic only from the selected country
- is not: to exclude traffic from the selected country
- In the Value field, select the country (e.g., Italy)
5. Set the action
Choose the desired action for traffic matching the rule:
- Allow: allows only traffic from the selected country
- Block: completely blocks traffic from the selected country
- Challenge (Captcha): requires users to complete a CAPTCHA
- JS Challenge: runs a JavaScript challenge on the request
6. Save and apply the rule
- Click Deploy to activate the rule
- The rule will be applied immediately and shown in the Firewall Rules list
Example: block traffic from Italy
- Field: Country
- Operator: is
- Value: Italy
- Action: Block
Monitoring and management
- Go to Security > Events to monitor activity related to the rule
- Ensure the rule works as expected
- Edit or disable the rule if needed
Additional notes
- Firewall rules do not affect internal Cloudflare traffic (e.g., API calls or admin access)
- Use caution when configuring rules to avoid blocking legitimate users
- For further assistance, contact Utixo technical support