Skip to content

route — routing ​

The section decides where each connection accepted by an inbound goes: to which outbound or group, whether to refuse it, or whether to hand it to the built-in DNS.

yaml
groups:
  main:
    members: [proxy-de, direct]

rule_sets:
  ads:
    remote: https://example.org/ads.srs

route:
  rules:
    - do: sniff
    - match:
        protocol: dns
      to: hijack-dns
    - match:
        rule_set: ads
      to: block
    - match:
        domain_suffix: [lan, local]
      to:
        outbound: direct
  final:
    group: main

Order of processing: the rules are checked from top to bottom; a rule with do performs an intermediate action and the check goes on, a rule with to ends the route. If no to matched, final applies.

  • Rules — how a rule is built: match, do, to, the logic any, all, not.
  • Conditions — everything that can be written in match.
  • Actions — to and do: outbounds, refusal, sniffing, resolving, connection parameters.
  • Rule-sets — sets of conditions that rule_set refers to.

final ​

A required field: what to do with a connection that no rule ended. It takes the same values as a rule's to:

finalMeaning
outbound: <name>To an outbound
group: <name>To a group
blockRefuse
block: dropRefuse silently
hijack-dnsAnswer with the built-in DNS
bypassPast the proxy; what reaches the process goes directly

The outbound or group from final is also the default outbound: everything that connects without a route goes through it, for example downloading rule-sets without via. final: block refuses such connections too. For final: bypass the loader adds a plain direct outbound named bypass (bypass-1, … if the name is taken) and makes it the default outbound. The other values work as a last rule without conditions; the default outbound is then the first outbound in outbounds.

Other fields ​

FieldMeaning
find_processDetermine the owning process of every connection, even if no rule needs it (visible in the dashboard). The process_*, user, user_id conditions look up the process without this flag too
find_neighborThe same for the source's MAC address and host name (the neighbor table and DHCP leases), which the source_mac_address and source_hostname conditions need
dhcp_lease_filesDHCP lease files for find_neighbor and for the local upstream with neighbor_domain; by default /tmp/dhcp.leases, /var/lib/dhcp/dhcpd.leases, /var/lib/dhcpd/dhcpd.leases, /var/lib/kea/kea-leases4.csv, /var/lib/kea/kea-leases6.csv (those that exist)
auto_detect_interfaceWatch the default interface and bind outgoing sockets to it
tcp_half_close_timeoutA duration, 60s by default. When one side of a TCP connection has finished sending (FIN), the other direction keeps being forwarded, but the connection is closed if nothing goes over it for longer than this. Long silent answers to a half-closed request (ssh host cmd < /dev/null) need a larger value, for example 1h
dialDefault socket parameters, see below
default_http_clientThe name of a client from http_clients through which rule-sets without a client of their own are downloaded
override_android_vpnAccepted for compatibility; has no effect on Linux, check warns
yaml
route:
  final:
    outbound: direct
  auto_detect_interface: true
  dial:
    fwmark: 0xff
  find_process: true

dial ​

How all sockets of the kernel dial by default: outbounds, DNS upstreams, rule-set downloads.

FieldMeaning
interfaceThe interface to bind to
fwmarkThe mark for sockets without a mark of their own
interfacesA block {strategy, type, fallback} like dial.interfaces; the strategy requires auto_detect_interface or dial.interface
fallback_delayAs in the dial block
tcp.congestionThe congestion control algorithm for sockets without their own (dial.tcp.congestion)

Priority: the outbound's own dial, then outbounds.defaults.dial, then route.dial.

The sing-box fields rule_set, default_domain_resolver, geoip and geosite are a load error with a hint, see Migration.

Checking a route ​

ours explain shows which rules would match for a given connection (Command line); in the dashboard the same is the route check.

GPL-3.0-or-later