IP-based geolocation and intelligence

Fastly is able to determine the approximate general physical location of the end user based on their IP address. This is useful for providing content suitable for the region the user lives in, or enforcing licensing restrictions on content distribution.

IMPORTANT: IP geolocation information, including data streamed by our log streaming service, is intended to be used only in connection with your Fastly services. Use of IP geolocation data for other purposes may require permission from Digital Element, our data supplier.

Geolocation data is exposed in VCL and all official Compute SDKs. The IP address used for the geolocation lookup is automatically populated from the connection in some languages, but you can also always fetch geolocation data for an arbitrary IP.

LanguageClient IPCustom geo lookupAutomatic connection-based geo data
VCLclient.ipclient.geo.ip_overrideSee Geolocation variables
Rustget_client_ip_addrgeo_lookupN/A
JavaScriptevent.connection.addressgetGeolocationForIpAddressevent.client.geo
Go<Request>.RemoteAddrgeo.LookupN/A

Here is an example of adding geo information to a request before forwarding it to a backend:

  1. Fastly VCL
  2. Rust
  3. JavaScript
  4. Go

WARNING: Avoid using location data to select a language. The ability to speak a language is a property of a person, not the location where they are currently located. If possible, use the Accept-Language header to customize language preferences.

Data updates and accuracy

The data is updated periodically, as IP allocations change and various amendments are made. Fastly does not own or control the data or the update frequency, but we release the latest version of the database to our network twice a week. If you discover inaccurate IP geolocation data, please report it to Fastly support.

Location information for some IPs is much more accurate than for others. IPs belonging to businesses may identify a specific office building. The location of domestic internet users will usually be less accurate, but close enough to identify the correct city. Mobile devices connected to cellular networks may not be anywhere near the actual location of the user but will usually be in the same country.

Some variables may be absent at any given time. For STRING types, the special value ? is used to indicate absent data.

Reserved IP address blocks

The IPv4 and IPv6 address spaces have several blocks reserved for special uses; these include private use networks (e.g., 192.168.0.0/16), loopback (127.0.0.1/8), and address ranges reserved for documentation (e.g., 203.0.113.0/24 RFC 5737 TEST-NET-3).

Geographic data has no meaningful association for these ranges, and so the Geolocation VCL variables present special values for these ranges instead. These values are:

PropertyVCL VariableValue for reserved blocks
AS Numberclient.as.number0
AS Nameclient.as.name?
Latitudeclient.geo.latitude0.000
Longitudeclient.geo.longitude0.000
Connection speedclient.geo.conn_speedbroadband
Metro codeclient.geo.metro_code-1
UTC offsetclient.geo.utc_offset9999
Area codeclient.geo.area_code0
Postal codeclient.geo.postal_code0
Continent codeclient.geo.continent_code**
Country code (2 char)client.geo.country_code**
Country code (3 char)client.geo.country_code3***
Country nameclient.geo.country_namereserved/private
Cityclient.geo.cityreserved
Regionclient.geo.region***

AOL data

The third-party geolocation database that Fastly uses may return "AOL" for region and city properties, despite AOL not representing a region or city per the region code requirements stated in ISO 3166-2.

AOL, an internet service provider, assigns dial-up users an internet access point based on the country in which their AOL account is established. This means that the IP addresses associated with their access to the internet don't necessarily reflect the country from which they are connecting.