Skip to content
BoWen Chai's Notes
Go back

Use Tailscale Behind a Transparent Proxy (sing-box / Momo)

Updated:
AIWriteEdit page

Behind an OpenWrt sing-box (Momo) transparent proxy, inbound Tailscale SSH can fail in a confusing way:

Summary

Why it looks intermittent

Tailscale tries direct UDP first and falls back to DERP relays (or a Peer Relay) when NAT traversal fails:

  1. A cloud node opens a cold inbound SSH connection to the home node.
  2. No direct NAT mapping exists yet, so Tailscale falls back to DERP.
  3. Momo routes the DERP connection to outbound/socks, where it dies with EOF.
  4. Running tailscale ping from the home node opens an outbound UDP NAT state and establishes a direct peer path.
  5. SSH works over that direct path until idle time expires the NAT entry; with DERP broken, there is no fallback and the session freezes silently.

Because SSH works as soon as a direct path is warm, sshd is fine—the broken relay path is the issue.

Split control plane vs. transport plane

In mainland China behind OpenWrt transparent proxying, Tailscale’s two traffic planes need opposite routes:

Routing the whole device direct breaks control-plane reachability where coordination servers are blocked; proxying everything breaks UDP and DERP streams.

Confirming the problem

1. Check tailscaled on the home node

tailscale status
tailscale netcheck
systemctl status tailscaled

Look for a normal logged-in daemon with DERP/relay failures in netcheck. Do not restart tailscaled over an active SSH session—it will cut your connection without fixing router rules.

2. Compare cold inbound vs. warm NAT

From the cloud node, try SSH before sending anything from home:

ssh <USER>@<HOME_NODE_TAILSCALE_IP>

Then punch an outbound packet from the home node:

tailscale ping <CLOUD_NODE_TAILSCALE_IP>

If SSH starts working right after tailscale ping, outbound packets are warming a direct path while inbound relay fallback is dead.

3. Check tailscaled and Momo logs together

Home node:

journalctl -u tailscaled --since "30 minutes ago"

OpenWrt:

logread -e momo | tail -n 120

You should see tailscaled DERP EOF errors lining up with Momo sending literal DERP IPs into the proxy:

tailscaled: DERP connection -> EOF
Momo: <DERP_IP>:3478 -> outbound/socks
Momo: <DERP_IP>:80   -> outbound/socks
Momo: <DERP_IP>:443  -> outbound/socks

Why DNS-only rules fail

Putting .tailscale.com / DERP hostnames ahead of Fake-IP and GeoIP passes sing-box check, but DERP still ends up on outbound/socks. tailscaled already has the relay IPs from the downloaded DERP map and connects directly by IPv4/IPv6 without a domain match. Those connections fall straight through to the default proxy outbound unless matched by port and IP rule-set.

sing-box / Momo routing policy

Put these rules right after protocol sniffing—before source bypass, Fake-IP, GeoIP, private-CIDR, and selector rules:

{
  "route": {
    "rule_set": [
      {
        "type": "local",
        "tag": "tailscale-derp",
        "format": "source",
        "path": "/etc/momo/ruleset/tailscale-derp.json"
      }
    ],
    "rules": [
      {
        "network": "udp",
        "source_port": 41641,
        "action": "route",
        "outbound": "direct"
      },
      {
        "network": "udp",
        "port": 3478,
        "action": "route",
        "outbound": "direct"
      },
      {
        "network": "tcp",
        "port": [80, 443],
        "rule_set": ["tailscale-derp"],
        "action": "route",
        "outbound": "direct"
      },
      {
        "ip_cidr": [
          "100.64.0.0/10",
          "fd7a:115c:a1e0::/48",
          "<CLOUD_NODE_PUBLIC_IP>/32"
        ],
        "action": "route",
        "outbound": "direct"
      },
      {
        "domain_suffix": [".tailscale.com", ".tailscale.io"],
        "action": "route",
        "outbound": "<STABLE_PROXY_OUTBOUND>"
      }
    ]
  }
}

Check your node’s actual tailscaled UDP port before hard-coding 41641 (Tailscale firewall ports). If you also match DERP hostnames (derp*.tailscale.com), place that rule directly above the .tailscale.com proxy rule.

Keeping DERP IPs fresh

Tailscale rotates DERP IPs, so avoid a hand-maintained static list. Fetch the current map from:

curl -fsS https://login.tailscale.com/derpmap/default | jq .

Automate updates on the router with a scheduled job:

  1. Download https://login.tailscale.com/derpmap/default to a temp file and verify valid JSON.
  2. Extract all IPv4 and IPv6 entries into a temp sing-box source rule-set (rule-set format).
  3. Validate the full config with sing-box check -c <MOMO_CONFIG>.
  4. Atomically replace /etc/momo/ruleset/tailscale-derp.json only if validation passes; keep the old file on failure.

Reload and cold-test

Keep a second SSH session open and set a timed rollback before reloading Momo remotely:

sing-box check -c <MOMO_CONFIG>
/etc/init.d/momo reload
/etc/init.d/momo status
logread -e momo | tail -n 120

Confirm all four flows hit the expected outbound in logread:

UDP source 41641        -> outbound/direct
UDP destination 3478    -> outbound/direct
DERP TCP 80 / 443       -> outbound/direct
Tailscale control plane -> <STABLE_PROXY_OUTBOUND>

Then verify from a cold state (a warm NAT test hides broken DERP):

  1. Stop any temporary ping keepalive.
  2. Wait past the NAT idle timeout without running tailscale ping.
  3. SSH from the cloud node to <HOME_NODE_TAILSCALE_IP> and confirm it connects on the first try.
  4. Leave the shell idle past the previous freeze window and verify it still responds.
  5. Reboot the home node when convenient and repeat the cold SSH check.

Optional: self-hosted Peer Relay

If public DERP latency is too high, any cloud node with a public IP running Tailscale 1.86+ can serve as a private Tailscale Peer Relay:

sudo tailscale set \
  --relay-server-port=<PEER_RELAY_UDP_PORT> \
  --relay-server-static-endpoints="<CLOUD_NODE_PUBLIC_IP>:<PEER_RELAY_UDP_PORT>"

Open <PEER_RELAY_UDP_PORT>/udp on the cloud firewall, add <CLOUD_NODE_PUBLIC_IP>/32 to Momo’s direct CIDR list, and grant tailscale.com/cap/relay to the nodes that should use it.


Edit page
Share this post:

Previous Post
Note App: 胶片冷暖分离与闪光速查手册
Next Post
Write Markdown Lexer and Parser in Zig