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.
Language | Client IP | Custom geo lookup | Automatic connection-based geo data |
---|---|---|---|
VCL | client.ip | client.geo.ip_override | See Geolocation variables |
Rust | get_client_ip_addr | geo_lookup | N/A |
JavaScript | event.connection.address | getGeolocationForIpAddress | event.client.geo |
Go | <Request>.RemoteAddr | geo.Lookup | N/A |
Here is an example of adding geo information to a request before forwarding it to a backend:
- Fastly VCL
- Rust
- JavaScript
- 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:
Property | VCL Variable | Value for reserved blocks |
---|---|---|
AS Number | client.as.number | 0 |
AS Name | client.as.name | ? |
Latitude | client.geo.latitude | 0.000 |
Longitude | client.geo.longitude | 0.000 |
Connection speed | client.geo.conn_speed | broadband |
Metro code | client.geo.metro_code | -1 |
UTC offset | client.geo.utc_offset | 9999 |
Area code | client.geo.area_code | 0 |
Postal code | client.geo.postal_code | 0 |
Continent code | client.geo.continent_code | ** |
Country code (2 char) | client.geo.country_code | ** |
Country code (3 char) | client.geo.country_code3 | *** |
Country name | client.geo.country_name | reserved/private |
City | client.geo.city | reserved |
Region | client.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.