Skip to content
AnswerWell geo Documentation

Research · 7 min read · Answerwell

IP Geolocation Rules, Fields and Country-Based Traffic Control

How edge platforms derive country and region from client IPs, which rule fields and headers expose it, and how to block or filter traffic by location.

This page summarises Cloudflare documentation on IP geolocation: how visitor location is inferred from IP addresses, which Ruleset Engine fields and WAF expressions use that data, how Cloudflare One Gateway policies filter by source or destination geography, and what appears in Logpush logs and HTTP headers such as CF-IPCountry.

Geolocation data on the Cloudflare network is tied to GeoIP databases (Cloudflare’s field references note that GeoIP is a registered trademark of MaxMind, Inc.). Values are approximate—city names are described as “approximate” in several log field definitions, and policies should assume VPNs, corporate egress, and mobile networks can misplace a client relative to their physical location.

Ruleset Engine geolocation fields: country, region and city on ip.src

Section titled “Ruleset Engine geolocation fields: country, region and city on ip.src”

Rules that run at the HTTP edge match on request fields under the ip.src.* namespace. These replace the older ip.geoip.* names; both may still work in existing rules, but new work should use ip.src.*.

ip.src.country: two-letter ISO country code for the client IP

Section titled “ip.src.country: two-letter ISO country code for the client IP”

ip.src.country is the primary field for country-based blocking or allow lists at the zone edge.

The 2-letter country code in ISO 3166-1 Alpha 2 format.

— Cloudflare, ip.src.country

The same page states that ip.src.country has the same value as the deprecated ip.geoip.country field, and that you should use ip.src.country instead.

Related source fields from the same reference family include:

Field Purpose (from Cloudflare field docs)
ip.src.continent Continent code (NA, EU, …); includes special value T1 for Tor
ip.src.city City name (example: "San Francisco")
ip.src.region Region name (example: "Texas")
ip.src.region_code Region code (example: "TX")
ip.src.lat / ip.src.lon Latitude and longitude strings
ip.src.postal_code Postal code (example: "78701")

ip.src.subdivision_* and EU membership: plan-gated geolocation fields

Section titled “ip.src.subdivision_* and EU membership: plan-gated geolocation fields”

Some finer-grained fields are not available on all plans:

ip.src.timezone.name is geolocation-related but only available in rewrite expressions of Transform Rules, not as a general match field everywhere.

For destination (server) geography on packet-level products, Cloudflare Network Firewall fields document ip.dst.country alongside ip.src.country. On Network Firewall, deprecated ip.geoip.country matches either source or destination; Cloudflare recommends ip.src.country and/or ip.dst.country instead.

WAF custom rules: how to block or allow traffic by country

Section titled “WAF custom rules: how to block or allow traffic by country”

Administrators who want to block traffic from specific countries or allow only certain countries typically use custom rules in the WAF, matching geolocation fields in the rule expression.

The block traffic by geographical location use-case page points to:

  • Use case: Block traffic from specific countries
  • Use case: Allow traffic from specific countries only
  • Fields reference: Geolocation

In practice, country rules at the HTTP layer use expressions on fields such as ip.src.country (and optionally continent or region fields). Threat types analytics include Country block as requests from countries blocked based on WAF user configuration—useful when verifying that geo blocks are firing.

ip.src.metro_code: DMA / metro market geolocation in rules

Section titled “ip.src.metro_code: DMA / metro market geolocation in rules”

For United States–style market areas, Cloudflare added DMA (Designated Market Area) data to the Ruleset Engine.

The ip.src.metro_code field in the Ruleset Engine is now populated with DMA (Designated Market Area) data.

You can use this field to build rules that target traffic based on geographic market areas, enabling more granular location-based policies for your applications.

— Cloudflare, Metro code field now available in Rules

Field Type Meaning
ip.src.metro_code String | null Metro/DMA code for the client IP

Example filter from the same changelog:

ip.src.metro_code eq "501"

The dedicated field reference ip.src.metro_code gives example value "635" and categorises the field under Request and Geolocation.

CF-IPCountry and visitor location HTTP headers

Section titled “CF-IPCountry and visitor location HTTP headers”

Applications behind Cloudflare often read geolocation from response or request headers instead of writing WAF rules.

The CF-IPCountry header contains a two-character country code of the originating visitor’s country.

— Cloudflare, Cloudflare HTTP headers

Besides ISO 3166-1 alpha-2 codes, Cloudflare documents:

  • XX — clients without country code data
  • T1 — clients using the Tor network

To add CF-IPCountry along with other visitor location headers, enable the Add visitor location headers Managed Transform.

Zaraz exposes similar concepts as tag manager Device location properties: City, Continent, Country code, EU country (1/0), Region, Region code, and Timezone for the incoming request.

Cloudflare One Gateway: DNS, HTTP and network policies by geo

Section titled “Cloudflare One Gateway: DNS, HTTP and network policies by geo”

For Zero Trust traffic through Cloudflare Gateway, geolocation selectors use different expression namespaces than zone WAF fields. Source geography is generally taken from the device’s public IP (typically the ISP-assigned address); destination geography comes from the target or resolved IP, depending on policy type.

DNS and resolver policies (source vs resolved destination)

Section titled “DNS and resolver policies (source vs resolved destination)”

DNS policies include:

UI concept API example When evaluated
Source Country IP Geolocation dns.src.geo.country == "RU" Before DNS resolution
Source Continent IP Geolocation dns.src.geo.continent == "North America" Before DNS resolution
Resolved Country IP Geolocation dns.dst.geo.country == "RU" After DNS resolution
Resolved Continent IP Geolocation dns.dst.geo.continent == "EU" After DNS resolution

Resolver policies document the same source continent and country selectors (dns.src.geo.*) evaluated before resolution.

Continent codes are consistent across Gateway docs: AF, AN, AS, EU, NA, OC, SA.

  • HTTP policies: http.src_ip.geo.country, http.dst_ip.geo.country, and matching continent fields. Destination continent/country selectors only apply to traffic sent through the Cloudflare One Client (noted on those sections).
  • Network policies and egress policies: net.src.geo.* and net.dst.geo.* for session source and destination geography.

Gateway Logpush datasets mirror this split. For example, Gateway DNS logs SrcIPCountryCode, ResolvedIPCountryCodes, and colo identifiers; Gateway HTTP and Gateway Network log source and destination country and continent codes.

Edge colocation vs client geolocation in logs and analytics

Section titled “Edge colocation vs client geolocation in logs and analytics”

Do not confuse where the visitor appears to be with which Cloudflare data center handled the request.

Common Logpush fields:

Field / dataset Meaning
ClientCountry on HTTP Requests 2-letter ISO-3166 country of the client IP
ClientCity Approximate city of the client
EdgeColoCode IATA airport code of the data center that received the request
ColoCode on Firewall Events Airport code of the colo that served the request

Network Analytics Logs go further: ColoCountry is the country where the Cloudflare data center that received the packet is located, while SourceCountry / DestinationCountry describe the packet IPs—a useful distinction when debugging anycast routing versus geo blocking.

Rules and firewall products also expose colo match fields such as cf.colo.name (example: sfo06) and cf.colo.region (example: WNAM) for the data center handling traffic—not the visitor’s home country.

Network Analytics dashboards can show top source data centers and optionally the country associated with those data centers—again, edge ingress geography, not the same card as client country in HTTP logs.

  • Mixing field families: Zone WAF uses ip.src.country; Gateway HTTP policies use http.src_ip.geo.country. Copy-pasting expressions across products fails silently or never matches.
  • Ignoring XX, T1, and empty subdivisions: Missing geo data and Tor traffic need explicit rule handling.
  • Blocking on colo country: Blocking “traffic from Germany” using data center country fields blocks by edge location, not client GeoIP.
  • Assuming headers reach the origin: Without Managed Transforms, CF-IPCountry may be absent; with Workers, the header may be stripped on certain fetch paths.
  • Staying on deprecated ip.geoip.*: Still supported, but field references state ip.src.* equivalents should be used for new rules.
  1. Create or edit a WAF custom rule that matches ip.src.country (or allow-list logic), deploy it, and generate test requests from an IP in the targeted country using a controlled egress or test host.

  2. Confirm matching in Firewall Events (fields ClientCountry, EdgeColoCode) or zone analytics threat types for Country block if the action is block.

  3. If the application reads visitor country at the origin, enable Add visitor location headers and verify CF-IPCountry per Cloudflare HTTP headers; retest any path that uses Workers to the origin.

  4. For Zero Trust, validate Gateway selectors on DNS policies or HTTP policies against Gateway HTTP or Gateway DNS log fields for SrcIPCountryCode / resolved destination codes.

  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact sentence you are asking about, and we will correct or clarify it.