rules fields and match order

In rule mode, the core checks connections against the active configuration’s rules list from top to bottom. Once a rule matches, its specified outbound policy is used, and the remaining rules are skipped. The core does not automatically put exact domain matches ahead of suffix matches, nor does a rule set receive higher priority just because a rule uses one. Position in the list determines priority.

Most rules follow the format “type, match value, policy”; some IP-based rules also accept an optional parameter at the end. MATCH has no match value, so it uses the format “type, policy.” The hyphen at the start of each line below is a YAML list marker. A quoted line is a single string, and the commas separate the fields read by the core.

Rule types, fields, and match targets
TypeExampleMatch target
DOMAINDOMAIN,api.example.com,DIRECTExact domain
DOMAIN-SUFFIXDOMAIN-SUFFIX,example.com,REJECTSpecified domain and its subdomains
GEOIPGEOIP,CN,DIRECT,no-resolveGeographic classification of the destination IP
RULE-SETRULE-SET,local-services,DIRECTAn entry in the local-services rule set
MATCHMATCH,DIRECTAll connections that reach this rule

DIRECT means connect directly; REJECT means block. When using a custom policy group, the third field must match a name in proxy-groups, including capitalization and spaces. Rules select a policy; the policy group then determines the actual outbound route. If the logs show the expected rule matched but traffic still goes direct, check whether the group is currently set to DIRECT.

DOMAIN-SUFFIX: put exact exceptions before suffix rules

DOMAIN-SUFFIX,example.com matches example.com, www.example.com, and deeper subdomains, but not notexample.com or example.com.other.test. Enter only the domain—do not include https://, a *. wildcard prefix, a port, or a path. To make an exception for a single host, use DOMAIN and place it before broader rules.

mode: rule
rules:
  - 'DOMAIN,api.example.com,DIRECT'
  - 'DOMAIN-SUFFIX,example.com,REJECT'
  - 'MATCH,DIRECT'
  • api.example.com matches rule 1 and goes direct. Although it also matches rule 2, the core does not check it.
  • www.example.com skips rule 1, matches rule 2, and the connection is rejected.
  • example.net matches neither of the first two rules, so it matches rule 3 and goes direct.

If you swap the first two rules, api.example.com matches the suffix rule first. This example uses documentation-only domains. For testing, use a domain you control or one intended for testing, then check the destination host in the connection logs. If an app connects directly to an IP and the core cannot obtain the associated domain from connection metadata, a suffix rule will not match. A webpage may also connect to multiple hosts; a match for the main site does not mean its static assets and API calls will use the same policy.

GEOIP: distinguish the destination domain from its IP

GEOIP,CN,DIRECT checks whether the destination IP is classified as CN in the current GeoIP database. It does not check whether the domain ends in .cn or use the device’s location. A domain may resolve to different addresses through a CDN; the database version, DNS response, and address used for the actual connection can all affect the match. To apply a consistent policy to a specific service, put an explicit domain rule before the GeoIP rule.

no-resolve controls whether this rule triggers DNS resolution

In mihomo, GEOIP,CN,DIRECT,no-resolve means the rule will not actively resolve the destination domain to determine its geographic classification. If the core already has a usable destination IP, it can still match against that address. If only a domain is available and no usable destination IP exists, the core continues to the next rule. This does not disable DNS for the entire configuration: earlier rules may already have triggered resolution, and later rules or the outbound connection may still need it.

When troubleshooting, first open a new connection using a domain, then open a separate connection to an IP you are allowed to test. Check the destination and matched rule in each log entry; do not treat the two results as one request. For a policy covering a fixed network range, IP-CIDR or IP-CIDR6 is more explicit than a country or region classification. Test IPv4 and IPv6 separately for dual-stack services; an IPv4-only range rule will not cover IPv6 connections.

RULE-SET: define a rule set and reference it in the rules list

Add a rule set in two steps: define its source under the top-level rule-providers, then reference its declared name with RULE-SET under the top-level rules. Defining a provider does not enable it: even if the rule set has loaded, it will not be evaluated unless the rules list references it. Here is a local YAML example for mihomo. For other cores or forks, first check that they support the same rule-set fields.

Main config: define local-services and set its match position
mode: rule

rule-providers:
  local-services:
    type: file
    behavior: classical
    format: yaml
    path: ./rules/local-services.yaml

rules:
  - 'DOMAIN,api.example.com,DIRECT'
  - 'RULE-SET,local-services,REJECT'
  - 'GEOIP,CN,DIRECT,no-resolve'
  - 'MATCH,DIRECT'
Rule set file: rules/local-services.yaml
payload:
  - 'DOMAIN-SUFFIX,example.com'
  - 'DOMAIN,old-api.example.net'

behavior: classical is for typed match entries such as DOMAIN or DOMAIN-SUFFIX. These entries do not include an outbound policy; a match uses the REJECT policy in the main configuration’s reference rule. With behavior: domain or behavior: ipcidr, entries must use the corresponding domain or network-range format. Changing only behavior while keeping the classical entries above will not work.

For a rule set hosted remotely, mihomo’s type: http should be paired with url. For example, interval: 86400 is in seconds, so it updates every 24 hours. Updating a rule set and refreshing the full subscription configuration are separate steps. After an update, check which entries actually loaded, then make sure the reference rule comes before any rule that could match first.

MATCH fallback and troubleshooting missed matches

A typical order is to start with single-host exceptions, followed by broader domain rules or rule sets, then IP-based rules for the remaining traffic, and finally MATCH. This is not a fixed order by rule type: if an IP range should take precedence over a domain policy, put the IP rule first and confirm the destination IP is available when that rule is evaluated. Place MATCH last; once it matches a connection, no later rules can run.

Verify each case with a new connection

  1. Check the active configuration and mode. Make sure the client is using the configuration you edited and is in rule mode. Do not expect rules to behave as shown in global or direct mode. If you use a subscription, recheck the active rules after refreshing it so a subscription update that overwrote your local changes is not mistaken for a rule failure.
  2. Check the configuration load result. Keep only one top-level rules key and one rule-providers key, and merge new entries into the existing list or mapping. If loading fails, first check indentation, rule names, policy group names, and rule-set paths, then verify the entry format.
  3. Test four kinds of targets. Choose an exact-match exception, a host that matches a suffix rule or rule set, an address suitable for testing an IP rule, and a target that clearly does not meet the earlier conditions. For each, record the destination, matched rule, and actual outbound route. To verify the fallback, check that the logs show MATCH; a GeoIP rule and the fallback may both happen to use DIRECT.
  4. Confirm the traffic reaches the core. Retest with a new connection to avoid reusing an existing one. If the connection list shows no matching traffic, first check whether the app is included in the client’s VPN routing. In a system-proxy setup, also confirm the app respects that proxy setting. Changing rule order cannot affect connections that never reach the core.

When two rules could both match, choose a test target that distinguishes their outcomes, then change one rule at a time. This helps separate rule-order issues from DNS resolution issues. See Policy Groups in the Configuration Reference for policy group fields, and TUN Mode for traffic routing.