lazydns

GeoIP & GeoSite Plugins

This page documents two related geo-based plugins:

Both 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.


GeoIP Plugin

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:

Configuration options:

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:

Troubleshooting:


GeoSite Plugin

Purpose: Tag domain names with categories (commonly country codes like cn, us, or other custom categories) for routing decisions.

Default behavior:

Configuration options:

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:

Implementation notes:

Troubleshooting:


Using GeoIP and GeoSite Together

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.


Best Practices