Back to postsPOST 06

How My Home Network Evolved After TProxy

Moving from a single bare-metal Ubuntu box with iptables and mihomo to Proxmox VE, Fedora Cloud, sing-box TUN, dual-stack IPv6 policy routing, and split-horizon DNS.

Contents

Comments

Last year, I wrote about setting up a transparent proxy for my home network using an OpenWrt router, a bare-metal Ubuntu 24.04 server, mihomo, and a handful of iptables rules. That setup worked, and for a few months I barely touched it.

Over the past year, though, as more services moved onto the home server and dual-stack IPv6 became harder to ignore, the cracks in that first design started showing:

  1. Everything shared a single bare-metal OS. My NAS storage, media server, reverse proxy, WireGuard endpoint, and packet-intercepting gateway all lived directly on one Ubuntu installation. Touching iptables, routing tables, or systemd-resolved always carried the risk of knocking unrelated services offline. Add Canonical’s increasingly sluggish kernel security updates on top of Snap and apt noise, and I was ready to move on from Ubuntu altogether.
  2. IPv6 was still a workaround, not a solution. Stripping AAAA records and disabling IPv6 DNS announcements in Router Advertisements forced proxied domains over IPv4, which worked as a stopgap. At the end of the previous post, I added a note (“Solution C”) about using source-based IPv6 policy routing on the main router. I finally built that out properly.
  3. Configuration sprawl. Maintaining external iptables scripts alongside bloated, legacy-style proxy rulesets and proxy-side internal DNS overrides made the whole stack harder to reason about than it needed to be.

Here is how the architecture looks today after rebuilding it around Proxmox VE, Fedora Cloud, sing-box, and router-level policy routing.

From Bare-Metal Ubuntu to Proxmox VE

The biggest structural change was wiping Ubuntu off the home server (192.168.1.10) and installing Proxmox VE (built on Debian) as a bare-metal hypervisor.

Instead of piling services onto one host OS, workloads are now split strictly by how much kernel isolation they need:

  • LXC containers handle lightweight user-space services with near-zero memory overhead, each with its own static LAN IP on br-lan:
    • NAS (192.168.1.11): Headless Samba (SMB) container with no web UI, bind-mounting /srv/nas read-write from the host for LAN file sharing.
    • Media server (192.168.1.12): Bind-mounts /srv/nas read-only and runs Jellyfin with /dev/dri iGPU passthrough for hardware transcoding.
    • WireGuard + DDNS (192.168.1.13): Terminates remote road-warrior tunnels (192.168.2.0/24) over IPv6 UDP, requiring zero open IPv4 ports on the WAN.
    • Caddy (192.168.1.14): Serves internal HTTPS reverse proxies (pve, media, and the proxy dashboard) using Let’s Encrypt DNS-01 challenges, giving internal web UIs valid TLS certificates without exposing ports 80 or 443 to the internet.
  • Full VMs (Fedora Cloud) run anything that manipulates kernel networking, nftables, or tun interfaces—most importantly a dedicated transparent gateway VM (proxy at 192.168.1.2).

Moving the gateway into its own VM turned upgrades and experiments into a trivial blue-green swap. When migrating my proxy stack recently, I spun up a fresh Fedora Cloud VM at 192.168.1.2, verified routing and DNS against a single test client, flipped the DHCP gateway option on the main router, and destroyed the old proxy VM—zero downtime, zero leftover state. Fedora Cloud also tracks upstream mainline kernels closely, and dnf5-automatic (apply_updates=True, reboot=when-needed) keeps both the kernel and proxy packages current without babysitting.

Replacing iptables + mihomo with sing-box TUN

In the old setup, mihomo listened on a TPROXY port while a separate shell script populated iptables -t mangle and ip rule tables on boot. On the new proxy VM, I replaced both with sing-box.

With tun configured using auto_route: true and auto_redirect: true, sing-box creates the virtual interface and programs nftables TCP redirection in the kernel automatically—combining native TCP redirect performance with clean UDP handling over TUN, with no external firewall scripts to maintain.

Letting sing-box Own Port 53

Fedora enables systemd-resolved on 127.0.0.53:53 by default. Rather than redirecting port 53 to an alternate port like 5353 as I did before, I disabled systemd-resolved and let NetworkManager manage /etc/resolv.conf directly (pointing the VM itself at the main router 192.168.1.1), freeing port 53 for sing-box:

sudo systemctl disable --now systemd-resolved.service systemd-resolved-varlink.socket systemd-resolved-monitor.socket

sudo tee /etc/NetworkManager/conf.d/90-system-dns.conf >/dev/null <<'EOF'
[main]
dns=default
rc-manager=symlink
EOF

sudo ln -sf /run/NetworkManager/resolv.conf /etc/resolv.conf
sudo systemctl reload NetworkManager

Keeping TUN, FakeIP, and Sniffing Simple

Using sing-box 1.14 rule actions (sniff, hijack-dns, and reject), the core inbound and routing setup stays very compact—proxying only matched rule-sets while sending everything else straight out. Note that the snippet below is only an excerpt (dns, outbounds, and route.rule_set definitions are omitted, so do not copy-paste it as a standalone config.json):

{
  "inbounds": [
    {
      "type": "direct",
      "tag": "dns-in",
      "listen": "::",
      "listen_port": 53
    },
    {
      "type": "tun",
      "tag": "tun-in",
      "address": ["172.19.0.1/30", "fdfe:dcba:9876::1/126"],
      "auto_route": true,
      "auto_redirect": true,
      "stack": "system"
    }
  ],
  "route": {
    "rules": [
      { "action": "sniff" },
      { "protocol": "dns", "action": "hijack-dns" },
      { "ip_is_private": true, "outbound": "direct" },
      { "rule_set": ["proxy"], "protocol": "quic", "action": "reject" },
      { "rule_set": ["proxy"], "outbound": "PROXY" }
    ],
    "final": "direct",
    "auto_detect_interface": true,
    "default_domain_resolver": "local"
  }
}

On the DNS side, only A and AAAA queries matching the proxy rule-set hit fakeip (198.18.0.0/15), while everything else resolves normally through 192.168.1.1. Combined with {"action": "sniff"} for connections that bypass system DNS, domain-based routing works without leaking proxied lookups. Rejecting "protocol": "quic" on proxied rules nudges browsers to fall back cleanly to HTTP/2 over TCP instead of tunneling QUIC inside a TCP-based proxy stream, without blocking non-QUIC UDP traffic on port 443.

Finally Solving IPv6 (“Solution C” in Practice)

In my selectively proxied LAN, some devices (laptops, phones, workstations) should use the transparent proxy, while others (smart TVs, IoT devices, the NAS itself) should talk straight through the main router (192.168.1.1) so a proxy restart never affects them.

For IPv4, selective gateway assignment is trivial in OpenWrt’s dnsmasq: assign a proxy tag to selected hosts by MAC address and hand them 192.168.1.2 as both default gateway (option 3) and DNS server (option 6):

# /etc/config/dhcp (excerpt)
config tag 'proxy'
    list dhcp_option '3,192.168.1.2'
    list dhcp_option '6,192.168.1.2'

config host
    option name 'workstation'
    option mac 'aa:bb:cc:00:00:10'
    option ip '192.168.1.50'
    option tag 'proxy'

For IPv6, as noted in the previous post, DHCPv6 does not distribute default gateways—hosts learn their IPv6 router from multicast Router Advertisements (RA), which apply to the whole L2 broadcast domain rather than per MAC address.

The real fix is source-based policy routing on the OpenWrt main router:

  1. Every device on the LAN continues to learn the main router (192.168.1.1 / link-local fe80::1) as its default IPv6 router via RA.
  2. When a proxied client sends an IPv6 packet toward the internet, an OpenWrt firewall rule matches its source MAC address and marks the packet with fwmark 0x100.
  3. An IPv6 routing rule directs fwmark 0x100 packets to routing table 100, whose default route forwards them over br-lan to the proxy VM’s link-local IPv6 address (fe80::200:ff:fe00:2).
  4. sing-box on proxy intercepts the forwarded IPv6 traffic via tun-in (auto_route + auto_redirect with net.ipv6.conf.all.forwarding=1), sniffs or matches IP rules, and either proxies it or sends it out directly. Because packets originating from proxy’s own MAC address are never marked with 0x100, outbound IPv6 traffic from proxy passes cleanly through the main router to the WAN interface without looping.

In OpenWrt (/etc/config/firewall and /etc/config/network), the entire mechanism takes three blocks:

# /etc/config/firewall (excerpt)
config rule
    option name 'proxy-ipv6-clients'
    option src 'lan'
    option dest '*'
    option family 'ipv6'
    option proto 'tcp udp'
    list src_mac 'AA:BB:CC:00:00:10'
    list src_mac 'AA:BB:CC:00:00:11'
    option target 'MARK'
    option set_mark '0x100'

# /etc/config/network (excerpt)
config rule6
    option mark '0x100'
    option lookup '100'

config route6
    option interface 'lan'
    option target '::/0'
    option gateway 'fe80::200:ff:fe00:2'
    option table '100'

With this in place, untagged devices get native ISP IPv4/IPv6 straight from the main router, while tagged clients get transparent dual-stack routing without disabling IPv6 on the LAN.

Split-Horizon DNS Without Touching the Proxy

One subtle trap appeared once internal services (pve.example.com, media.example.com, proxy.example.com) were placed behind the Caddy LXC (192.168.1.14) while example.com also hosted public endpoints on Cloudflare.

At first, it is tempting to put internal domain rules inside sing-box. That turns out to be the wrong layer for three reasons:

  • Unproxied LAN devices never query sing-box, so they cannot resolve internal hostnames unless the main router knows about them anyway.
  • Matching a broad domain_suffix like .example.com inside DNS rules accidentally shadows public subdomains under the same zone.
  • If the Caddy container itself points its DNS at the LAN while renewing DNS-01 certificates, internal overrides can interfere with ACME propagation checks.

Moving split-horizon DNS onto the main router’s dnsmasq solved all three problems at once:

# /etc/config/dhcp on the main router
uci add_list dhcp.@dnsmasq[0].address='/media.example.com/pve.example.com/proxy.example.com/192.168.1.14'
uci add_list dhcp.@dnsmasq[0].server='/media.example.com/pve.example.com/proxy.example.com/'
uci commit dhcp
/etc/init.d/dnsmasq reload

Pairing address= with server=/.../ (with an empty upstream) tells dnsmasq that those exact three hostnames—and only those three, not arbitrary subdomains—are strictly local:

  • A queries immediately return 192.168.1.14 (the Caddy LXC).
  • AAAA and HTTPS (TYPE65) queries return a local empty NOERROR in 0 ms instead of leaking internal service names upstream to the ISP resolver or returning public records.
  • Both direct LAN clients (querying 192.168.1.1) and proxied clients (querying 192.168.1.2, whose local upstream is 192.168.1.1) get identical answers with zero domain-specific rules inside sing-box.

Meanwhile, the Caddy LXC is configured with public resolvers in its own /etc/resolv.conf so Let’s Encrypt DNS-01 checks always see the public authoritative view, and the proxy VM carries a single static route (192.168.2.0/24 via 192.168.1.13) so return packets to remote WireGuard peers go straight back to the WireGuard container instead of entering the TUN gateway.

Architecture Today

Putting it all together, the home network has gone from one overloaded Ubuntu box to a clean separation of duties:

Proxmox VE Host (192.168.1.10) IPv6 RA · fwmark 0x100 Default IPv4 / IPv6 IPv6 UDP 51820 DHCPv4 GW + DNS IPv6 table 100 Direct / Encrypted Tunnel Split-Horizon DNS proxy.example.com pve.example.com media.example.com Dual-Stack ISP WAN OpenWrt Main Router192.168.1.1 Tagged ClientsWorkstation · Phone Direct ClientsTV · IoT VM: apps192.168.1.15 · Fedora LXC: nas192.168.1.11 · Samba (/srv/nas) LXC: caddy192.168.1.14 · DNS-01 HTTPS LXC: wg192.168.1.13 · WireGuard VM: proxy192.168.1.2 · Fedora + sing-box PVE Web UI192.168.1.10:8006 LXC: media192.168.1.12 · Jellyfin + iGPU

Every component now does one job: the router handles L3 policy routing and split-horizon DNS, Proxmox isolates infrastructure into disposable containers and VMs, Caddy terminates TLS internally, and sing-box stays focused on transparent proxying with a config small enough to read in one sitting.

Comments

Comments use GitHub for sign-in. They load automatically as you reach this section.

Search posts

Search post titles and text.

Enter a word or phrase to begin.