Tunnel Inbound (Port Forwarding)¶
Tunnel inbounds forward incoming TCP and/or UDP connections on a local port to a fixed target address.
- Platform / Feature: All platforms, built-in.
- Routing behavior:
- When
proxyis set to an outbound proxy or proxy group name (includingDIRECT,REJECT,GLOBAL, or a provider node looked up at traffic time), all traffic through the tunnel uses that outbound regardless ofmode. If the named outbound is unavailable, traffic is dropped. - When
proxyis omitted (or empty), traffic goes through normal routing rules.
Top-Level tunnels Shorthand¶
tunnels accepts either structured YAML mappings or comma-separated strings:
tunnels:
- network: [tcp, udp]
address: 127.0.0.1:1053
target: 192.0.2.53:53
proxy: DIRECT
- "tcp,127.0.0.1:8443,example.org:443"
- "tcp/udp,127.0.0.1:5353,1.1.1.1:53,PROXY"
Mapping Fields¶
| Key | Type | Required | Description |
|---|---|---|---|
network |
list["tcp" \| "udp"] |
Yes | Non-empty list of protocols (tcp, udp). |
address |
string |
Yes | Local bind host:port (empty host or * → 0.0.0.0; localhost → 127.0.0.1). |
target |
SocksAddr |
Yes | Fixed destination host:port (port must be non-zero). |
proxy |
string |
No | Fixed outbound or proxy group name. Omit for normal rule routing. |
String Format¶
networkseparates protocols with/(e.g.tcp,udp,tcp/udp).- Duplicate
(listen, port, transport)entries return a configuration error. - Generated listener names follow
tunnel-<networks>-<listen>withallow-landerived from!listen.ip().is_loopback()andfw-markinherited from top-levelrouting-mark.
Named Listener (listeners with type: tunnel)¶
You can configure the exact same tunnel as an explicit listener by splitting address into listen and port:
listeners:
- name: dns-tunnel
type: tunnel
listen: 127.0.0.1
port: 1053
network:
- tcp
- udp
target: 192.0.2.53:53
proxy: DIRECT
| Key | Type | Required | Description |
|---|---|---|---|
name, type, listen, port, fw-mark |
Common fields | Yes (except fw-mark) |
Standard listener fields (type: tunnel). |
network |
list["tcp" \| "udp"] |
Yes | Protocols to listen on (case-insensitive). |
target |
SocksAddr |
Yes | Destination host:port. |
proxy |
string |
No | Fixed outbound name; omit to route normally. |