Skip to content
Sign inDashboard

GeoIP and owner classification

Two lookups add data to the query logs:

  • GeoIP maps an address to a country. It gives each answer address of the destinations analytics its country.
  • Owner classification names the company behind a query or an address: Google, Apple, Meta, Amazon and Microsoft, and the CDNs Cloudflare, Akamai and Fastly. It gives each destination its owner, and feeds the top_owners analytics shape.

The control plane reads one country database in the MaxMind DB format (.mmdb). Production uses DB-IP IP to Country Lite. The geoip role refreshes it every week (below). The code can read any of three free databases that share the format:

Database License Attribution the license asks for
MaxMind GeoLite2 Country GeoLite2 EULA (account and license key) This product includes GeoLite2 data created by MaxMind
DB-IP IP to Country Lite CC BY 4.0 IP Geolocation by DB-IP, with a link to db-ip.com
IPinfo Lite CC BY-SA 4.0 IP address data powered by IPinfo

A lookup returns the country of the record. If the record has no country (anycast and satellite ranges), the lookup returns its registered country. The result is an upper-case ISO 3166-1 alpha-2 code. opdns never looks up addresses that cannot have a country: private, CGNAT (100.64.0.0/10), loopback, link-local, unique-local, documentation and benchmarking ranges.

opdns-cp geoip run is a long-running role that keeps the published database current. One replica is enough. The role does these steps:

  1. Fetch: once a week (--geoip-interval, 168 h), it downloads the DB-IP file of the month over HTTPS (https://download.db-ip.com/free/dbip-country-lite-{YYYY}-{MM}.mmdb.gz, --geoip-dbip-url). DB-IP publishes a new file at the start of each month. Until the new file appears, the role uses the file of the previous month. If a run fails, the role tries again after an hour (--geoip-retry-interval).
  2. Verify: the file must open as a country database and answer the probes (--geoip-probes, default 8.8.8.8=US). It must not be older than the published file. If a file fails any test, the role refuses it, and the published file stays.
  3. Publish: the role writes the database to the opdns bucket as geoip/country.mmdb (--geoip-object). It keeps the file that it replaces as geoip/country.previous.mmdb. It writes the sidecar geoip/country.json, which holds the checksum, size, source, build date and attribution. The sidecar also holds when the file was published and when it was last confirmed current. If a run finds the same file, it only updates the check time in the sidecar. On a single host, --out PATH writes a local file instead of the bucket, or in addition to it.
  4. Sync: every api and ingest replica started with OPDNS_GEOIP_OBJECT=geoip/country.mmdb reads the sidecar every OPDNS_GEOIP_SYNC_INTERVAL (10 minutes). If the checksum changed, the replica downloads the database and tests it. It writes it atomically to its local OPDNS_GEOIP_DB, and reloads. A replica that starts before any file is published runs without countries until the first sync.

The same binary has one-shot subcommands, which take the same flags:

Terminal window
opdns-cp geoip status # the published sidecar: build date, checksum, last check, pinned
opdns-cp geoip refresh # fetch, verify and publish now
opdns-cp geoip refresh --source file --source-file ./dbip-country-lite.mmdb.gz
opdns-cp geoip rollback # make the previous database current again, pinned
opdns-cp geoip refresh --force # publish over a pinned or newer database

--source file publishes a file that you got another way. For example, a DB-IP file that you downloaded by hand when the control plane cannot reach DB-IP, or a MaxMind or IPinfo database.

rollback swaps the current and the previous databases, and pins the result. A pinned database stays in place until someone runs refresh --force. Until then, the weekly run leaves it alone and fails, so the alert below fires after some time.

Metric On Meaning
opdns_cp_geoip_last_success_timestamp_seconds geoip role when a refresh last published or confirmed the current database
opdns_cp_geoip_build_timestamp_seconds geoip role build time of the published database
opdns_cp_geoip_refresh_runs_total{result} geoip role runs by published, unchanged or error
opdns_geoip_build_timestamp_seconds api, ingest build time of the database the replica has loaded
opdns_geoip_loaded_timestamp_seconds api, ingest the replica’s last load
opdns_geoip_reload_errors_total api, ingest files that failed to load (the previous one stays in use)

GeoIPStale (warn) fires when no refresh succeeded for 45 days. With a weekly schedule and monthly DB-IP files, a healthy database is never more than about 38 days old. A role that never succeeded counts as stale.

The GeoIP refresh runbook in the operator repository covers these cases: DB-IP is not reachable, the countries are wrong after a refresh (roll back), and replicas do not load a new file. How alerts are routed is on Alerting.

Section titled “Configuration of the api, ingest and link roles”

The link role uses the database to place each self-hosted node where it links from. The owner of the node sees this location on the Analytics globe (the location of the node). The link role also takes OPDNS_TRUSTED_PROXIES: the load balancers whose X-Forwarded-For gives the address of the node.

Variable (flag) Default Meaning
OPDNS_GEOIP_DB (--geoip-db) none the local .mmdb path. Empty or none for no database
OPDNS_GEOIP_OBJECT (--geoip-object) none the published key to sync into OPDNS_GEOIP_DB, usually geoip/country.mmdb. Needs the S3 settings of the role
OPDNS_GEOIP_SYNC_INTERVAL (--geoip-sync-interval) 10 minutes how often the replica reads the sidecar
OPDNS_GEOIP_ATTRIBUTION (--geoip-attribution) empty the notice in GET /v1/meta. Empty uses the published notice (or else the notice for the database type), none shows no notice, and any other value is shown as it is
  • Without OPDNS_GEOIP_OBJECT, a configured file must exist and load at start. If it does not, the role exits. With OPDNS_GEOIP_OBJECT, a missing file is permitted until the first sync.
  • In both cases, the replica reads the file every 10 minutes. It reloads the file when its size or modification time changed. You can move a new file into place without a restart. If a file fails to load, the replica keeps the previous database in use.
  • When the replica syncs, the local path must be writable. The images run as a non-root user. Use the allocation directory, an emptyDir or /tmp.

Without a database, every country is "". The API still returns the country column, and GET /v1/capabilities reports the destinations_map feature as off.

The DB-IP Lite license (CC BY 4.0) requires credit wherever its data is shown. The refresh publishes the notice with the database: IP Geolocation by DB-IP (https://db-ip.com), licensed under CC BY 4.0. The API returns the notice of the loaded database as geoip_attribution in GET /v1/meta. This is the published notice, or else the notice for the type of the database (GeoLite2, DB-IP or IPinfo above). For any other type, and without a database, it is "".

The dashboard shows the notice next to the destinations globe, with its URLs as links. While opdns serves DB-IP data, the notice must not be empty. Do not set OPDNS_GEOIP_ATTRIBUTION=none in production.

The data of the classifier is part of the opdns source. It is compiled into both the control plane and the self-hosted node. As a result, both classify the same way, with no configuration:

File Holds
domains.txt domain suffixes each company operates itself (youtube.com google, github.com microsoft, brand top-level domains such as google). The longest match wins. Curated by hand
asns.txt the autonomous systems of each owner
prefixes/<owner>.txt the address ranges of each owner, aggregated, with their sources and fetch date in the header

Where the ranges come from:

Owner Source
Google its published list (goog.json) minus the customer ranges of Google Cloud (cloud.json)
Amazon its published ip-ranges.json
Cloudflare its published IPv4 and IPv6 lists
Fastly its published public IP list
Apple, Meta, Microsoft, Akamai RIPEstat’s announced prefixes of their ASNs

A refresh script gets the ranges again. Someone runs it by hand. Tests and builds never run it. A reviewer reads its diff before it is committed. Changes to the classifier data need code-owner review. Tests pin well-known names and addresses (8.8.8.8 is Google’s). As a result, a refresh that drops one of them shows up in review.

The owner of a query is the owner of its name (from domains.txt). If the name has no owner, it is the owner of the first answer address that is in a known range. The owner of a destination is the owner of its address, by range only. opdns classifies the customers of a CDN by address. For example, a site behind Cloudflare counts as Cloudflare.

For logs stored in the cloud, ingest adds three columns to each ClickHouse row. It uses the database and the classifier data in use at that moment:

Column Holds
answer_country the country of each answer address, in the order of answer_ips ("" when unknown)
client_country the country of the client address, only when the profile logs client IP addresses. "" otherwise
owner the query’s owner, "" when none

Two hourly rollups (summary tables per hour) come from these columns:

  • Queries per owner (owners_hourly). top_owners reads it for whole-hour ranges.
  • Answer addresses per country (countries_hourly).

Like the other rollups, each one expires with the rows that it summarizes. Both are erased with the logs of the account.

The values are frozen when the row is written. A new GeoIP database or a data update changes new rows only. Rows written before these columns existed read as "". When the API answers destinations, it fills an empty country from its current database. The API does not read the owner of a destination from the row. It classifies each address when it answers, with the data that it ships with.

Self-hosted nodes have no GeoIP database. A node classifies owners itself, at query time, from the data built into its release. Its destinations rows carry an empty country. The API fills the country from its own database when the answer passes through to the dashboard (Analytics from your node). For a node older than these columns, the API adds both.

  • Client countries follow the client IP switch. With Log client IP addresses off, the edge removes the address on the PoP (the server location). Ingest never looks up a country for the client, even when a record carries an address. With the switch on, the country is stored with the address, for the same retention. No API view returns client countries today.
  • If domain logging is off, there are no answer countries and no owner. Such a record has no name and no answer addresses, so there is nothing to look up.
  • Lookups are local. The database is a file on the server, and the classifier data is compiled in. No address is sent to a third party.
  • Retention and deletion: the new columns live in rows that expire with the retention of the profile. The two rollups expire with them. Account deletion erases both, with the other log tables.