Advanced About 7 min read

Clash Rules Guide: DOMAIN-SUFFIX, IP-CIDR, and Rule Order

Learn how Clash rules are structured, compare DOMAIN, DOMAIN-SUFFIX, DOMAIN-KEYWORD, IP-CIDR, GEOIP, and MATCH, and understand first-match-wins behavior and rule ordering.

The Three Parts of a Clash Rule

Take DOMAIN,api.example.com,DIRECT as an example. Its three comma-separated fields are the match type, match value, and outbound policy. Rules go in the top-level YAML rules: list, with one rule per list item. In Clash Verge Rev, the client manages the configuration, while mihomo (formerly Clash.Meta) handles traffic. The core routes each connection according to this list only when the client is set to Rule mode.

Three fields are common, but the field count is not fixed. MATCH,DIRECT needs no match value, while IP-CIDR,192.0.2.0/24,REJECT,no-resolve adds an optional parameter after the outbound policy. When editing an existing configuration, update its current rules: list instead of adding a second top-level key with the same name.

What Each of the Six Rule Types Matches

Type Example value What it matches and when to use it
DOMAIN api.example.com Matches only this hostname, not example.com or v2.api.example.com. Useful for exceptions on a single host.
DOMAIN-SUFFIX example.com Matches example.com and cdn.example.com, but not notexample.com. No need to add *..
DOMAIN-KEYWORD example Matches hosts containing this string, so it may also match notexample.com. Use it only when you need substring matching across different domains.
IP-CIDR 192.0.2.0/24 Matches a destination IPv4 address within the specified subnet. This prefix covers 192.0.2.0 through 192.0.2.255; to match only 192.0.2.42, use 192.0.2.42/32.
GEOIP CN Matches the destination address using the geolocation IP data loaded by the core. The result depends on that database; it does not check whether a domain ends in .cn.
MATCH None Matches every connection that reaches this line, making it a catch-all. If placed earlier, it prevents any rules below it from being checked.

To match example.com and its subdomains, use DOMAIN-SUFFIX rather than the broader DOMAIN-KEYWORD,example. If the issue occurs only over IPv6, first check the address type in the connection details. In mihomo, a rule such as IP-CIDR6,2001:db8::/32,DIRECT,no-resolve matches an IPv6 prefix, rather than an IPv4 subnet.

Rule Order: The First Match Determines the Route

Rules are checked from top to bottom in the order they appear in the active configuration. They are not automatically reordered by specificity. This example shows one possible order: a single-host exception first, followed by domain suffix and subnet rules, with a catch-all at the end. The example domains and addresses are for illustration only; do not use their connectivity to validate your local configuration.

rules:
  - DOMAIN,api.example.com,DIRECT
  - DOMAIN-SUFFIX,example.com,REJECT
  - IP-CIDR,192.0.2.42/32,DIRECT,no-resolve
  - IP-CIDR,192.0.2.0/24,REJECT,no-resolve
  - MATCH,DIRECT
  1. When the core sees api.example.com as the destination hostname, the first rule matches and routes it directly. The host also matches the second rule, but that rule is never reached. Move the second rule above the first, and the connection will instead be rejected.
  2. For a destination of cdn.example.com, the first rule does not match, so the second rule matches and rejects the connection. Even if the destination address also matches the subnet rule below, that decision is not overridden.
  3. A direct connection to 192.0.2.42 matches the single-address /32 rule first. Change the address to 192.0.2.43, and it falls through to the later /24 reject rule. The core does not automatically prioritize /32 over /24 because it is more specific.

How IP-CIDR, GEOIP, and no-resolve Work Together

If the core knows the destination hostname but has no usable destination IP, checking a destination-IP rule may trigger DNS resolution. Adding no-resolve to a rule that supports it prevents that rule from initiating a lookup just to obtain an address; it does not disable DNS globally. The rule can still match connections made directly to an IP, and it may also use an address already obtained earlier in processing.

Choose Between Routing by Domain and Routing by IP

Apply Rules and Check Matches on macOS

  1. Make sure you're editing the active configuration. Check the enabled configuration on the Subscriptions page in Clash Verge Rev. Edits made directly to a downloaded remote subscription may be overwritten the next time it updates. To keep your changes, use the rule extension features available in your current version, or import a local copy while keeping the original. After saving, reapply the configuration and check where your custom rules appear in the active rule list—not just in the editor.
  2. Make sure test traffic reaches the core. On the Proxies page, select Rule mode, not Global or Direct. If you use the system proxy, go to macOS System Settings → Network → your current network service → Details → Proxies and check the relevant setting. The app must also be configured to use the system proxy. TUN mode changes how traffic enters the core, not the order of the rules.
  3. Test with a new connection. On the client's Connections page, check the destination host, destination address, and matched rule, then verify the outbound policy or proxy chain. If possible, quit and reopen the test app to avoid reusing a connection opened before the rules changed. If the request does not appear on the Connections page, check how traffic is routed into the core before rearranging rules.
  4. Narrow down the issue based on the result. If an earlier broad rule matches, move the exception above it. If the connection falls through to MATCH, check for a typo in the destination hostname, whether the core received only an IP address, or whether no-resolve prevented the rule from matching when no address was available. If the expected rule matches but traffic still takes the wrong route, check the policy group's current selection instead of changing the match conditions.

When troubleshooting, change one condition at a time and note the rule name and outbound policy before and after each change. This helps distinguish three issues: the rule was not loaded, it was loaded but did not match, or it matched but the policy group selected a different route.

Download Clash