Skip to content

About

Home-first managed routing for ASUS Merlin: sing-box + dnsmasq/ipset split routing, Reality/Vision egress, XHTTP/Naive/Karing client lanes, health and traffic observability.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

8 stars

Watchers

0 watching

Forks

Repository files navigation

GhostRoute

Router-level Reality routing for ASUS Merlin: home ingress for mobile clients, Reality egress to VPS

License: MIT CI Platform Routing Status

Localized version ->

Documentation policy: English docs are the developer-facing ground truth; the Russian README is an operator-facing summary.

Software versions and upgrade gates track reviewed dependencies, qualified runtimes and deployment targets separately. The VPS software inventory records the per-role deployed baseline and explicit compatibility holds. The compatibility matrix explains tested combinations, retained versions and client acceptance boundaries. For Mac SSH over Tailscale and recovery over LAN or a bastion, see the router access guide. The archive and rotation checks are in the VPS audit runbook.


TL;DR

GhostRoute is a single-operator routing platform for an ASUS Merlin edge router. It keeps home LAN devices app-free, gives selected remote clients a home-first entrypoint, and keeps routing policy on the router. It also supports isolated policies for applications that require egress in a designated region. By default only managed destinations use the active Reality egress; selected home Wi-Fi/LAN devices and selected Channel A Home Reality profiles can opt into full-VPS mode where all internet-bound traffic uses reality-out. The active egress is normally the owned VPS, or an explicit reserve backend during incidents. The repo is intentionally module-native: routing, health, traffic, catalog, client profiles, secrets and recovery all have separate ownership and tests.

An opt-in cold emergency controller checks backup_reality every five minutes and can select backup_reality_emergency after thirty continuously observed failed minutes. It stops the former profile before qualifying the reserve, preserves client imports and requires manual return. Local faults and partial application failures do not trigger this switch. See the architecture diagram.

Sensitive sites mode gives reviewed destinations a dedicated sensitive-out egress before the general managed rules. The LAN managed guard protects already classified IPv4 TCP and UDP/443 during REDIRECT recovery; atomic ipset snapshots preserve the last valid saved classification. Channel M keeps its separate regional service policy.

GhostRoute: home-first networking

GhostRoute: home ingress and three explicit exit roles

Editable routing, lifecycle and recovery diagrams · Русские схемы.

For an operator map of what is installed on the ASUS Merlin router, including runtime files, services, cron watchdogs and channel diagrams, see docs/router-runtime-map.md. The privacy assurance checklist records what the managed guard proves, what requires a real client and how to check recovery. External egress profile rotation supports TCP or gRPC with Reality while preserving existing client imports. For the companion VPS-side runtime map used by Channel M, GhostRoute Console and the routing/app surfaces, see praefectus-ai/docs/vps-runtime-map.md.

Engineering Highlights

What this project demonstrates, with proof in-repo:

  • Architecture — a module-native platform: independently-owned modules (routing, health, traffic accounting + intelligence, DNS catalog, client profiles, secrets, recovery) each with their own runtime, docs and tests. See the ownership table in docs/operational-modules.md and the decisions in docs/adr/.
  • Testing — a layered pyramid (static contract checks -> mock/fixture integration -> Console smoke -> Playwright e2e), CI-gated on every push/PR via .github/workflows/ci.yml. Health tooling is driven end-to-end against stubbed ssh/vault/curl (see docs/testing.md).
  • Security & privacy — secrets stay out of git (Ansible Vault), a secret-scan gate runs in CI, and operational tooling is role-only: it prints mnemonic roles (primary_vps / backup_reality / hermes_vps), resolves real endpoints from Vault locally, and sanitizes operator summaries. Raw deployment and traffic evidence stays private. Operator and Console router access use separate credentials and a fixed service report gate. See SECURITY.md.
  • Product thinking — an explicit channel model, measurable SLOs (docs/operational-slos.md), and a deliberate, documented egress-failover design (docs/managed-egress-failover-roadmap.md). The problem framing and decisions live in docs/prd.md.
  • Operability & recovery — read-only health monitors, a recovery-verification module, deterministic deploy.sh / verify.sh entrypoints, sanitized runtime maps and a machine-readable traffic-accounting contract.
  • Maintainability & DX — ADR discipline, bilingual docs, contributor review gate, and reproducible local checks (./tests/run-fast.sh).

Maintenance and retention

See maintenance and retention for safe VPS cleanup, protected rollback/client assets and Console's automatic rolling 90-day traffic-history ceiling. Raw diagnostics use shorter retention windows.

Channel Status

An additive Snell + ShadowTLS lab provides three experimental identities. It requires separate client acceptance and does not replace the protected production anyT imports.

The failover column below describes switching between client channels. The opt-in cold emergency controller changes their shared egress backend, preserving the channel.

Channel Status First hop Scope Automatic failover
A Production router data plane Endpoint or LAN -> home router LAN split routing, selected full-VPS sets, Home Reality clients, active managed Reality egress No
B Production for selected device-client profiles Endpoint -> home router XHTTP/TLS ingress Protocol-diverse home-first client lane, relayed through the same managed split No
C C1-Shadowrocket live compatibility plus C1-sing-box native Naive design Endpoint -> home router HTTPS CONNECT or Naive ingress Home-first selected-client lane; C1-SR is iPhone-proven, C1-sing-box is server-ready but blocked by SFI 1.11.4 No
D Experimental router-native NaiveProxy lab Endpoint -> home router Caddy forward_proxy@naive on :<channel-d-public-port> Karing/NaiveProxy-style proof lane relayed into the same managed split; disabled by default No
anyT Production for issued client profiles Endpoint -> home router AnyTLS/TLS Eight protected client imports, shared selected-client split, scoped boot/firewall/process recovery No
M Regional service policy Selected applications Approved regional egress, isolated from client routing No
WireGuard Cold fallback only Manual emergency script Catastrophic Reality outage recovery No

The optional Amn compatibility lab retains a manually selected AmneziaWG ingress on the home router. It is disabled in steady state. The shared supervisor can restore it after boot when the operator enables recovery and its validated policy projection is current. Its eight named QR profiles use Channel Amn 01–08; existing bootstrap credentials are preserved. Architecture diagrams: English and Русский.

Channel anyT provides a separate home-first AnyTLS/TLS ingress with eight approved production QR profiles and automatic boot/firewall/process recovery. Issued imports are preserved during maintenance under the production compatibility contract. Its separate process applies the shared sensitive / managed / direct split; changing a router egress does not require new client QR codes. Shared deploy gates verify approved profiles/live settings and an authenticated anyT HTTPS request automatically; approved bundles reject routine re-export. Routing and lifecycle diagrams show these separate owners; the runbook defines recovery and verification.

Why This Exists

The project solves a narrow but real edge problem: keep ordinary home devices configuration-free, let mobile clients enter through the home network first, and preserve explicit routing control over which destinations use a remote VPS exit. The design favors boring operational boundaries over broad automation: Channel A owns the router data plane, Channel B is a separate selected-client production lane, Channel C is the home-first Naive/compatibility lane, Channel D is an experimental NaiveProxy lab lane, and none of them silently rewrites another channel.

Overview

GhostRoute is a layered routing setup for endpoint clients, a home ASUS Merlin router and a remote VPS egress. Home devices can stay configuration-free, while managed endpoint clients may also apply their own first-hop routing policy before traffic reaches the home router.

The layered model separates the main traffic responsibilities:

  • Layer 0 is endpoint/client-side routing. A client app or system VPN profile can decide DIRECT vs MANAGED/PROXY before traffic enters GhostRoute. For example, Shadowrocket on an iPhone/iPad/MacBook can use domain, IP, GEOIP and rule-list policy; it is a routing layer, not just a VPN toggle.
  • Layer 1 is the managed channel layer. Channel A, Channel B, Channel C and experimental Channel D are home-first: the first network sees endpoint -> home endpoint, not endpoint -> VPS. See docs/channels.md for the compact A/B/C/D handoff model. Channel C has C1-Shadowrocket HTTPS CONNECT compatibility for Shadowrocket and a C1-sing-box native Naive design that is waiting on an iOS client with Naive outbound support. Channel D is a disabled-by-default router-native Caddy forward_proxy@naive lab on :<channel-d-public-port>, relayed into the same managed split through channel-d-naiveproxy-socks-in. Channel M supports applications with regional egress requirements through an isolated service policy.
  • Layer 2 is the home router. It terminates home-based channels and applies the managed split with STEALTH_DOMAINS / VPN_STATIC_NETS, plus an optional Channel A selected full-VPS override for home Wi-Fi/LAN devices and Home Reality profiles that should send all internet-bound traffic through reality-out. A FORWARD guard drops direct LAN traffic to already classified managed IPv4 destinations if TCP REDIRECT is missing, and blocks managed UDP/443 during rule refresh. The router flow diagram shows the guard and channel boundaries. Router reboot recovery is centralized in ghostroute-runtime-supervisor.sh: services-start delegates to it, and it re-registers watchdog crons, restores listeners and performs delayed firewall stabilization after Merlin rebuilds chains. Channel M keeps its regional service policy independent of the managed split.
  • Layer 3 is the VPS. It acts as remote egress for selected managed traffic.

Production endpoint policy is intentionally country-neutral in this repository: local/private/captive and trusted domestic destinations go DIRECT; non-local, foreign, unknown or selected destinations go MANAGED/PROXY; FINAL points to MANAGED/PROXY in country-aware deployment profiles. The concrete country suffixes, GEOIP lists and service lists belong to private deployment profiles, not the general architecture.

Only Channel A is part of the automatic router data plane. Channel B is production for selected device-client profiles, has its own ingress/relay surface and must stay isolated from Channel A REDIRECT ownership. Channel C is home-first, separate from Channel A/B routing and has no automatic failover. Channel M supports applications with regional egress requirements through an isolated service policy.

The public Channel M policy and isolation contract is documented in docs/channel-m-environment.md.

Legacy WireGuard (wgs1 + wgc1) is decommissioned in normal operation. wgc1_* NVRAM remains only as a cold fallback.

If the router reports WAN carrier=0 or "network cable unplugged", that is a physical/provider WAN-link incident. It is not evidence that Channel A, Caddy/VPS, or the Reality data plane is broken.

Operator Router Access

  • Daily access from the operator Mac. Connect Tailscale and select the private router profile in the Mac's SSH configuration. The router admits SSH from that Mac's registered private IPv4 address. The Mac checks the pinned Dropbear host key and authenticates with its operator key.
  • Local recovery. On the home LAN or Wi-Fi, the private LAN profile reaches firmware SSH even when Tailscale or Entware is unavailable.
  • Remote recovery. ssh ghostroute-router forwards through hermes_vps. The independent ssh ghostroute-router-backup reaches a dedicated public listener on primary_vps without Tailscale. Both bastions can forward only to router SSH. The router admits only the approved fixed sources on its WAN interface. Test the backup from the external network where it will be needed.

Router SSH paths, the Console report key and the private syslog archive

Console uses a separate service key that the router restricts to reading reports. Merlin sends system events over Tailscale to a private VPS archive. Router access, log review and recovery · Console key restrictions

For deploy.sh, ./verify.sh and health reports, the shared helper uses ROUTER_ACCESS_MODE=auto. It selects direct SSH when the control machine has a physical LAN route. Otherwise it tries the configured remote endpoint from secrets/router.env with bastion settings from secrets/router-management.env. If the remote SSH preflight fails, it tries the LAN fallback. The interactive Tailscale alias is selected explicitly.


Key Features

  • Domain-based routing with dnsmasq + ipset.
  • Single active domain catalog for home LAN (STEALTH_DOMAINS).
  • Shared static CIDR catalog for direct-IP services via VPN_STATIC_NETS.
  • Optional Layer 0 endpoint/client-side routing for devices that support rule-based client profiles such as Shadowrocket-style configs.
  • Channel A managed egress through the stable reality-out tag with three operator-selectable mnemonic backends: primary_vps, backup_reality and hermes_vps. The route contract stays fixed; only the backend behind the role swaps. Public docs must not map those roles to real providers, endpoints or host families.
  • Optional Channel A selected full-VPS sets for home LAN/Wi-Fi devices and Home Reality profiles that should send all internet-bound traffic through reality-out, while non-selected devices keep the managed-domain split. This is a Channel A policy override, not Channel B/C failover.
  • Channel B selected-client production home-first lane: selected devices connect to the home router first via XHTTP/TLS, then the router relays into local sing-box SOCKS and reuses the active managed reality-out upstream.
  • Channel C home-first lane: C1-Shadowrocket uses authenticated HTTPS CONNECT/TLS for Shadowrocket compatibility and is live-proven. C1-sing-box uses sing-box Naive on the home endpoint as the native design, but current SFI 1.11.4 rejects outbound type: naive. Both router-side paths apply the same managed split and selected Reality upstream.
  • Channel D experimental NaiveProxy lab: selected Karing/NaiveProxy-style clients connect to router-native Caddy forward_proxy@naive on home TCP/. Caddy relays into local sing-box SOCKS channel-d-naiveproxy-socks-in, where managed destinations use reality-out and non-managed traffic uses direct-out. The server build pins klzgrad/forwardproxy; the current live client proof is Karing-only, with a Karing fingerprint limit and a neutral cover site for ordinary unauthenticated HTTPS GET probes. It is disabled by default and is not Channel C proof.
  • Channel M supports applications with regional egress requirements through an isolated service policy.
  • Router-side VLESS+Reality ingress on TCP/ for remote clients, so the first network sees the home endpoint instead of the VPS endpoint.
  • Stable router-side sing-box TCP REDIRECT instead of unstable Merlin TUN routing.
  • Automatic domain discovery that writes STEALTH_DOMAINS only.
  • Local QR/VLESS profile generation from Ansible Vault.
  • Health, traffic and catalog reports suitable for humans and LLM handoff.
  • Local GhostRoute health monitor with router-side STATUS_OK / STATUS_FAIL, summary-latest.md, and internal alert ledgers on router storage.
  • Read-only GhostRoute Console with full desktop workbenches and compact mobile /m pages over prepared route, traffic, client, health, live and catalog evidence.

Switching the managed egress backend

One local operator helper selects which backend serves the shared reality-out upstream for Channel A/B/C. It edits only the Vault selector, saves an encrypted backup, and optionally redeploys the router:

./modules/routing-core/bin/managed-egress-mode status
./modules/routing-core/bin/managed-egress-mode set hermes_vps --deploy-router
./modules/ghostroute-health-monitor/bin/managed-egress-check
./modules/ghostroute-health-monitor/bin/egress-backend-health

Valid modes are primary_vps, backup_reality and hermes_vps. The switch changes only the upstream managed egress, never client QR/VLESS artifacts, ingress ports or managed catalogs. Channel D follows this shared backend by default but can be pinned to its own backend behind reality-out-d with set <mode> --channel d (canary lane); Channel M is never affected. See docs/managed-egress-failover-roadmap.md for the full procedure and recovery checks.

Backends marked quarantined: in the backend bank are excluded from set and listed separately by status. Revalidate the affected application operation before removing quarantine; a green TCP or web probe is insufficient for media. After revalidation, rerun both application canaries and the affected client transfer. Backend availability is not a permanent guarantee; keep a verified rollback role. An active Amn lab must be explicitly refreshed after changing the production policy, because it holds an isolated policy copy.

Public documentation and commits refer to managed egresses only by mnemonic roles. The real provider, endpoint, ASN, host family, account and role mapping belong in Vault or gitignored operator notes.

Sensitive sites mode optionally sends Claude/Anthropic, OpenAI/ChatGPT and selected Google AI destinations through sensitive-out (hermes_vps by default, or an explicitly qualified backup_reality recovery selection), while other managed destinations retain their current backend. The separate domain catalog and vault_router_sensitive_sites_enabled switch do not change client imports. There is no direct fallback. Automatic backend changes require the explicitly enabled cold emergency pair; an independently pinned sensitive profile is not silently moved. See the mode contract and limitations. An experimental vault_router_sensitive_telegram_enabled extension sends Telegram domains and its reviewed native IPv4 ranges through the same sensitive backend. It requires the base mode, preserves other managed destinations and excludes M; the mode runbook covers review windows, verification and manual rollback. It requires observation on real clients before promotion to a permanent policy.

Router storage modes

The protocol/component matrix separates each channel's client ingress from its shared managed VPS egress.

Dropbear and its persistent access rules live in firmware and JFFS. The private SSH route also needs the Entware Tailscale service. Check the LAN recovery profile before removing the Entware volume. Router access guide

The main mode keeps Entware programs and /opt/etc on writable USB/ext4, router-owned hooks/configuration in JFFS, and volatile runtime in RAM. Optional temporary read-only recovery restores selected writable paths into RAM from a private JFFS seed while binaries remain on readable USB. Sensitive sites mode works with either storage layout. See the storage ownership table and temporary-mode runbook.


Operational Modules

GhostRoute is organized as a small operational platform around the routing core, not just a set of firewall scripts:

  • GhostRoute Guard for Mac — native SwiftUI and popup controls with automatic qualified proxy routing for ordinary Chrome's sensitive catalog, the Mac network for other sites, optional external PAC compatibility, and an optional protected Chrome profile with a qualified proxy-only gate, and an in-memory journal receiving gateway decisions and ordinary Chrome blocker events. The app also controls the Chrome agent and explicit per-tab HTTP diagnostics, with built-in help and bounded temporary response previews. See the module and installation guide. User guide · Tests and acceptance. Visual guide: Chrome routing, components and access states.
  • Routing Core — the production data plane: dnsmasq/ipset classification, sing-box REDIRECT, selected full-VPS TPROXY, home Reality ingress, managed Reality egress to VPS, direct-out fallback for non-selected non-managed traffic, and WireGuard cold fallback.
  • GhostRoute Health Monitor — a read-only reliability module for the router + VPS setup. It produces local STATUS_OK / STATUS_FAIL sentinels, status.json, Markdown summaries, daily digests and disk-based alert ledgers without changing production routing state. It also owns the live deploy gate and deploy-risk path classifier used to decide when the full A/B/C + DNS + VPS canary is required for a change set.
  • Traffic Observatory — usage and routing reports for WAN, LAN/Wi-Fi, Home Reality QR clients, popular destinations and split-routing mistakes. It is designed for day-to-day inspection and safe LLM handoff with redacted device labels by default.
  • GhostRoute Console — a read-only web Console over prepared route, traffic, client, health, live and catalog evidence. It renders full desktop workbenches plus compact mobile /m triage pages, while remaining a read-model consumer rather than a router/VPS runtime owner. See modules/ghostroute-console/README.md and docs/ghostroute-console-architecture.md.
  • DNS & Catalog Intelligence — DNS lookup observation, domain discovery and managed-catalog maintenance. It helps identify which domains a service uses, keeps manual and auto-discovered rules separated, and feeds STEALTH_DOMAINS / VPN_STATIC_NETS without requiring VPN apps on home devices.
  • Routing Policy Principles — the compact contract for endpoint policy, channel ingress, router managed split and VPS/home egress decisions. See docs/routing-policy-principles.md.
  • DNS Policy — channel proof guidance for DNS leak vs resolver fingerprint: the primary goal is no DNS leakage to the mobile operator; resolver geography shown by BrowserLeaks is a secondary consistency signal. See docs/dns-policy.md.
  • Performance Diagnostics Toolkit — checks and documentation for latency, retransmits, TCP tuning, MSS clamp, keepalive behavior and LTE/Home Reality performance symptoms, so speed issues can be diagnosed separately from routing correctness.
  • SNI Rotation Guide for Reality - operational guidance for validating, rotating and documenting Reality cover SNI choices, including client behavior, regional reachability and rollback considerations.
  • Client Profile Factory — local generation and cleanup of QR/VLESS profiles from Ansible Vault, including separate router, home-mobile, emergency, Channel B and Channel C artifact flows. Generated credentials stay outside git.
  • Secrets Management — Ansible Vault templates, local secret storage rules, generated-artifact isolation and a repo-specific secret-scan for catching real URIs, UUIDs, keys, public endpoints and production literals before push.
  • Recovery & Verification Toolkit — verify.sh, Ansible verification, incident runbooks and explicit cold-fallback scripts for controlled manual recovery when Reality, VPS, DNS or routing invariants drift.

Together these modules make the repo auditable: routing, health, traffic, performance and recovery procedures are documented as separate operational surfaces with clear read-only diagnostics and explicit manual recovery steps. See the full module map in docs/operational-modules.md. For a compact channel handoff, see docs/channels.md.


Architecture At A Glance

flowchart LR
  LAN[Home LAN / Wi-Fi]
  RC[Remote clients A/B/C/D/anyT]
  LAN --> ROUTER
  RC --> ROUTER
  ROUTER{{ASUS Merlin: main and isolated anyT policy processes}}
  ROUTER -. sensitive mode: matching destinations first .-> SENSITIVE[sensitive-out / hermes_vps]
  ROUTER -->|managed: STEALTH_DOMAINS / VPN_STATIC_NETS| RO[reality-out]
  ROUTER -->|non-managed| DIRECT[direct-out via home WAN]
  RO --> ACTIVE{active managed egress}
  ACTIVE --> PRIMARY[primary_vps]
  ACTIVE --> BACKUP[backup_reality]
  ACTIVE --> HERMES[hermes_vps]
  ROUTER -. Channel D canary pin .-> ROD[reality-out-d] --> ACTIVE
Loading

The text map below shows the same flow in full detail (placeholders for ports):

                         Control machine
                deploy.sh / Ansible / reports / vault
                              |
                              v
Layer 0 endpoint/client routing
  local/private/captive/trusted domestic -> DIRECT
  foreign/non-local/unknown/selected     -> MANAGED/PROXY
  FINAL                                  -> MANAGED/PROXY
                  |
                  v
Layer 1 managed channels
  Channel A -> endpoint -> home endpoint :<home-reality-port>
            -> ASUS sing-box Reality inbound
  Channel B -> endpoint -> VLESS+XHTTP+TLS -> home endpoint :<home-channel-b-port>
            -> router local Xray XHTTP/TLS ingress
  Channel C -> endpoint -> Naive/HTTPS-H2-CONNECT-like
            -> home endpoint :<home-channel-c-public-port>
            -> router sing-box Naive ingress
  Channel D -> Karing/Naive -> home endpoint :<channel-d-public-port>
            -> router Caddy forward_proxy@naive
            -> sing-box channel-d-naiveproxy-socks-in
  Channel anyT -> AnyTLS/TLS -> home endpoint :<anyt-port>
               -> separate sing-box-atls -> sensitive / managed / direct
  Channel M -> isolated service policy -> approved regional egress
Layer 2 home router
  services-start -> ghostroute-runtime-supervisor.sh boot
       prepare runtime -> sing-box -> firewall/stealth rules
       -> dnscrypt -> Channel B/D/M -> delayed firewall stabilization
       -> enabled anyT: own reconcile / firewall hook / minute cron

  Home Wi-Fi/LAN DNS -> dnsmasq + ipset
                              |
                              +-- managed DNS lookup
                              |     dnsmasq server=/managed/127.0.0.1#<dnscrypt-port>
                              |     -> dnscrypt-proxy -> sing-box SOCKS
                              |     -> reality-out -> dnscrypt upstream
                              |
                              +-- selected full-VPS override
                              |     reserved source IP / Home Reality auth_user
                              |     -> TPROXY or reality-in rule
                              |     -> reality-out -> active managed egress -> Internet
                              |
                              +-- managed match
                              |     STEALTH_DOMAINS / VPN_STATIC_NETS
                              |     -> sing-box REDIRECT / reality-in
                              |     -> VLESS+Reality outbound
                              |     -> active managed egress -> Internet
                              |
                              +-- non-managed match
                                    -> direct-out -> home WAN -> Internet

  Channel M -> isolated service policy -> approved regional egress

Layer 3 VPS
  remote egress for managed traffic and selected full-VPS traffic
  sites see VPS IP for managed and selected full-VPS traffic

Operational layer:
  Routing Core        -> dnsmasq/ipset/sing-box/Reality split
  Runtime Supervisor  -> reboot recovery, watchdog crons, firewall stabilization
  Health Monitor      -> STATUS_OK/FAIL, summaries, local alerts
  Traffic Observatory -> WAN/LAN/Home Reality usage and routing checks
  DNS Intelligence    -> lookup evidence, domain discovery, catalog review
  Performance Toolkit -> RTT/retransmit/TCP/MSS diagnostics
  SNI Rotation Guide  -> Reality cover validation, rotation, rollback
  Client Profiles     -> QR/VLESS, selected-client B/C/D artifacts from Vault
  anyT Profiles       -> eight preserved private imports; Routing Core owns export
  Secrets Management  -> vault, generated artifacts, secret-scan
  Recovery Toolkit    -> verify.sh, Ansible verify, runbooks, cold fallback

How It Works

1. Home Wi-Fi / LAN Devices

Home Wi-Fi / LAN devices
      |
      +-- DNS query
      |     |
      |     v
      |  dnsmasq
      |  +-- managed domain -> STEALTH_DOMAINS
      |  +-- static network -> VPN_STATIC_NETS
      |  +-- other domain   -> normal DNS path
      |
      +-- TCP connection to matched IP
            |
            v
      ASUS Router / Merlin
      +-- nat REDIRECT :<lan-redirect-port>
      +-- sing-box redirect inbound
      +-- VLESS+Reality TCP/443
            |
            v
      VPS host
      +-- shared Caddy :443
      +-- Xray Reality inbound
            |
            v
      Internet

Home devices do not need VPN apps. The router sees DNS answers, fills STEALTH_DOMAINS, redirects matching TCP traffic into sing-box, and sends it through Reality. UDP/443 for managed destinations is silently dropped so apps fall back from QUIC to TCP.

Selected home Wi-Fi/LAN devices can instead use Channel A selected full-VPS mode. Those devices are matched by reserved source IP, captured with TPROXY, and sent to channel-a-selected-lan-full-vps-in -> reality-out; local/private traffic remains local. Plain DNS :53 from those selected devices is also captured and destination-overridden to the strict resolver before it exits through reality-out. Non-selected home devices keep the managed-domain split.

2. Endpoint / Client-Side Routing

Endpoint device
  -> optional client-side rules
       local/private/captive/trusted domestic -> DIRECT
       foreign/non-local/unknown/selected     -> MANAGED/PROXY
       FINAL                                  -> MANAGED/PROXY
  -> selected managed channel

Layer 0 can exist on any endpoint that supports rule-based routing. Shadowrocket on iPhone/iPad/MacBook is the primary example today: a config file can choose DIRECT or PROXY/MANAGED by domain, IP, GEOIP or rule list before traffic reaches Channel A/B/C. Devices without Layer 0 policy can still rely on the router-managed split at Layer 2.

3. Remote QR / VLESS Clients

Endpoint outside home
      |
      v
Client app imports generated QR profile
      |
      v
Home public IP :<home-reality-port>
      |
      v
ASUS Router / Merlin
+-- sing-box home Reality inbound
+-- managed destination
|     +-- STEALTH_DOMAINS / VPN_STATIC_NETS
|     +-- sing-box Reality outbound
|     +-- active managed egress
|     +-- Internet
+-- selected full-VPS Home Reality profile
|     +-- auth_user rule before managed split
|     +-- private destinations direct
|     +-- other internet destinations -> active managed egress
+-- non-managed destination
      +-- sing-box direct outbound
      +-- home WAN
      +-- Internet

For Channel A/B managed traffic, the first network sees the endpoint connecting to the home endpoint, not directly to the active managed egress. The home ISP sees the home router connecting to the active managed egress. Managed websites/checkers see that active managed exit; non-managed websites see the home WAN IP unless the Home Reality profile is explicitly selected for Channel A full-VPS mode.

Detailed workflow, ports, components and observer model: modules/routing-core/docs/network-flow-and-observer-model.md.

4. Cold Fallback

WireGuard is not active in steady state. The preserved wgc1_* NVRAM can be used only with modules/recovery-verification/router/emergency-enable-wgc1.sh during a catastrophic Reality outage.

5. Channel B/C Device Profiles

Channel B, Channel C and Channel D are device-client lanes with different client surfaces:

  • Channel B is production for selected device-client profiles. It is home-first: selected devices connect to dedicated home ingress on :<home-channel-b-port>. A local Xray process terminates that first hop and forwards traffic into local sing-box SOCKS, so the second hop reuses the same existing selected Reality upstream to VPS as Channel A.
  • Channel C is the home-first Naive/compatibility lane. C1-sing-box is the router-side native Naive design, but the tested iPhone SFI app used sing-box 1.11.4 and rejected outbound type: naive; generated SFI native profiles are disabled by default until the selected iPhone client supports Naive outbound. C1-Shadowrocket devices use HTTPS CONNECT/TLS and terminate at channel-c-shadowrocket-http-in. Both router-side paths apply the same managed split as the other home-first lanes.
  • Channel D is the experimental router-native NaiveProxy lab. It runs a separate Caddy forward_proxy@naive runtime on the router and relays accepted clients into sing-box channel-d-naiveproxy-socks-in for the same STEALTH_DOMAINS / VPN_STATIC_NETS split. It is disabled by default and is removable with playbooks/24-channel-d-router.yml.

Channel B isolation boundaries are strict: it has its own ingress port and local Xray relay process, but it does not mutate Channel A REDIRECT ownership, router DNS, TUN state or automatic failover. Treat generated ansible/out/clients-channel-b/ artifacts as selected-client production credentials and generated ansible/out/clients-channel-c/ artifacts as selected-client Channel C artifacts. Shadowrocket compatibility is not proof of native Naive; see docs/channels.md and docs/channel-c.md. Treat generated ansible/out/clients-channel-d/ artifacts as experimental Channel D credentials; see docs/channel-d.md.

6. Channel M — Regional Service Policy

Channel M supports applications with regional egress requirements through an isolated service policy.

Technical Stack

Router:
  ASUS RT-AX88U Pro + Asuswrt-Merlin
  dnsmasq + ipset + iptables
  sing-box REDIRECT inbound on :<lan-redirect-port>
  optional Channel A selected full-VPS TPROXY inbound on :<full-vps-tproxy-port>
  sing-box home Reality inbound on :<home-reality-port>
  optional Channel B home XHTTP/TLS ingress on :<home-channel-b-port>
  optional Channel B local Xray relay to sing-box SOCKS on 127.0.0.1:<router-socks-port>
  optional Channel C1 Naive ingress on :<home-channel-c-ingress-port>
  optional Channel M service policy (operator-owned)
  policy DNS split via dnsmasq + dnscrypt-proxy over sing-box SOCKS/Reality
  dnscrypt listener watchdog on /jffs/scripts/dnscrypt-watchdog.sh
  sing-box vps-dns-in remains for DNS hijack compatibility
  Legacy WireGuard disabled; wgc1 NVRAM preserved for cold fallback

VPS:
  VPS Ubuntu host
  shared system Caddy with layer4 plugin on :443
  existing 3x-ui/Xray Docker container behind Caddy
  Xray/3x-ui Reality inbound on 127.0.0.1:<xray-local-port>
  optional restricted/private DNS resolver support:
    - 127.0.0.1 for host checks
    - Docker bridge / configured private target when enabled
    - host firewall allows restricted DNS only from trusted private sources
  public TCP/443 must be allowed by provider and host firewalls for Reality/Caddy
  public TCP/UDP 53 must stay denied
  optional direct-mode Channel B Xray XHTTP on 127.0.0.1:<xhttp-local-port>
  stealth stack under /opt/stealth

Control:
  deploy.sh for router base runtime files/catalogs
  Ansible for VPS, router stealth layer, verification and QR generation
  ansible-vault for real credentials and client parameters

Project Structure

configs/
  dnsmasq-stealth.conf.add        # STEALTH_DOMAINS for home LAN Channel A
  static-networks.txt             # shared CIDR catalog

ansible/
  README.md                       # Ansible control plane overview
  playbooks/10-stealth-vps.yml
  playbooks/11-channel-b-vps.yml
  playbooks/20-stealth-router.yml
  playbooks/21-channel-b-router.yml
  playbooks/22-channel-c-router.yml
  playbooks/30-generate-client-profiles.yml
  playbooks/99-verify.yml
  secrets/stealth.yml             # ansible-vault, gitignored
  out/clients/                    # generated QR/profile artifacts, gitignored
  out/clients-home/               # generated home QR/profile artifacts, gitignored
  out/clients-emergency/          # generated emergency artifacts, gitignored
  out/clients-channel-b/          # generated Channel B artifacts, gitignored
  out/clients-channel-c/          # generated Channel C artifacts, gitignored
  out/clients-channel-d/          # generated Channel D NaiveProxy lab artifacts, gitignored
  out/channel-d-naiveproxy/       # locally built Channel D Caddy binary, gitignored
  out/<service-egress>/           # private service artifacts, gitignored

modules/
  routing-core/
  ghostroute-health-monitor/
  traffic-observatory/
  ghostroute-console/
  dns-catalog-intelligence/
  performance-diagnostics/
  reality-sni-rotation/
  client-profile-factory/
  secrets-management/
  recovery-verification/

scripts/
  README.md                       # reserved for future cross-repo utilities

docs/
  architecture.md
  operational-modules.md
  getting-started.md
  troubleshooting.md
  future-improvements-backlog.md

The detailed physical module map lives in docs/operational-modules.md. The global README keeps the high-level workflow; module folders contain local implementation overviews. The Ansible router/VPS deployment component map lives in ansible/README.md.

Repository conventions

A few intentional artifacts that a first-time reader may wonder about:

  • AGENTS.md, CLAUDE.md, LEAN-CTX.md are agent-workflow configuration — shared instructions for coding agents (Codex, Claude Code) so they inherit the same durable project rules. They document how this repo is maintained, not product behavior.
  • docs/repo-review-*.md are a rolling contributor review gate referenced by CONTRIBUTING.md; the newest one is the active gate.
  • docs/vpn-domain-journal.md is an operational data artifact read by catalog/health tooling, not a freeform note.
  • Generated artifacts (ansible/out/, reports/, docs/private/) and real secrets are gitignored; tracked docs use placeholders and mnemonic roles only.

The presentation roadmap for this repository lives in docs/repo-presentation-roadmap.md.


Quick Start

# Base router deploy through the active router access profile.
# Remote operators should prepare gitignored secrets/router.env first.
./deploy.sh

# Home-LAN-only one-off override:
# ROUTER=<router_lan_ip> ./deploy.sh

# Channel A router layer: sing-box, dnscrypt-proxy, reboot-safe REDIRECT/full-VPS routing
cd ansible
ansible-playbook playbooks/20-stealth-router.yml

# Channel B selected-client home-first add-on on router
ansible-playbook playbooks/21-channel-b-router.yml

# Optional direct mode for B
ansible-playbook playbooks/11-channel-b-vps.yml

# Channel C1 selected-client home-first add-on on router
ansible-playbook playbooks/22-channel-c-router.yml

# Optional Channel D router-native NaiveProxy lab on router
../modules/routing-core/bin/build-channel-d-caddy
ansible-playbook playbooks/24-channel-d-router.yml

# End-to-end verification: VPS + router
ansible-playbook playbooks/99-verify.yml
cd ..

# Local health snapshot
./verify.sh
./modules/ghostroute-health-monitor/bin/router-health-report

Mutating deploy entrypoints run a shared pre/post canary gate:

./modules/ghostroute-health-monitor/bin/live-check --active-probe --deploy-gate

The gate normally takes 40-90 seconds. It checks the existing Wi-Fi managed domain path, VPS TCP/443 edge, public DNS 53 exposure, managed/direct DNS split, cover SNI and Channel A/B/C runtime chain before deploy is allowed to mutate files or restart services. Bypass is explicit and should be reserved for emergency recovery: GHOSTROUTE_SKIP_DEPLOY_GATE=1 ./deploy.sh or ansible-playbook ... -e ghostroute_skip_deploy_gate=true.

20-stealth-router.yml also installs the Channel A reboot hooks, selected full-VPS TPROXY/dnsmasq policy when enabled, and catalog scripts (firewall-start, cron-save-ipset, domain-auto-add.sh, update-blocked-list.sh) so REDIRECT, selected full-VPS rules and the accumulated STEALTH_DOMAINS state survive router reboots and Merlin firewall rebuilds.

21-channel-b-router.yml is the Channel B add-on: dedicated home XHTTP ingress plus local router relay into sing-box Reality upstream, without taking over Channel A REDIRECT routing.

Traffic and observability:

# Lightweight Dashboard source: current-day counter summary without destination
# analytics or routing mistake checks.
./modules/traffic-observatory/bin/traffic-summary --json today

# Machine contract for Console accounting: traffic-evidence -> traffic-facts v3.
./modules/traffic-observatory/bin/traffic-evidence --json today
./modules/traffic-observatory/bin/traffic-facts --json today

# Main usage report: exits, devices, Home Reality ingress clients,
# popular destinations and routing mistake checks.
./modules/traffic-observatory/bin/traffic-report today
./modules/traffic-observatory/bin/traffic-report yesterday
./modules/traffic-observatory/bin/traffic-report week
./modules/traffic-observatory/bin/traffic-report month

# Human/LLM-safe operational snapshot.
./modules/ghostroute-health-monitor/bin/router-health-report

The lightweight summary is the preferred source for frequent Console Dashboard traffic cards. Console machine accounting reads traffic-facts v3 from raw traffic-evidence; traffic-report remains the operator/debug report for how much went through the VPS, how much stayed on the home WAN, which devices and Home Reality ingress clients were active, and whether likely routing mistakes appeared. See modules/traffic-observatory/docs/traffic-observability.md. Traffic interpretation is a separate local layer: traffic_facts keeps bytes, DNS/route evidence and accounting status, while Traffic Intelligence writes labels, explanations and dry-run decision candidates for the Console /intelligence review surface. It does not change routing, blocking, managed domains or accounting. Home Reality profile bytes enter the trusted pipeline only when the ingress counter is profile-labelled (home_reality_samples -> Home Reality ingress or sing-box destination facts). Unprofiled remote:* ingress counters are kept as diagnostics and are not counted as client-observed traffic; Console does not revive legacy estimated Apple/iCloud-style per-destination allocations without real DNS/flow evidence.

Health monitor:

# Install/update with deploy.sh or ansible, then run a local router-side sample.
ssh admin@<router_lan_ip> '/jffs/scripts/health-monitor/run-once'

# Primary storage on the router:
ssh admin@<router_lan_ip> 'cat /opt/var/log/router_configuration/health-monitor/summary-latest.md'
ssh admin@<router_lan_ip> 'cat /opt/var/log/router_configuration/health-monitor/alerts/$(date +%F).md'
ssh admin@<router_lan_ip> 'cat /opt/var/log/router_configuration/health-monitor/status.json'

# Unified router+VPS report from the control machine.
./modules/ghostroute-health-monitor/bin/ghostroute-health-report
./modules/ghostroute-health-monitor/bin/ghostroute-health-report --save

The health monitor is read-only for production routing state. It writes local internal alerts and reports to router storage only. Primary path: /opt/var/log/router_configuration/health-monitor; fallback: /jffs/addons/router_configuration/health-monitor. Scheduled collection runs hourly; use /jffs/scripts/health-monitor/run-once for an immediate fresh snapshot. The VPS observer keeps its own local-only status on the VPS under /var/log/ghostroute/health-monitor. ghostroute-health-report --save stores merged latest/history reports on the router under health-monitor/global/ and keeps 31 days of history.

How to read a router-side alert:

  1. Check STATUS_OK / STATUS_FAIL.
  2. Read summary-latest.md.
  3. Read alerts/<today>.md.
  4. Use raw/<today>.jsonl only for exact evidence.
  5. After manual recovery, run run-once or wait for the next hourly cycle and confirm STATUS_OK; do not delete alert history.

Expected invariants:

  • LAN TCP for STEALTH_DOMAINS and VPN_STATIC_NETS is redirected to :<lan-redirect-port>.
  • LAN UDP/443 for those sets is silently dropped to force TCP fallback.
  • Remote QR/VLESS clients connect to the home public IP on :<home-reality-port>, not directly to VPS.
  • Router-side sing-box accepts reality-in on 0.0.0.0:<home-reality-port>.
  • Non-selected mobile profiles keep the managed split: managed destinations route to reality-out, and non-managed destinations route to direct-out. Selected Channel A full-VPS profiles route private destinations direct and other internet-bound traffic to reality-out.
  • Plain DNS from Wi-Fi/LAN and mobile Channels A/B/C reaches router dnsmasq.
  • Managed/foreign DNS goes through dnsmasq -> dnscrypt-proxy -> sing-box SOCKS -> reality-out; RU/direct/default DNS stays on the home/RF/default resolver path. Router vps-dns-in remains for DNS hijack compatibility, but it is no longer the generated managed-domain forward target.
  • dnscrypt-proxy is a load-bearing router-local dependency for managed DNS. If 127.0.0.1:<dnscrypt-port> disappears, LAN/Wi-Fi managed domains and home-first mobile Channels A/B/C/D can fail together even when listeners and iptables still look healthy. Channel M keeps a separate service policy and does not use the managed DNS split. /jffs/scripts/dnscrypt-watchdog.sh monitors that listener every minute and restarts only dnscrypt-proxy. The dnscrypt init path and GhostRoute runtime supervisor also set vm.overcommit_memory=1 before startup so Entware's Go dnscrypt-proxy2 can reserve its runtime heap after router reboot. services-start delegates boot recovery to the runtime supervisor instead of owning per-channel start blocks.
  • Optional VPS restricted DNS, when enabled, is not public: host firewall allows it only from trusted private sources, while public 53/tcp,udp is denied.
  • STEALTH_DOMAINS and VPN_STATIC_NETS exist.
  • VPN_DOMAINS, RC_VPN_ROUTE, 0x1000, active wgs1 and active wgc1 are absent.

Client QR Profiles

Client profiles are generated locally from Ansible Vault:

./modules/client-profile-factory/bin/client-profiles generate
./modules/client-profile-factory/bin/client-profiles open

Generated files live under ansible/out/clients/, including iphone-*.png, macbook.png, matching .conf files and a local qr-index.html gallery.

The router.conf profile still targets the VPS directly because it is the router's outbound identity. iphone-* and macbook profiles target the home public IP first.

Never commit or paste real VLESS URIs, UUIDs, Reality keys, short IDs, admin paths or QR payloads into documentation. Use fake placeholders only.

See modules/client-profile-factory/docs/client-profiles.md and modules/secrets-management/docs/secrets-management.md.


Demo

The repo-only checks do not require router access, Vault access or generated client artifacts:

$ ./modules/secrets-management/bin/secret-scan
secret-scan: ok

$ ./tests/run-all.sh
router-health fixture smoke tests passed
catalog-review fixture smoke tests passed
dns-forensics fixture smoke tests passed
health-monitor fixture tests passed
vps-health-monitor fixture tests passed
module entrypoint tests passed
channel-a deploy static tests passed
channel-b/c static tests passed
audit-fixes tests passed
all fixture tests passed

When the router and VPS are reachable, the live operator flow adds read-only verification and sanitized reports:

./verify.sh --verbose
cd ansible && ansible-playbook playbooks/99-verify.yml
cd ..
./modules/ghostroute-health-monitor/bin/router-health-report
./modules/traffic-observatory/bin/traffic-report check
./modules/traffic-observatory/bin/traffic-report today

Expected live evidence: Channel A router invariants are green, Channel B selected-client traffic reaches the home ingress and uses the managed split, and Channel C traffic reaches either channel-c-naive-in for C1-sing-box or channel-c-shadowrocket-http-in for Shadowrocket compatibility before using the same managed split.

Sanitized live sample from the home network:

router-health-report:
  Result: OK
  Drift items: 0
  STEALTH catalog usage: 882/65536 (1.3%)
  Channel A REDIRECT listener: OK
  Home Reality listener: OK
  Home Reality managed split: OK

ansible-playbook playbooks/99-verify.yml -e verify_openclaw_checks_enabled=false:
  stealth-vps: ok=11 failed=0
  router-home: ok=41 failed=0
  Channel B home relay config: OK
  sing-box Channel B relay SOCKS inbound: OK

traffic-report today:
  Client observed total: 9.35 GiB
  Via VPS: 8.78 GiB (93.9% observed)
  Via home RU direct: 581.5 MiB (6.1% observed)
  Home Reality connections: 36817
  Home Reality unresolved: 0
  Channel B ingress: 0 B observed in this sample window

Architecture Decisions

GhostRoute uses concise ADRs for decisions that affect routing behavior, runtime layout, secret handling, public command structure and monitoring contracts.

ADR Decision
0001 Keep the repository module-native rather than script-bucket oriented.
0002 Reserve scripts/ for future cross-module utilities.
0003 Keep health alerts local and read-only by default.
0004 Preserve WireGuard only as an explicit cold fallback.
0005 Keep real credentials and generated artifacts outside git.
0006 Define initial channel terminology and no automatic B/C failover.
0007 Record current B/C channel maturity.
0008 Record Channel C live compatibility and native Naive blocker.
0009 Keep managed DNS on dnscrypt-backed forwarding; public VPS 443 open for Reality, public DNS 53 closed.
0010 Add Channel A selected full-VPS override for selected home Wi-Fi/LAN devices and Home Reality profiles.

See docs/adr/ for the full index and when to add a new record.


Security Considerations

The public repo intentionally contains implementation logic, placeholders and sanitized examples only. Real endpoints, listener ports, UUIDs, keys, QR payloads, admin paths and generated profiles stay in Vault or gitignored local directories. See SECURITY.md and modules/secrets-management/docs/secrets-management.md.


Detailed Documentation


License

MIT - Copyright (c) 2025 Denis Ermilov

About

Home-first managed routing for ASUS Merlin: sing-box + dnsmasq/ipset split routing, Reality/Vision egress, XHTTP/Naive/Karing client lanes, health and traffic observability.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

8 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages