Skip to content

Router ​

A router (OpenWrt or any Linux that the LAN goes through) sends the traffic of the network's devices through the subscription's servers, without configuring the devices themselves. Sites from your own list, the local network and everything the rules send directly bypass the process and go straight through the kernel.

How it works:

  • the tproxy inbound with auto_nft sets up the nftables table and policy routing by itself: only what the rules may send somewhere other than directly is intercepted;
  • the devices' DNS is intercepted to the built-in DNS server; domains that will go through the proxy get a fakeip, so the proxy server sees the domain, not the address;
  • the servers come from the subscription, and the subscription's group picks the fastest one.

You need the kernel modules nft_tproxy, nf_tproxy_ipv4, nf_tproxy_ipv6, nft_fib_inet (on OpenWrt, the packages kmod-nft-tproxy, kmod-nft-fib) and to run as root. The binary for a router is the static musl one (Installation).

Configuration ​

yaml
inbounds:
  lan:
    tproxy:
      listen: ":7895"
      auto_nft:
        interfaces: [br-lan]
        router: true
        dns: true

outbounds:
  direct:
    direct:

subscriptions:
  provider:
    remote:
      url: https://panel.example.com/sub/abc
      update: 6h
    group:
      rank:
        delay:
          probe:
            interval: 5m

rule_sets:
  domestic:
    inline:
      - domain_suffix: [ru, su, рф]

dns:
  listen: ":53"
  upstreams:
    isp:
      udp: 77.88.8.8
    remote:
      https: 1.1.1.1
      via: provider
  fakeip:
    inet4: 198.18.0.0/15
  rules:
    - match:
        rule_set: domestic
      to:
        upstream: isp
    - match:
        query_type: [A, AAAA]
      do: fakeip
  final:
    upstream: remote

route:
  rules:
    - match:
        ip_is_private: true
      to:
        outbound: direct
    - match:
        rule_set: domestic
      to:
        outbound: direct
  final:
    group: provider
  • interfaces: [br-lan] is the LAN interface; on OpenWrt it is br-lan, on another Linux the name of the bridge or port the devices are connected to.
  • router: true does the same for the router's own connections; with dns: true the devices' DNS queries to port 53 go to dns.listen. If dnsmasq already runs on port 53 on the router, either move it to another port, or remove dns: true, set dns.listen to 127.0.0.1:5353 and make that address dnsmasq's upstream.
  • domestic are your own sites: their DNS is asked of the ISP (isp), and their connections go directly through the kernel, without the process. A downloaded rule-set works instead of inline too (Rule-sets).
  • Other domains get a fakeip and their connections go to the provider group. Queries to remote go through the same subscription, so that the ISP does not see which domains are asked for.

Connections to an address without a DNS query (programs with their own IP list) go directly by default with capture: rules: only fakeip addresses and the addresses of rules that lead somewhere other than directly are intercepted. To send everything but what is explicitly direct through the proxy, set capture: all in auto_nft.

For this configuration ours check warns that the subscription has not been downloaded yet and the provider group is empty: the servers appear after the first download under ours run.

Running ​

sh
ours check -c /etc/ours/config.yaml
ours run -c /etc/ours/config.yaml

On OpenWrt, as a procd service or from /etc/rc.local; on Linux with systemd, the unit from Installation. It is important that ours clean runs after a crash: otherwise the interception rules stay and the LAN is left without network until the next start.

To check from a device in the LAN, open any site; a connection through provider/<server> appears in the router's log. Which rule chose the outbound is shown by ours explain:

sh
ours explain -c /etc/ours/config.yaml --inbound lan --destination example.com:443 --domain example.com

If something does not work, see Troubleshooting.

GPL-3.0-or-later