English
tproxy (inbound only)
A Linux transparent proxy: accepts TCP connections and UDP packets that nftables/iptables redirected to it with a tproxy rule, with their original destination address. It is used on a router to proxy the traffic of devices without configuring them. Compatible with sing-box tproxy; nat and auto_nft are ours extensions.
The interception rules can be written by hand or left to the process (auto_nft).
Fields
| Field | Type | Default | Meaning |
|---|---|---|---|
network | tcp, udp or a list | both | What to accept |
nat | block | see below | UDP NAT behavior; udp_nat is an error with a hint |
auto_nft | block | — | The nftables table and policy routing the process sets up |
Socket settings are the listener block; its udp.timeout is the lifetime of a UDP flow without packets.
nat
| Field | Values | Default | Meaning |
|---|---|---|---|
mapping | endpoint_independent, address_dependent, address_and_port_dependent | endpoint_independent | When a new flow is created for a new peer of the client (RFC 4787) |
filtering | the same | endpoint_independent | From which addresses replies are let through to the client |
max_flows | number | 4096 | How many UDP flows to keep; on overflow the old ones are evicted |
endpoint_independent for both is Full Cone NAT, which games and calls need.
auto_nft
The process itself writes the inet ours table (over netlink, without the nft/ip binaries) and a policy routing rule that delivers marked packets to the local socket. It needs CAP_NET_ADMIN and the nft_tproxy, nf_tproxy_ipv4/6 modules. On stop the table and the route are removed. After a crash (SIGKILL, OOM) they stay and steer the LAN's traffic and its DNS into a closed port; the next ours run or ours clean removes them, see running as a service.
| Field | Type | Default | Meaning |
|---|---|---|---|
interfaces | string or list | required | Incoming interfaces whose traffic is intercepted |
capture | rules, all | rules | What to intercept, see below |
router | bool | false | Also intercept the router's own traffic |
dns | bool | false | DNS to port 53 from interfaces (and from 127.0.0.1/::1 with router) goes to dns.listen |
exclude | list of addresses/subnets | — | Sources that are never intercepted |
fakeip_for_direct | bool | false | Give a fakeip also to domains that go directly |
mark | string value/mask | 0x1000000/0x3000000 | The interception mark; a mask bit outside the value is the mark of the process's own sockets |
route_table | number | 100 | The policy routing table; 0, 253–255 are forbidden |
What is intercepted. A target "in the kernel" is what the kernel can handle without the process: a direct outbound without a dial block and the route action to: bypass. With capture: rules the fakeip pools on all ports are intercepted, as well as the addresses, subnets and ports from route rules that may lead somewhere other than the kernel; the kernel routes the rest by itself. With capture: all everything is intercepted except what the rules certainly lead to the kernel. The decision is made by the first packet of a flow.
DNS. Without auto_nft, or with fakeip_for_direct: true, the fakeip DNS rule always gives a fakeip. With auto_nft and fakeip_for_direct: false a domain that the route rules will send to the kernel gets the real address, and its traffic bypasses the process.
Checks at load time: only one tproxy inbound may have auto_nft; with dns, dns.listen must have a wildcard address or an interface address, and with router also a wildcard or loopback; the dial.fwmark of any outbound must not touch the mark mask. A reload and updates of rule-sets and subscriptions recompute the interception set.
detour and listener.netns work as for all inbounds (listener). In another namespace the interception would have to be set up there, so netns together with auto_nft is an error (netns: auto_nft sets up the process's own namespace, not the listener's).
Example
yaml
inbounds:
transparent:
tproxy:
listen: ":7895"
nat:
mapping: endpoint_independent
filtering: endpoint_independent
max_flows: 8192
auto_nft:
interfaces: [br-lan]
capture: rules
router: true
dns: true
exclude: [192.168.1.50, 192.168.1.64/28]
outbounds:
direct:
direct:
proxy:
socks:
server: 192.0.2.10:1080
dns:
listen: ":53"
upstreams:
local:
udp: 1.1.1.1
final:
upstream: local
route:
rules:
- match:
ip_is_private: true
to:
outbound: direct
final:
outbound: proxyWithout auto_nft the nftables rules are written by hand, and the inbound is just tproxy: {listen: ":7895"}. The dns and route sections are described in the configuration.