Docs Config Routing Rules

Routing Rules

The rules array is the core of traffic routing — rules are matched from top to bottom, and the first match determines the outbound to use, with the rest of the list skipped.

Syntax Overview

config.yaml YAML
rules:
  - DOMAIN,ad.com,REJECT
  - DOMAIN-SUFFIX,google.com,auto
  - DOMAIN-KEYWORD,google,auto
  - DOMAIN-WILDCARD,*.google.com,auto
  - DOMAIN-REGEX,^abc.*com,PROXY
  - GEOSITE,youtube,PROXY

  - IP-CIDR,127.0.0.0/8,DIRECT,no-resolve
  - IP-CIDR6,2620:0:2d0:200::7/32,auto
  - IP-ASN,13335,DIRECT
  - GEOIP,CN,DIRECT

  - DST-PORT,80,DIRECT
  - PROCESS-NAME,curl,PROXY
  - NETWORK,udp,DIRECT

  - RULE-SET,providername,proxy
  - AND,((DOMAIN,baidu.com),(NETWORK,UDP)),DIRECT
  - SUB-RULE,(NETWORK,tcp),sub-rule

  - MATCH,auto

Rules are matched from top to bottom, so rules listed earlier take priority. If a request is UDP but the matched proxy node doesn't have udp: true enabled, matching continues to the next rule instead of failing outright.

Domain-Based

TypeDescription
DOMAINMatches the exact full domain
DOMAIN-SUFFIXMatches a domain suffix — e.g. google.com matches www.google.com/mail.google.com/google.com, but not content-google.com
DOMAIN-KEYWORDMatches a keyword within the domain
DOMAIN-WILDCARDWildcard matching, supporting only * (zero or more characters) and ? (one character) — note this is a different syntax from the Clash-style wildcards used elsewhere in the config
DOMAIN-REGEXMatches the domain against a regular expression
GEOSITEMatches domain categories from the Geosite database, partly sourced from v2fly/domain-list-community

IP-Based

TypeDescription
IP-CIDR / IP-CIDR6Matches an IP address range — both behave the same, IP-CIDR6 is just an alias
IP-SUFFIXMatches an IP suffix range
IP-ASNMatches the IP's ASN (Autonomous System Number)
GEOIPMatches the IP's country code
SRC-GEOIP / SRC-IP-ASN / SRC-IP-CIDR / SRC-IP-SUFFIXThe corresponding source IP version — matches the connection's origin instead of its destination

Port / Inbound / Process / Other

TypeDescription
DST-PORT / SRC-PORTMatches a destination/source port range
IN-PORT / IN-TYPE / IN-USER / IN-NAMEMatches the inbound's port/type/username/name
REMATCH-NAMEMatches the name written by a Rematch outbound
PROCESS-PATH / PROCESS-PATH-WILDCARD / PROCESS-PATH-REGEXMatches by full process path (three formats supported: exact path / wildcard / regex)
PROCESS-NAME / PROCESS-NAME-WILDCARD / PROCESS-NAME-REGEXMatches by process name; on Android this can match the package name
UIDMatches the Linux user ID
NETWORKMatches tcp or udp
DSCPMatches a DSCP marking, tproxy UDP inbound only
RULE-SETReferences a rule provider — requires rule-providers to be configured

Logical Rules & Sub-Rules

AND / OR / NOT

Written as LOGIC_TYPE,((payload1),(payload2)),Proxy, where payload is a rule type and its content, e.g. DOMAIN,google.com. Note the parentheses — multiple conditions need to be wrapped in double parentheses.

AND,((DOMAIN,baidu.com),(NETWORK,UDP)),DIRECT
OR,((NETWORK,UDP),(DOMAIN,baidu.com)),REJECT
NOT,((DOMAIN,baidu.com)),PROXY
SUB-RULE

Matches against a set of sub-rules — see the dedicated Sub-Rules page for details.

MATCH

Matches everything unconditionally — usually placed as the last entry in the rule list as a catch-all.

Extra Parameters

no-resolveDestination IP Rules Only

When a domain starts matching against a "destination IP" rule type, mihomo first triggers a DNS lookup to check whether the resolved IP matches that rule; adding no-resolve skips this lookup. If an earlier rule already triggered a resolution, the existing result is still used for matching even with no-resolve set.

srcDestination IP Rules Only

Converts a "destination IP" match into a "source IP" match.