Check the rule mode and proxy group first

Clash matches rules against a connection's destination domain or IP address. In Rule mode, the core checks rules from top to bottom. The first matching rule determines how the connection is routed. DIRECT is the built-in direct connection option; this guide uses International Proxy to refer to an existing proxy group with an available node selected. Direct connection here means the core handles the connection and sends it out directly—not that the connection bypasses the core.

  • Check the core: The examples use the configuration syntax for Clash Meta (now called mihomo). A client with “Clash” in its name may use a different core, so check the core name and version shown in the client first.
  • Check the mode: Switch the client to “Rule” mode. The corresponding YAML setting is mode: rule, but changing the mode in the interface may override the value in the configuration file. Check the active mode. Global and Direct modes do not classify connections against the rules in this guide.
  • Check the group name: Open proxy-groups in the active configuration, find the existing proxy group, and check which outbound is selected. Replace International Proxy in the example with the group's exact name. Don't leave a group name that doesn't exist in the configuration, and don't select DIRECT within the group.

Copy the current working configuration before editing its rules. A subscription is the source of the configuration, and automatic updates may overwrite changes made directly to a subscription file. For long-term use, consider the client's configuration override feature. Check whether it replaces the entire rules section or appends rules to the existing list.

Rule order: domains first, IPs next, catch-all last

With this routing policy, known domains for services in mainland China go direct first. Connections not covered by a domain rule are then checked against the destination IP's mainland China geolocation. Everything else goes to the proxy group. This is a maintainable default, not a precise classification by service operator or user location. A service's main site and image assets, for example, may use different domains, so each connection must be assessed separately.

Rule order and what each type does
Order Rule What it matches
1 DOMAIN-SUFFIX Matches the specified domain and its subdomains. Best for a small number of services that need a specific outbound.
2 RULE-SET References a separately maintained rule set. This example checks the direct-connection domain set before checking IP geolocation.
3 GEOIP Classifies by the database's location for the destination IP. It does not identify a site's language, company registration location, or domain suffix.
4 MATCH Catches every connection not matched by the rules above. If placed earlier, it prevents all later rules from matching.

For example, DOMAIN-SUFFIX,baidu.com,DIRECT matches both baidu.com and www.baidu.com, but not notbaidu.com. To route only www.baidu.com through a different outbound, use an exact DOMAIN match and place it before this suffix rule.

Configure mihomo rules and a local rule set

Merge rules into your existing configuration

The following is a snippet to merge, not a complete configuration. Keep your existing proxies, proxy-groups, and inbound settings. If rule-providers already exists, add mainland-direct to the existing mapping. If rules already exists, reorder its current entries instead of declaring a second top-level key with the same name. If the original configuration has exceptions for LAN traffic or specific apps, decide which ones to keep and place them before any general rules that would override them.

mode: rule

rule-providers:
  mainland-direct:
    type: file
    behavior: classical
    format: yaml
    path: ./rules/mainland-direct.yaml

rules:
  - DOMAIN-SUFFIX,baidu.com,DIRECT
  - RULE-SET,mainland-direct,DIRECT
  - GEOIP,CN,DIRECT,no-resolve
  - MATCH,International Proxy

Create the rule set file

Create rules/mainland-direct.yaml in the core's working directory. Relative paths are usually resolved from mihomo's main directory, which may differ from the directory containing the subscription file. A graphical client may place the core's working directory under its app data directory. If you can't find the file, check the startup logs or the client's configuration directory shortcut to confirm its location.

payload:
  - DOMAIN-SUFFIX,qq.com
  - DOMAIN-SUFFIX,bilibili.com

behavior: classical means each entry in the file includes a rule type. Don't specify DIRECT here; the main configuration's RULE-SET,mainland-direct,DIRECT sets the outbound for the whole rule set. These two domains are just a starting point for checking that the rule set loads; they don't cover all traffic for the apps in question. If a video or login feature uses a different domain, check the connection log first, then add the relevant domain rule.

Check whether GEOIP should resolve domains

GEOIP,CN,DIRECT,no-resolve tells mihomo not to initiate a DNS lookup for this IP rule. If the connection already has a destination IP that can be matched, mihomo can still check its geolocation. If the connection has only a domain and no earlier domain rule matches, processing continues down the list and may eventually reach MATCH. This does not disable DNS across the client or guarantee that all mainland China domains connect directly.

If you explicitly want to use the resolved destination IP's geolocation as an additional way to route traffic directly, change the rule to GEOIP,CN,DIRECT and verify the results in the connection log. Requests not caught by a domain rule may then trigger DNS lookups during the GeoIP check. The same domain can resolve to different CDN addresses on different networks, so for services where the outbound matters, use a domain rule placed before GeoIP to pin the route.

Verify the actual outbound with three new connections

Reload the configuration and confirm it activates successfully, then open the client's “Connections” view. To test in a browser, close any existing page and make a new request; an existing connection may keep using its previously selected outbound. You can also use the command below to send a request explicitly through the local core. The example uses the HTTP proxy on the local mixed port 7890; use the port configured in your client. In Windows PowerShell, use curl.exe. If your environment has a proxy exclusion list, make sure it doesn't exclude the test domain.

curl --proxy http://127.0.0.1:7890 -I https://www.baidu.com/
curl --proxy http://127.0.0.1:7890 -I https://www.bilibili.com/
curl --proxy http://127.0.0.1:7890 -I https://example.com/
  1. First, check the suffix rule. With only the rules above, www.baidu.com should match DOMAIN-SUFFIX and use DIRECT.
  2. Next, check the rule set. www.bilibili.com should match RULE-SET through mainland-direct. If it still connects directly but the reason shows GeoIP, check that the rule set loaded and that no other rule was inserted earlier in the list.
  3. Finally, check the catch-all. If no other retained rule matches example.com and GeoIP does not classify it as CN, it should use MATCH → International Proxy. Check not only the group name but also that the actual outbound is a node in that group.

Use the matched rule and outbound shown in the client—not whether a webpage loads—as your evidence. If the expected rule matches but the request times out, check the outbound's connectivity. If no connection appears in the log, first check the port, proxy exclusions, or how the app's traffic is being captured. To test GeoIP on its own, connect to a known-reachable IPv4 address classified as CN in the current database and check the matched rule. Don't use an HTTPS certificate error when connecting to an IP address to judge whether routing works.

If direct routing doesn't work as expected, check the connection before changing rules

The site loads, but some resources use the proxy

Images, video, and login requests on a webpage may use different domains. Find the specific request that matched the catch-all in the connection log, then decide whether it should go direct. For an exception affecting a single host, use DOMAIN where possible. Don't route an entire shared CDN suffix directly just because one resource loads slowly.

Results differ with TUN enabled and a manually configured proxy

TUN captures traffic routed through its virtual network interface, but enabling TUN does not change the rules themselves. The destination information available to the core may differ, though. With a manually configured HTTP proxy, the client usually passes the destination domain directly to the core. TUN captures network packets instead. If an app's DNS requests pass through mihomo and it uses fake-ip, the core can recover the domain using its mapping. If the core sees only the real destination IP and cannot recover the domain, check the destination address and GeoIP match first instead of repeatedly rewriting domain rules.

All connections suddenly use the same outbound after a subscription update

First check that the mode is still “Rule.” Then check whether the active configuration still contains the local rule set, whether the proxy group name has changed, and whether another MATCH rule was merged higher in the list. Check each item in this order: “mode → active configuration → matched rule → actual outbound.” This helps distinguish an inactive configuration from an active configuration producing a different match. Once fixed, retest one suffix rule, one rule set, and the catch-all; don't test just one site you use regularly.