Clash Rules Guide: DOMAIN-SUFFIX, GEOIP, and Direct vs. Proxy Routing
Learn how to route mainland China traffic directly and other traffic through a proxy with Clash rules. Covers rule order, rule-providers, and the MATCH fallback.
Basic rules: direct routing for mainland China, proxy for everything else
Start by making a copy of your working configuration, and edit the copy. This example uses Clash Meta (mihomo): explicit domain exceptions take priority, connections to IP addresses classified as belonging to mainland China go direct, and everything else goes to a proxy group. Routing is based on the rules—not the page language, domain registration location, or where a website is based. After switching to the copy, set the mode to Rule. Global and Direct modes do not route traffic through this rule list.
rules:
- DOMAIN,www.example.com,PROXY
- DOMAIN-SUFFIX,example.com,DIRECT
- DOMAIN-SUFFIX,qq.com,DIRECT
- IP-CIDR,192.168.0.0/16,DIRECT,no-resolve
- GEOIP,CN,DIRECT
- MATCH,PROXY
The example.com entries show how rule order works; they do not classify traffic by location. To send commonly used services in mainland China direct, keep only the domain entries you actually need and remove the two demonstration rules. 192.168.0.0/16 covers only that IPv4 range. To route traffic to a home printer or router directly, first check the device's actual subnet.
Rule order: specific domains first, MATCH last
Rules are checked from top to bottom. The first match selects its assigned policy; Clash does not continue looking for a more specific rule. In the example above, the first DOMAIN rule sends www.example.com to PROXY. Move the suffix rule above it, and www.example.com will match DIRECT first.
| Rule type | What it matches | Example result |
|---|---|---|
DOMAIN | Exact domain | www.example.com goes through the proxy; other subdomains are not included. |
DOMAIN-SUFFIX | The specified domain and all its subdomains | qq.com and mail.qq.com go direct; notqq.com does not match this rule. |
IP-CIDR | The subnet containing the destination IPv4 address | A direct connection to 192.168.1.1 matches the LAN rule in this example. |
GEOIP | Look up the destination IP's location in the database | If no earlier rule matches and the database classifies the destination IP as CN, the connection goes direct. |
MATCH | Connections that did not match an earlier rule | Sent to the PROXY group. |
For a suffix rule, enter only the domain—no https://, path, or *.. To make a specific subdomain an exception, put DOMAIN before the corresponding suffix rule. Pay particular attention to the existing MATCH rule in your subscription: any new rules added below it will never be checked.
GEOIP and DNS: rules match the destination IP
GEOIP,CN,DIRECT checks the destination IP, not the domain suffix. A service based in mainland China may use an overseas CDN, while a service based elsewhere may return an edge server IP in mainland China. The destination IP for the same domain can also vary by network or DNS response. If a domain should always use a particular policy, add a domain rule before GEOIP.
Should you add no-resolve to IP rules?
- For LAN address exceptions: Adding
no-resolveto the example'sIP-CIDRrule prevents DNS lookups solely for checking that rule. Connections made directly to an IP can still match. - For the mainland China IP fallback: The example deliberately omits
no-resolvefromGEOIP. If earlier domain rules do not match and the destination is still a domain, the core can resolve it before checking its location. If you add this option here and no destination IP is available during matching, the connection may fall through toMATCH.
no-resolve only controls whether that rule triggers a DNS lookup. It does not disable DNS in the core or prevent a rule from using an already available destination IP. With fake-ip enabled, the synthetic address shown to an app is not the server's real address. Do not use the synthetic address returned by the client's DNS query to determine geographic location; check the domain and matched rule in the connection details instead.
Manage larger lists with rule-providers
If you need to maintain dozens of domains that should go direct, keep them in a separate file. Add a top-level rule-providers key, then use RULE-SET as the match type in your rules list. This example uses a local YAML ruleset with mihomo. Place the file at ruleset/extra-direct.yaml in the core's working directory. If you use a desktop client, check which working directory it passes to the core—do not assume it is the same as the subscription file's location.
Ruleset file: list match conditions only
payload:
- DOMAIN-SUFFIX,example.net
- DOMAIN,static.example.org
Main config: load the file and set its policy
rule-providers:
extra-direct:
type: file
behavior: classical
format: yaml
path: ./ruleset/extra-direct.yaml
rules:
- DOMAIN,www.example.com,PROXY
- DOMAIN-SUFFIX,example.com,DIRECT
- DOMAIN-SUFFIX,qq.com,DIRECT
- RULE-SET,extra-direct,DIRECT
- IP-CIDR,192.168.0.0/16,DIRECT,no-resolve
- GEOIP,CN,DIRECT
- MATCH,PROXY
In this classical ruleset, each line contains a rule type and match value, with no DIRECT at the end. The action is set by RULE-SET,extra-direct,DIRECT in the main config. If rule-providers: already exists, add extra-direct under that key and make sure its name exactly matches the one used in RULE-SET. Put this rule before GEOIP so domains in the list are not routed by the IP location rule first.
To use a remote ruleset, first check the source file's actual behavior and format, then switch to type: http and set the url, local cache path, and update interval interval in seconds (for example, 86400 is one day). If an update fails, check the logs to see whether the file could not be fetched or was fetched but could not be parsed. Neither issue is fixed by changing MATCH.
Test routing: check the matched rule and actual egress
After saving the config, reload the copy and start a new connection. Existing connections may keep their previous route, so refreshing an open page does not necessarily create a new connection. You can explicitly set the local HTTP proxy in a command to rule out whether the browser is using the system proxy. The example assumes the mixed port is 7890; replace it with the port in your config if different.
curl --noproxy "" --proxy http://127.0.0.1:7890 \
--head --max-time 15 https://www.example.com/
The --noproxy "" option prevents environment variables from adding a bypass list that could interfere with the test. The command only starts a connection; its HTTP status code does not prove that routing worked correctly. Find the domain in the client's Connections page or logs, and check the matched rule and policy chain. If the connection ends too quickly to inspect, check the logs first.
- Test a domain exception: Use the command above to visit
www.example.com. It should match the exact-domain rule and go to the proxy group. Then change the URL tohttps://example.com/; it should match the suffix rule and go direct. - Test a destination not in your lists: Choose a destination that is not covered by any domain ruleset. Find one connection that matches
GEOIPand another that falls through toMATCH. If the results differ from what you expect, check the actual destination IP, its database classification, and the earlier rules. Do not infer the route from the website's name alone. - Check the actual egress: If the rule column shows
MATCHbut the policy chain showsDIRECT, check whether Direct is selected in the proxy group.MATCH,PROXYsends the connection to the group; it does not select a proxy node for you.
Rules not working? Check traffic capture, matching, and config
- No destination in the connection list: First confirm that the test app is actually sending traffic through the core. System proxy settings only work with apps that respect them; some apps make connections directly. If specifying the port explicitly works but the original app does not, check the traffic capture method first, then review the TUN routing and DNS settings.
- Connection appears, but the domain rule does not match: Check whether the connection details include a domain. If the app gives the core only a destination IP, a suffix rule cannot infer the expected domain from that IP. A page's images, APIs, and login flow may also use different hosts. Troubleshoot the actual host used by the failed request, not just the domain in the address bar.
- New rules are missing after reload: Check that the edited copy is the one currently enabled, then review the load logs for YAML indentation, policy group names, and ruleset paths. For a command-line deployment, test the config with
mihomo -t -d "$HOME/.config/mihomo" -f "$HOME/.config/mihomo/config.yaml". Replace both paths with the locations used by your service. - Changes disappear after updating the subscription: A subscription refresh may replace the config contents. Keep a local copy, or maintain your entries using the client's supported override feature, and make sure they are inserted before the existing
MATCHrule. After updating, start another new connection and verify the active rule order.