Skip to content
Edit this page

Routing Rules (rules)

When mode: rule (default), ClashRS evaluates rules from top to bottom and routes each session to the target of the first matching rule. If no rule matches (for example when MATCH is omitted), traffic falls back to DIRECT.

Syntax

TYPE,PAYLOAD,TARGET[,OPTIONS...]
MATCH,TARGET[,OPTIONS...]
  • Built-in targets: DIRECT and REJECT (plus any defined proxy or proxy group name).
  • REJECT-DROP, PASS, and COMPATIBLE are not defined.
  • sub-rules and script are not supported.

Supported Rule Types (18 Types)

Rule Type Aliases Payload & Matching Semantics Triggers DNS Resolution?
DOMAIN — Exact domain match (ASCII case-insensitive; returns false for IP targets). No
DOMAIN-SUFFIX — Matches the domain itself or any .suffix subdomain (case-insensitive; google.com will not match fakegoogle.com). No
DOMAIN-KEYWORD — Case-insensitive substring match against the domain. No
DOMAIN-REGEX — Rust regex match against the domain (case-insensitive by default). No
GEOSITE — Matches a category from geosite database. Supports !code negation and code@attr attribute filtering (case-insensitive). No
GEOIP — Matches ISO 3166-1 alpha-2 country code (e.g. CN) from mmdb. No special built-in PRIVATE override—relies on MMDB data. Yes (unless no-resolve)
IP-CIDR IP-CIDR6 Matches destination IPv4 or IPv6 CIDR (both names accept IPv4 and IPv6). Yes (unless no-resolve)
SRC-IP-CIDR — Matches client source IP CIDR (sess.source.ip()). No
SRC-PORT SRC-PORT-RANGE Source port(s): single port (80), range (8000-8080 or 8000:8080), or /-separated combinations (80/443/8000-8080). No
DST-PORT DST-PORT-RANGE, PORT-RANGE Destination port(s); same syntax as SRC-PORT. No
IN-TYPE — Case-insensitive inbound type: HTTP, HTTPCONNECT/HTTP-CONNECT, SOCKS/SOCKS5, TUN, TPROXY, REDIR, TUNNEL, SHADOWSOCKS/SS, ANYTLS, HYSTERIA2/HY2, IGNORE/INNER. No
IN-USER — Exact match on authenticated inbound username (sess.inbound_user, e.g. from SS2022/AnyTLS/Hysteria2 multi-user listeners). Non-empty payload required. No
PROCESS-NAME — Exact match on local process name (Linux, macOS, Windows; always false elsewhere). No
PROCESS-PATH — Substring match against process name/path (Linux, macOS, Windows). No
NETWORK — Transport protocol: TCP/tcp or UDP/udp. No
RULE-SET — References a provider defined in rule-providers. domain: No; ipcidr/classical: Yes unless no-resolve
AND / OR / NOT — Arbitrarily nested logical combinators (see below). Yes if any leaf requires DNS
MATCH — Catch-all rule (MATCH,TARGET[,interface=<name>]). No

Unsupported Rule Types

The following rule types are not supported and fail config loading with unsupported rule type: DOMAIN-WILDCARD, IN-PORT, IN-NAME, IN-IP, PROCESS-NAME-REGEX, PROCESS-PATH-REGEX, UID, DSCP, IP-ASN, IP-SUFFIX, SRC-GEOIP, SRC-IP-ASN, SRC-IP-SUFFIX, SUB-RULE, SCRIPT, FINAL (use MATCH).

Rule Modifiers (Options)

ClashRS strictly validates options—unknown or duplicate modifiers cause a config error. Exactly 2 modifiers are supported:

  1. no-resolve
  2. Skips DNS resolution for domain targets before evaluating IP-based rules.
  3. Allowed only on GEOIP, IP-CIDR, IP-CIDR6, SRC-IP-CIDR, and RULE-SET.
  4. interface=<iface_name>
  5. Allowed on any top-level rule (including MATCH and AND/OR/NOT, but not on inner sub-expressions of logical rules).
  6. Binds the matched session's outbound socket to the named network interface (logs a warning and falls back to default if the interface is not found).

Logical Combinators (AND, OR, NOT)

Sub-rules omit the target (they may still include no-resolve, but interface= must be placed on the outermost rule):

rules:
  - AND,((NETWORK,UDP),(DST-PORT,443)),REJECT
  - OR,((DOMAIN-SUFFIX,example.com),(IP-CIDR,192.0.2.0/24,no-resolve)),PROXY
  - NOT,((GEOIP,CN,no-resolve)),PROXY
  - AND,((IN-USER,alice),(GEOSITE,cn)),DIRECT,interface=eth0
  • NOT must contain exactly 1 sub-expression.
  • If a malformed compound rule fails to construct, ClashRS logs an error and falls back to MATCH,REJECT for safety.

Example

rules:
  - IN-USER,vip-user,PROXY
  - PROCESS-NAME,curl,DIRECT
  - RULE-SET,private-domains,DIRECT
  - DOMAIN-SUFFIX,example.com,PROXY
  - DOMAIN-REGEX,^ad[0-9]+\.example\.net$,REJECT
  - GEOSITE,cn,DIRECT
  - GEOSITE,geolocation-!cn,PROXY
  - IP-CIDR,127.0.0.0/8,DIRECT,no-resolve
  - IP-CIDR,192.168.0.0/16,DIRECT,no-resolve
  - GEOIP,CN,DIRECT,no-resolve
  - AND,((NETWORK,UDP),(DST-PORT,443)),REJECT
  - MATCH,PROXY