Skip to content

Rule actions ​

to — final actions ​

After to the rules are no longer checked.

EntryWhat happens
to: {outbound: <name>}The connection goes to an outbound
to: {group: <name>}The connection goes to a group, and the group chooses a member
to: blockRefusal: a TCP connection is reset (RST), a UDP flow is closed
to: {block: drop}A "silent" refusal: a TCP connection is closed without RST, a UDP flow is closed
to: {block: default}The same as to: block
to: hijack-dnsThe built-in DNS serves the connection: the queries in it are answered by dns.rules
to: bypassPast the process: auto_nft does not intercept such a destination, the kernel routes it
yaml
- match:
    domain_suffix: ads.example.org
  to: block
- match:
    port: 25
  to:
    block: drop
- match:
    domain_suffix: example.org
  to:
    outbound: proxy

A name without a kind (to: proxy) is an error: the kind is written explicitly, outbound: or group:.

With auto_nft, the refusal method also sets the DNS answer for a domain whose every route is a refusal, see Fakeip and auto_nft.

block: reply is accepted, but is not supported for TCP and UDP: TCP is reset (RST), the UDP flow is closed, and an error is written to the log.

to: bypass makes sense together with auto_nft on a tproxy inbound: destinations for which all paths by the rules lead to bypass or to a plain direct are not brought into the process. If such a connection still reaches the process, the rule with bypass is skipped and the check goes on. For final: bypass, see final.

do — intermediate actions ​

After do the check continues from the next rule.

Sniffing: sniff ​

Reads the start of the connection and determines the protocol, the domain (SNI for TLS and QUIC, Host for HTTP) and the client. After that the protocol and client conditions and the domain conditions for connections to an IP address start working. The destination address does not change: the connection goes where it was going.

yaml
- do: sniff
- match:
    network: udp
  do:
    sniff:
      protocols: [tls, http, quic]
      timeout: 300ms
FieldMeaningDefault
protocolsWhich protocols to recognize: tls, http, quic, dns, stun, bittorrent, dtls, ssh, rdp, ntpall built in
timeoutHow long to wait for the first data300ms

dns recognizes DNS queries both in TCP and in UDP.

Sniffing is skipped on ports where the server speaks first (SMTP, for example), and for a connection that has already been sniffed.

Resolving: resolve ​

Resolves the destination domain with the built-in DNS, so that the next rules with ip_cidr and ip_is_private see the IP address.

yaml
- do: resolve
- match:
    ip_cidr: 10.0.0.0/8
  to:
    outbound: direct
FieldMeaning
strategyprefer_ipv4, prefer_ipv6, ipv4_only, ipv6_only
cachefalse — do not take the answer from the cache; {optimistic: false} — do not answer with stale cache records
rewrite_ttlReplace the answer's TTL
timeoutThe query timeout
client_subnetThe subnet for EDNS Client Subnet

The upstream is not given here (a server field is an error): dns.rules choose it. The query carries the connection's inbound, source and domain and has no outbound, so outbound rules do not apply. If the name does not resolve, the connection is refused.

Connection parameters: options ​

Sets the parameters with which the connection will be established once it gets a route.

yaml
- match:
    network: udp
    port: 443
  do:
    options:
      udp:
        timeout: 30s
FieldMeaning
overrideConnect to this host:port instead of the original one; ":53" replaces only the port
interfacesThrough which networks to connect: a block {strategy, type, fallback}, like dial.interfaces
fallback_delayThe pause before the fallback, a duration (300ms)
udpUDP of the connection: timeout — the idle time of a flow before it is closed; connect — a connected UDP socket; disable_domain_unmapping — do not substitute the domain back for the address in answers
reloadThe reload policy for such connections: reroute_changed, keep, close, see reload

The sing-box names (override_address, udp_timeout, network_strategy, tls_fragment, …) are an error with a hint of where the field moved: `udp_timeout` is `udp.timeout`.

An empty options is an error. Several do: options in a row complement each other, and the last value of a field wins.

tls.fragment (packet, record, fallback_delay) and tls.spoof (sni, method) are not supported: a configuration with them does not load.

To make the parameters apply to one route only, put do: options immediately before the to rule with the same match, see Rules.

GPL-3.0-or-later