English
The listener block
The socket settings of an inbound are the listener block next to the protocol block, like dial for an outbound. The address listen: host:port stays in the protocol block, like server for an outbound. The block is the same for all inbounds (anytls, direct, http, mixed, hysteria, hysteria2, redirect, shadowsocks, shadowtls, socks, tproxy, trojan, tuic, vless); for tun only udp.timeout has an effect.
yaml
inbounds:
local:
mixed:
listen: 127.0.0.1:1080 # the address is in the protocol
users: # a protocol field
- username: user
password: pass
listener: # the socket is next to it
tcp:
fast_open: true
udp:
timeout: 2m
outbounds:
direct:
direct:
route:
final:
outbound: directAddress
listen: host:port in the protocol block: :1080 is all addresses, [::1]:1080 is IPv6. The port is written only here: a separate listen_port field is an error (`listen_port` belongs in `listen: host:port`). listen is required, and so is the port in it: an inbound without listen is inbound: `listen` is required, an address without a port is listen: `127.0.0.1` has no port. A free port chosen by the system is given explicitly, as zero: listen: 127.0.0.1:0 (all shards listen on the same chosen port).
Two inbounds on the same address and port are a load error (inbound `b` listens on port 1080 (tcp) as inbound `a` does): TCP inbounds collide with TCP, UDP with UDP, so a TCP inbound and a QUIC inbound on the same port are allowed. A port already held by another process, including a second instance of ours, is a startup error: listen 127.0.0.1:1080 (tcp): address already in use by another process or inbound.
listener fields
| Field | Type | Default | Meaning |
|---|---|---|---|
interface | string | — | Bind the socket to an interface |
fwmark | number | — | The socket's SO_MARK mark |
reuse_addr | bool | false | SO_REUSEADDR |
netns | name or path | — | The network namespace the inbound listens in: a name from network_namespaces, a path (/run/netns/vpn, /proc/<pid>/ns/net) or an ip netns name. Accepted connections and UDP replies stay in it; outbounds connect from the process's own namespace. Requires CAP_SYS_ADMIN; a namespace that cannot be entered is a load error |
tcp | block | — | fast_open (TCP Fast Open), multi_path (MPTCP), congestion — the congestion control algorithm of accepted connections (as in dial), keep_alive — false turns it off, the block {idle, interval} sets the idle time before the first probe and the probe interval. The same block as in dial |
udp | block | — | timeout — how long a UDP session lives without packets (5m by default, a number without units is seconds); fragment — allow UDP fragmentation (QUIC inbounds, tproxy, direct) |
first_request | block | — | timeout — how long an accepted connection may go until its first request (60s by default); limit — how many connections of the inbound may wait for their first request at the same time (no limit by default). See below |
Socket fields in the protocol block are an error with a hint: `interface` belongs in the inbound's `listener` block. An unknown field in listener is listener: unknown field `x` .
tcp has no effect for QUIC inbounds (hysteria, hysteria2, tuic): they listen on UDP. Their QUIC settings are the shared quic block in the protocol.
udp.timeout has an effect for inbounds that accept UDP: socks, mixed, direct, tproxy, tun, shadowsocks, trojan, vless, the QUIC inbounds.
first_request
An accepted connection must send the first request of the protocol within timeout, counted from acceptance: TLS (or REALITY) and the transport, if any, plus the protocol header — a SOCKS request, an HTTP head, a Shadowsocks, VLESS or Trojan header, the ClientHello of ShadowTLS v2/v3, the AnyTLS password. If it does not arrive in time, the connection is closed silently. After the first request there is no limit: idle tunnels, keep-alive requests, UDP ASSOCIATE and mux streams are not affected.
limit is how many connections of the inbound may be in this interval at the same time. While the limit is taken, the inbound does not accept new connections; they wait in the kernel queue (backlog), as with an overloaded server, rather than being refused. The limit is shared by the inbound across all shards. No limit by default. A reasonable value is several hundred to several thousand, depending on how many clients connect at once.
direct, redirect and tproxy do not wait for a first request: the block has no effect on them. AnyTLS is additionally limited by its own 15 s, and ShadowTLS v1 by the handshake server to which it proxies the connection right away.
yaml
inbounds:
proxy-in:
trojan:
listen: :443
users:
- name: alice
password: secret
tls:
certificate_path: /etc/ours/cert.pem
key_path: /etc/ours/key.pem
listener:
first_request:
timeout: 30s
limit: 2048detour
detour is the name of an inbound to hand the connection to instead of routing it. It is a field of the protocol, not of the socket, and every inbound has it. What the inbound parsed is handed over: for direct and tproxy, the TCP connection itself; for proxy protocols, the stream after their header; for an HTTP proxy, also a plain request (not CONNECT) together with the response. Such a connection is accepted by shadowsocks, socks, trojan and vless; for the others the log says this inbound cannot be a detour. A vless inbound over QUIC takes none, and kTLS needs the connection handed over to be a plain TCP one. A UDP flow is handed over too: what the inbound decoded and the address its client sent to. It is accepted by shadowsocks and direct, which takes that address for its own; for the others the log says this inbound cannot be a UDP detour.
yaml
inbounds:
forward:
direct:
listen: :9388
network: tcp
detour: ss-in # all TCP from port 9388 goes to the ss-in inbound
ss-in:
shadowsocks:
listen: 127.0.0.1:8388
method: 2022-blake3-aes-128-gcm
password: 8JCsPssfgS8tiRwiMlhARg==
outbounds:
direct:
direct:
route:
final:
outbound: directNot supported
- Deprecated sing-box fields are a load error with a hint (
`sniff` is not an inbound field: sniffing is the `sniff` rule action):sniff,sniff_override_destination,sniff_timeout— sniffing is set by the route actiondo: sniff;domain_strategy— thedo: resolveaction;udp_disable_domain_unmapping— a field ofdo: options;proxy_protocol,proxy_protocol_accept_no_header— the PROXY protocol is not supported.
The nat and auto_nft blocks exist only in tproxy: they are its settings, not the socket's.