Clash Routing Rules: Use GEOIP, GEOSITE, and RULE-SET for China Direct Routing
Using the common setup of routing mainland China traffic directly and other traffic through a proxy, this guide explains rule matching order, rule-set subscriptions, and the MATCH fallback, then shows how to troubleshoot misrouted connections.
Choose a routing strategy: domains first, IPs as a fallback
In mihomo (formerly Clash.Meta), set the operating mode to rule. Connections handled by the core are checked against rules from top to bottom, and the first matching rule determines the outbound policy. A common setup is to handle specific exceptions first, then match China domains, add a China IP rule, and send all remaining traffic to a proxy group. If MATCH appears earlier, it will catch connections that have not matched yet, and the rules below it will never be checked.
| Rule | Match target | Typical placement |
|---|---|---|
DOMAIN | Exact domain | Specific exceptions, handled first |
RULE-SET | Entries in a named rule set | Positioned according to the rule set's purpose |
GEOSITE,cn | The cn category in domain data | Domain-routing layer |
GEOIP,CN | Addresses classified as CN in IP data | After domain rules |
MATCH | Connections not matched by earlier rules | At the end of the list |
Here, “China” refers to how the rule data classifies a domain or IP address; it does not measure where a service is physically hosted. A website may use separate domains for its homepage, login API, and images, each of which can match a different rule. To check whether a policy is working, inspect the connection causing the issue rather than relying on the address bar alone.
Minimal setup: GEOSITE, GEOIP, and MATCH
This snippet is for a mihomo configuration that already has a working proxy group. It uses a group named PROXY; if your group is named “Proxy Select,” replace PROXY in the rules with that name. DIRECT is a built-in direct-connection policy, so you do not need to create a group with that name. Merge these rules into the existing top-level rules list; do not add a second key with the same name at the end of the file.
mode: rule
rules:
- DOMAIN,www.example.com,PROXY
- GEOSITE,cn,DIRECT
- GEOIP,CN,DIRECT,no-resolve
- MATCH,PROXY
DOMAINmatches onlywww.example.com, notexample.comor any other subdomain. This reserved example domain illustrates where to put an exception. Replace or remove the line to suit your needs.GEOSITE,cn,DIRECTchecks whether the destination domain known to the core belongs to thecncategory in its current domain data. It does not infer classification from the domain suffix or check the resolved IP address.GEOIP,CN,DIRECT,no-resolveclassifies an existing destination IP without actively resolving the domain for this rule. If the connection has only a domain name and no usable destination IP, this rule cannot perform an IP match, so the connection may fall through toMATCH.MATCH,PROXYsends traffic that has not matched another rule to a proxy group. The selected node depends on the group's current choice; ifDIRECTis selected, a connection matchingMATCHwill still go direct.
Add RULE-SET: validate locally before enabling remote updates
rule-providers defines how rule sets are loaded; RULE-SET determines when they are checked and which outbound policy applies on a match. This is separate from proxy-providers, which supplies proxy nodes. A full client configuration subscription is not a domain rule set. Validate rule order with a local YAML file first to rule out download issues during routing tests.
Local rule set and provider name
Save the following content as rulesets/direct-extra.yaml in the mihomo working directory. If a GUI client manages the core's working directory, check the actual path in the client rather than assuming it is next to the exported subscription file. These entries demonstrate suffix syntax only; replace them with domains you have confirmed should connect directly.
payload:
- '+.example.org'
rule-providers:
direct-extra:
type: file
behavior: domain
format: yaml
path: ./rulesets/direct-extra.yaml
rules:
- DOMAIN,www.example.com,PROXY
- RULE-SET,direct-extra,DIRECT
- GEOSITE,cn,DIRECT
- GEOIP,CN,DIRECT,no-resolve
- MATCH,PROXY
direct-extra must match the key under rule-providers. behavior: domain is for domain matching, and +.example.org covers the domain itself and its subdomains. Use ipcidr for a list of IP ranges, and classical for a list containing rules such as DOMAIN-SUFFIX,example.org. The source file's structure must match both behavior and format; the file extension alone is not enough.
Update and verify remote rule sets
To switch to a remote rule set, change the provider's type to http, enter the direct URL of the rule file provided by its publisher, and keep a separate local cache path. For example, interval: 86400 sets an update interval of 24 hours. Do not use a code repository's file preview page as the URL: it may return HTTP 200 while serving HTML instead of rule data.
On first launch, confirm that the provider loads successfully, then monitor the connections you want to test. If an update fails, check network access to the rule source, the response content, and write permissions for the cache directory. If an older cache exists, verify which data the core actually loaded. If the rules revert after refreshing a subscription, check whether the client overwrites the local configuration with the remote one. To keep rules long-term, use an override or merge configuration supported by the client, then verify the effective rule order after refreshing.
Troubleshoot misrouting: trace the connection to its matching rule
No connection record? First check that traffic reaches the core
Rule mode applies only to traffic routed through mihomo. Some apps may ignore the system proxy even when it is enabled; TUN mode uses a virtual network interface to capture traffic that meets its routing conditions, so the two are not interchangeable switches. If mixed-port: 7890 is configured and local connections are allowed, use the command below to send a test request explicitly through the HTTP proxy. If the client uses a different port, check the effective configuration. This command tests the proxy entry point for this request only; it does not confirm that other apps are being captured.
curl --proxy http://127.0.0.1:7890 --head https://www.example.com/
Connection record found? Distinguish a rule miss from an outbound failure
- Check the destination. In the client's connections panel, inspect the destination domain or IP. If the record shows only an IP, first check how the application connects.
DOMAINandGEOSITErequire domain information; they cannot match a domain just because you remember entering it in the browser. - Check the matched rule. If a service in mainland China is routed through a proxy and matches
MATCH, check whether its domain is included in the rule data and whether a usable destination IP is available withno-resolve. If an earlier proxy rule set matched, check its coverage and move confirmed direct-connection exceptions above it. - Check the outbound chain. If the expected rule matched but the connection failed, inspect the final node, proxy group selection, and connection error. Changing rule order is unlikely to fix an unreachable node or a timeout connecting to the destination.
- Retest with a new connection. After changing rules, reload the configuration, close the test app's existing connections, and try again. Browsers may reuse HTTP/2 or HTTP/3 connections, so refreshing a page does not guarantee a new connection. Change one thing at a time and record the results before and after.
With Fake-IP enabled, an app may receive a synthetic address from a configured range such as 198.18.0.0/16. The address lets the core associate the connection with a domain; it does not indicate the destination server's location. If domain rules behave unexpectedly in TUN mode, check whether the app's DNS queries follow the expected resolution path and whether the core can still identify the corresponding domain before changing DNS or sniffing settings. Do not add the entire Fake-IP pool to the China direct-routing list as a workaround.
Before rollout: retest and verify each layer
Prepare at least four test cases: a custom exception domain, a domain included in GEOSITE,cn, an accessible IP classified as CN by the current IP data, and a domain expected to match MATCH. To test IP rules, use a service that supports access by IP; otherwise, an HTTPS certificate name mismatch may look like a routing failure.
For each test, record the destination, matched rule, and final outbound instead of simply noting whether it “works.” Reuse the same test cases after changing the proxy group, updating rule sets, or adjusting DNS. When results change, determine whether the rule data, destination IP, or proxy group selection changed before editing the corresponding section. If you need to roll back, restore the last verified rules and data rather than temporarily switching to global mode, which makes it easier to preserve diagnostic clues.