Rule syntax: type, match value, and outbound

To route a specific domain through a particular outbound, start with rules: at the top level of the active configuration. It’s a YAML list, with each rule on a line beginning with a hyphen. For example, in DOMAIN-SUFFIX,example.org,DIRECT, the first field selects the match type, the second specifies the domain, and the third is the outbound used when the rule matches. The examples below use clients running the mihomo core.

  • Type: DOMAIN matches an exact domain, DOMAIN-SUFFIX matches a domain suffix, and IP-CIDR matches a destination IPv4 address within a subnet.
  • Match value: For domain rules, enter the hostname only—no https://, port, or path. For https://api.example.org:443/v1, the domain field should be api.example.org.
  • Outbound: DIRECT connects directly, while REJECT blocks the connection. You can also reference a proxy or policy group already defined in the configuration; its name must match exactly. Once a rule points to a policy group, that group determines which proxy is used.

MATCH has no match value, so it takes just two fields: MATCH,DIRECT. IP rules that support no-resolve can take an additional option after the outbound. Keep the existing list indentation when editing, and don’t add a second top-level rules: key—insert the rule into the existing list.

Choosing between domain rules and IP subnets

What each rule matches: domains and destination addresses
TypeExample match valueWhat matches
DOMAINapi.example.orgMatches api.example.org, but not v2.api.example.org.
DOMAIN-SUFFIXexample.orgMatches example.org and api.example.org, but not notexample.org.
DOMAIN-KEYWORDexampleMatches by substring, so notexample.org also matches.
IP-CIDR192.0.2.0/24Includes 192.0.2.25, but not 192.0.3.25.
IP-CIDR62001:db8:1234::/48Includes 2001:db8:1234::25, but not 2001:db8:1235::25.

Use DOMAIN for a single host. Use DOMAIN-SUFFIX when APIs, static assets, and login subdomains under the same domain should use the same outbound. Suffix matching respects domain-label boundaries, so example.org covers the root domain and all its subdomains—no need to add *.. Keyword rules can catch unrelated domains, so prefer exact domains or clearly bounded suffixes whenever possible.

CIDR is the straightforward choice when you’re matching a fixed address. IPv4 /32 and IPv6 /128 each match a single address. A proxy may use different addresses for connections to the same site, while multiple sites may share an address. For site-based routing, matching the visible domain is more reliable than relying on an address from a particular DNS lookup. The addresses in this table are documentation examples, not live services.

Rule order: the first match wins

In Rule mode, the core checks rules from top to bottom. It doesn’t compare every rule and then choose the most specific match. Suppose api.example.org should connect directly, while other requests under example.org should go to a group named “Example Service.” Put the exception for the API host first, followed by the domain-wide rule.

proxy-groups:
  - name: Example Service
    type: select
    proxies:
      - DIRECT

rules:
  - DOMAIN,api.example.org,DIRECT
  - DOMAIN-SUFFIX,example.org,Example Service
  - IP-CIDR,192.0.2.0/24,DIRECT,no-resolve
  - MATCH,DIRECT
  1. api.example.org: The first rule matches, so the connection goes directly via DIRECT. The core stops there, even though the second rule would also match.
  2. static.example.org: The first rule doesn’t match, but the second does. The example group contains only DIRECT, making it easy to distinguish which group a rule selects from which outbound the group ultimately uses. In a real configuration, you can reference an existing group.
  3. Destination address is 192.0.2.25: If the connection has only this IP and no domain to match, the first two rules won’t match, so the third one does.
  4. No earlier rule matches: The final MATCH,DIRECT rule handles the connection. You can also use an existing policy group as the fallback, depending on your configuration.

no-resolve: skip DNS lookup for this IP rule

When a connection reaches the core, it may include a domain or only a destination IP. When checking an IP rule, if the connection has a domain but no destination address yet, a rule without no-resolve may trigger a DNS lookup to check whether the resulting IP falls within the subnet. With no-resolve, this rule won’t resolve the domain just to find a match; if there’s no destination IP available, the core moves on to the next rule.

One rule set, two possible outcomes

rules:
  - IP-CIDR,192.0.2.0/24,REJECT,no-resolve
  - DOMAIN-SUFFIX,example.org,DIRECT
  - MATCH,DIRECT
  • The destination is 192.0.2.25, and the core has that address: the first rule can still match, sending the connection to REJECT.
  • The destination is static.example.org, and there’s no destination IP when the first rule is checked: the first rule is skipped, and the second matches the domain.
  • If a destination IP is already available—for example, because an earlier rule triggered a lookup—a rule with no-resolve can still compare that address against its subnet.

So no-resolve is not a switch that disables Clash DNS, and it doesn’t guarantee that DNS won’t be used later when the connection is established. To prioritize a policy for a known domain, put its domain rule before any IP rule that could match first. If you want a subnet rule to check addresses resolved from a domain, don’t expect no-resolve to match when no destination IP is available.

Clash rules not working? Check the configuration and connection

  1. Make sure the traffic reaches the core. Find the request in the client’s Connections page. The system proxy only covers apps that use that proxy setting; TUN can capture traffic at the network layer, but the actual coverage still depends on routing and exclusions. If the connection isn’t listed, check how traffic is being captured before changing any rules.
  2. Check the active configuration and mode. On the Configuration or Profiles page, confirm which item is selected, then make sure the mode is Rule—not Global or Direct. A profile update may regenerate the configuration. If the client supports overrides, inspect the merged rule list rather than just the snippet in the editor.
  3. Test with a new connection. Close existing connections from the app in question before trying again, so a reused connection doesn’t look like a new result. In the connection details, check the destination domain or IP, matched rule, and outbound chain. Test a domain rule by visiting the domain—not by substituting its resolved IP. If the details show only an IP, check whether that connection source provides the domain to the core.
  4. Use the result to narrow down the cause. If you see MATCH, check the match value, whether an IP is available, and where the custom rule sits. If a broader suffix rule matches first, move the exception above it. If the expected policy group appears but traffic uses a different proxy, review the selection on the Proxies page. If the configuration fails to load, check YAML indentation, rule types, and group names in the Logs page.

Change one rule at a time, then test both a case that should match and one that shouldn’t. For example, after adding an exact exception for api.example.org, check that another domain with the same suffix still uses the original policy group. This confirms the exception works without widening its scope by mistake. For help with other fields, see the configuration reference.