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.
- Match type:
DOMAINmatches an exact hostname. Useapi.example.comwithouthttps://, a port such as:443, or a path such as/v1/status. This rule type cannot route different URL paths on the same host separately. - Match value: The value must match the rule type. Domain rules take a hostname, suffix, or keyword;
IP-CIDRtakes an address and prefix length, such as192.0.2.0/24. - Outbound policy:
DIRECTconnects directly, whileREJECTblocks the connection. To route traffic through a proxy, enter the name of a policy group that exists in the active configuration, then check which proxy is currently selected in that group.Proxyis not a built-in policy available in every configuration.
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
- When the core sees
api.example.comas 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. - 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. - A direct connection to
192.0.2.42matches the single-address/32rule first. Change the address to192.0.2.43, and it falls through to the later/24reject rule. The core does not automatically prioritize/32over/24because 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
- To keep a domain on the same policy: Put domain rules first. For example, place
DOMAIN-SUFFIX,example.com,DIRECTbefore a GEOIP rule so that the same service does not use different routes just because it resolved to different IP addresses. If a connection gives the core only an IP address, a domain rule may not have a hostname to match. - To route known IP ranges: Use
IP-CIDRfor private subnets, and decide whether domain-based requests should also be checked against this rule. Useno-resolvewhen you only want to check an address that's already available. If you need DNS results to make the match, do not add it by default. - To classify traffic broadly by IP geolocation: For example, use
GEOIP,CN,DIRECT. First make sure the database is loaded, then confirm the destination address in the connection details. A content delivery network may return different addresses for the same host, so a match on one connection does not guarantee the same result for the entire domain.
Apply Rules and Check Matches on macOS
- 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.
- 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.
- 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.
- 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 whetherno-resolveprevented 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.