Topic guides

GEOIP Rule Generator

Generate Clash or Mihomo GEOIP routing rules such as GEOIP,CN,DIRECT or custom country-based policies.

Last updated
geoip rule generatorclash geoipmihomo geoipip routing rules
On this page

When to use it

  • You need Clash or Mihomo rules such as GEOIP,CN,DIRECT.
  • You want country or region-based proxy, direct, or reject policies.
  • You maintain custom rules and need standard output quickly.

Notes

GEOIP behavior depends on the GeoIP database bundled with the client. Correct rule syntax does not guarantee identical database contents across clients.

GEOIP evaluates the destination IP

GEOIP,CN,DIRECT sends a request directly when its destination IP is classified as CN by the active geographic database. It does not mean every Chinese website, the visitor's location, a flag in a node name or the selected proxy's location. CDN answers, Anycast, DNS differences and database versions can affect classification.

This minimal teaching fragment rejects other requests so the boundary is clear. It is not a complete rule set to paste over your daily configuration:

rules:
  - GEOIP,CN,DIRECT
  - MATCH,REJECT

Generate and merge it

Open Mihomo / Clash Rule Builder, add a GEOIP rule, enter country code CN and choose built-in DIRECT. For a proxy target, select a group that actually exists in your configuration. Generate the fragment first, then review its insertion into the existing configuration. Keep the catch-all MATCH last.

The rule text does not contain the IP database. The client must be able to load the geographic data expected by its running core. Data format, source and update behavior depend on that core. When geographic data is unavailable to Nodebuf's offline rule debugger, an indeterminate condition is not a confirmed match or non-match.

Make a useful comparison

  1. Record the actual destination IP from the client's connection log. It may differ from a DNS lookup on another machine.
  2. Test with the client's current core and geographic data; inspect the matched rule and final target, not only whether a website opens.
  3. To isolate the problem, compare an explicit IP-CIDR rule for that IP in a temporary configuration. A successful comparison checks ordering or IP matching, not the accuracy of GEOIP data.
  4. Restore the real configuration and inspect the order of domain rules, direct rules and GEOIP conditions. An earlier rule may win.

Do not infer a real country from the documentation range 192.0.2.0/24; it is not a public service address for geographic testing.

no-resolve is a tradeoff

Adding no-resolve prevents a GEOIP rule from actively resolving a domain solely for that rule. If the request has no usable destination IP yet, the country condition cannot match by consulting the database. Use it when relying on an already known IP is intentional. It is not a universal speed or DNS-leak protection switch. DNS servers and whether DNS queries travel through a proxy must be reviewed together with routing.

For a collection of website domains, a domain rule or Geosite lookup may better express the intent. If one site's classification is unexpected, inspect the actual IP and database version before adding a specific domain exception. Removing every geographic rule is rarely a useful first diagnostic step.

Client reference