Skip to content

Rule conditions ​

Everything that can be written in match of route rules. How conditions combine and how logic is written is in Rules. Almost all conditions take one value or a list; a list means "any of".

Connection ​

ConditionMatches if
inboundThe connection came to one of these inbounds (by name)
networkThe network: tcp or udp; any other value is an error
ip_versionThe IP version of the destination: 4 or 6
auth_userThe user name the client logged in to the inbound with (the protocol's users)
protocolThe protocol found by sniffing: tls, http, quic, dns, stun, bittorrent, dtls, ssh, rdp, ntp; any other value is an error
clientThe client found by sniffing (by its TLS or QUIC fingerprint)

protocol, client and the domain conditions from sniffing work only after do: sniff, see Actions.

Destination ​

ConditionMatches if
domainThe destination domain equals one of the values
domain_suffixThe domain ends with one of the values: example.org matches example.org and a.example.org
domain_keywordThe domain contains a substring
domain_regexThe domain matches a regular expression
ip_cidrThe destination IP is in one of the subnets: 10.0.0.0/8, 2001:db8::/32, 1.2.3.4
ip_is_privatetrue: the destination IP is private (RFC 1918, loopback, link-local and the like)
portThe destination port: 443 or [80, 443]
port_rangeA port range: "1000:2000", ":1024", "8000:"

The destination domain is known if the client sent a domain itself, if the address was taken from the fakeip pool, if sniffing found the domain, or if dns.reverse_mapping is on and the address came from an answer of the built-in DNS. For a connection to a bare IP without any of these, domain conditions are false.

The destination IP is known if the client sent an IP, or after the action do: resolve.

Source ​

ConditionMatches if
source_ip_cidrThe source IP is in one of the subnets
source_ip_is_privatetrue: the source IP is private
source_port, source_port_rangeThe source port, like port and port_range
source_mac_addressThe source MAC address: aa:bb:cc:dd:ee:ff
source_hostnameThe source host name from a DHCP lease

source_mac_address and source_hostname come from the neighbor table and DHCP lease files (route.dhcp_lease_files); they work for clients on the same network.

Local process ​

For connections opened by programs on the same machine (Linux):

ConditionMatches if
process_nameThe name of the process's executable
process_pathThe full path to the executable
process_path_regexThe path matches a regular expression
userThe name of the user the process runs as
user_idThe UID of the process

Host ​

ConditionMatches if
network_typeThe type of the current default network: wifi, cellular, ethernet, other

Rule-sets ​

ConditionMatches if
rule_setAt least one rule of one of the named rule-sets matched
rule_set_ip_cidr_match_sourcetrue: the ip_cidr conditions inside the rule-sets check the source IP, not the destination
geoip, geositeA shorthand: geoip: ru is rule_set: geoip-ru, geosite: google is rule_set: geosite-google; source_geoip has no such shorthand and is an error

There are no built-in GeoIP and GeoSite databases: a rule-set with the corresponding name has to be declared in rule_sets, from an .srs or from a code of a V2Ray/Xray geosite.dat/geoip.dat database (the dat format). A missing rule-set is a load error:

yaml
rule_sets:
  geosite-google:
    remote: https://example.org/geosite-google.srs

route:
  rules:
    - match:
        geosite: google
      to:
        outbound: proxy
  final:
    outbound: direct

Not supported ​

These sing-box conditions are known, but a configuration with them does not load: check and run end with an error giving the reason:

ConditionWhy
wifi_ssid, wifi_bssidWi-Fi state is available only on Android, Apple and Windows
network_is_expensive, network_is_constrainedThe system does not report metered networks
package_name, package_name_regexAndroid only
clash_modeThere is no Clash API
interface_address, network_interface_address, default_interface_addressNot supported
preferred_byNot supported

The fields invert, type, mode, rules are an error: logic is written with the any, all, not nodes.

GPL-3.0-or-later