Allow traffic from specific countries only

Last updated May 5, 2026 This example custom rule blocks requests based on country code using the ip.src.country field, only allowing requests from two countries: United States and Mexico.

  • When incoming requests match:
Field Operator Value
Country is not in Mexico, United States

If you are using the expression editor:
(not ip.src.country in {"US" "MX"}) - Then take action: Block

Other resources

Was this helpful?

YesNo

On this page

Allow traffic from specific countries on - 图1Docs

{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/waf/custom-rules/use-cases/allow-traffic-from-specific-countries/#page","headline":"Allow traffic from specific countries only","description":"Allow traffic only from specific countries.","url":"https://developers.cloudflare.com/waf/custom-rules/use-cases/allow-traffic-from-specific-countries/","inLanguage":"en","image":"https://developers.cloudflare.com/waf/custom-rules/use-cases/allow-traffic-from-specific-countries/og.png?v=fe155ea220236639","dateModified":"2026-05-05","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"},"keywords":["Geolocation"]}


description: Allow traffic from search engine and verified bots. title: Allow traffic from search engine bots image: https://developers.cloudflare.com/waf/custom-rules/use-cases/allow-traffic-from-verified-bots/og.png?v=e38f9bd010e48e03


Skip to content

Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/waf/llms.txt
Use this file to discover all available pages before exploring further.