This page documents two related geo-based plugins:
geoip — map IP addresses to ISO country codes and set request metadatageosite — map domain names to categories (countries/regions or custom categories) and set request metadataBoth plugins are useful for routing and policy decisions (e.g., sending China-hosted sites to China-based upstreams) and can be used together in a pipeline.
Purpose: Determine the country of IP addresses found in DNS responses and attach a country code to the request metadata for downstream routing decisions.
Default behavior:
country).Configuration options:
metadata_key (string, optional): metadata key to set (default: country).files (sequence of strings, optional): list of files with lines of form <cidr> <country_code>.data (sequence of strings, optional): inline data strings, same format as files.Text data format (used by files / data):
# comment lines are ignored
8.8.8.0/24 US
1.0.1.0/24 CN
2001:4860::/32 US
Example configuration:
plugins:
- tag: geoip
type: geo_ip
config:
metadata_key: country
files:
- examples/geoip/geoip.txt
Implementation notes:
add_country_cidr, load_from_string, lookup, country_count, etc.ipnet::IpNet and both IPv4 and IPv6 are supported.Troubleshooting:
files.Purpose: Tag domain names with categories (commonly country codes like cn, us, or other custom categories) for routing decisions.
Default behavior:
*.qq.com will match mail.qq.com).category).Configuration options:
metadata_key (string, optional): metadata key to set (default: category).files (sequence of strings, optional): list of files with lines of form <category> <domain>.data (sequence of strings, optional): inline data strings, same format as files.Text data format (used by files / data):
# category domain
cn baidu.com
cn *.qq.com
us google.com
us *.facebook.com
Example configuration:
plugins:
- tag: geosite
type: geo_site
config:
metadata_key: site_category
files:
- examples/geosite/geosite.txt
Domain matching details:
example.com matches example.com.*.example.com and .example.com will match mail.example.com, deep.mail.example.com, and example.com itself.ads, cdn), or any grouping you need.Implementation notes:
add_domain, load_from_string, lookup, category_count, and domain_count.Troubleshooting:
A common pattern is to run both plugins and let later routing plugins decide based on metadata keys produced by them. For example, you might set up forwarding rules that select upstreams by country or site_category metadata.
Example pipeline:
[Listener]
-> [plugins: hosts]
-> [plugins: cache]
-> [plugins: geo_site] # tag domain category -> metadata `category`
-> [plugins: forward] # forward rule uses `category` or `country` metadata
-> [plugins: geoip] # tag answer IPs if needed -> metadata `country`
Note: order matters — geo_site runs early to tag by domain; geoip runs after answers are present to tag by IP.
examples/ or etc/ directory and reference them from configuration.