sh2/d2ypp2/docs/wg-easy-operations.md
eric 0517be0ce2 Harden deploy for WireGuard ShellCrash access and multi-arch installs.
Allow trusted CIDRs (Docker/LAN/10.88.0.0/24) past ShellCrash WAN reject so the dashboard works over WG, unify CPU arch detection for amd64/arm64/armv7, and document install-time LIVE_HTTP_PROXY plus Neko NAT1TO1 fallbacks.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-31 03:22:22 -05:00

4.2 KiB
Raw Permalink Blame History

wg-easy / WireGuard 组网运维记录

本文档记录无人直播栈当前采用的 WireGuard 中继方案,以及和 Neko、ShellCrash、Windows Mihomo/TUN 共存时的固定处理方式。

当前拓扑

  • 腾讯云 VPS:129.204.21.129,作为中国方向 WireGuard 中继。
  • WireGuard 端口:51820/udp,云防火墙和系统防火墙都需要放行。
  • Neko 主机:10.88.0.2。
  • Windows 客户端:10.88.0.6/32。
  • Neko Web:http://10.88.0.2:9201/,本地 LAN 和 WireGuard 网络都应能访问。

腾讯云仅负责中继内网段流量,不承载 ShellCrash 代理。Neko 容器内访问 Google/YouTube 仍走 Neko 主机上的 ShellCrash HTTP 代理。

2026-06-02 生产校验

  • wandaA:wgeasy 使用 Endpoint = 129.204.21.129:51820,Address = 10.88.0.4/32,MTU = 1360,PersistentKeepalive = 25。
  • wandaB:wgeasy 使用 Endpoint = 129.204.21.129:51820,Address = 10.88.0.2/32;到 10.88.0.1 的延迟约 25ms。
  • Neko 访问优先级:WireGuard 10.88.0.0/24 优先,frp 公网端口兜底,EasyTier 10.126.126.0/24 作为备用运维链路。

ShellCrash dashboard over WireGuard

ShellCrash firewall_area=1 rejects WAN access to 7890 / 9999 after accepting only the physical LAN. WireGuard peers (10.88.0.0/24) must be added to the trusted accept set or the UI shows “online” locally but http://10.88.0.x:9999/ui/ fails from remote.

See docs/deploy-hardening.md for SHELLCRASH_TRUSTED_CIDRS / shellcrash-allow-trusted.sh.

推荐参数

WireGuard peer 推荐:

MTU = 1360
PersistentKeepalive = 25
Endpoint = 129.204.21.129:51820

VPS 内核和链路优化:

sysctl -w net.core.default_qdisc=fq
sysctl -w net.ipv4.tcp_congestion_control=bbr
sysctl -w net.core.rmem_max=2500000
sysctl -w net.core.wmem_max=2500000
iptables -t mangle -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu

Windows 与 Mihomo/TUN 共存

如果 Windows 上有 Mihomo、Clash、ShellCrash TUN 抢默认路由,WireGuard 的 VPS Endpoint 可能被送进代理出口,导致绕路和高延迟。必须给 VPS 公网 IP 加一条物理网关旁路路由:

route -p add 129.204.21.129 mask 255.255.255.255 192.168.2.1 metric 1 if 21

参数说明:

  • 129.204.21.129:WireGuard VPS Endpoint。
  • 192.168.2.1:Windows 当前物理局域网网关。
  • if 21:Windows 物理网卡 ifIndex,用 Get-NetIPInterface -AddressFamily IPv4 查看。

删除命令:

route delete 129.204.21.129

Neko 黑屏和 NAT1TO1

Neko WebRTC 候选地址必须是访问端可达的地址。当前跨 WireGuard 访问时应设置:

NEKO_WEBRTC_NAT1TO1=10.88.0.2
NEKO_WEBRTC_EPR=52101-52199
NEKO_WEBRTC_TCPMUX=52301
NEKO_WEBRTC_UDPMUX=52301

不要把旧公网 IP 写入 NEKO_WEBRTC_NAT1TO1。源码已调整为:显式填入本机 WireGuard/Tailscale/EasyTier 地址时,Neko LAN watcher 不会再把它覆盖成物理 LAN IP;留空才自动选择物理 LAN IP。

Web 控制台导入

无人直播 Web 的「网络」模块支持导入 VPS 的 WireGuard .conf:

  • 配置会保存到 config/wireguard/imports/<name>.conf。
  • 返回结果会脱敏 PrivateKey、PublicKey、PresharedKey。
  • 页面会生成 Windows Endpoint 旁路路由模板。

导入功能只做解析和保存,不直接执行系统级 wg-quick 或 Windows 隧道安装命令,避免从 Web 表单执行未审计的网络配置。

WireGuard Client Watchdog

NAT-side clients must keep:

PersistentKeepalive = 25

The console now normalizes imported WireGuard configs and adds that value for endpoint peers when it is missing. Deployed hubs also install live-wireguard-watch.service; it checks keepalive-enabled wg-quick interfaces every WIREGUARD_WATCH_INTERVAL=30 seconds and restarts wg-quick@<iface>.service when the latest handshake is older than WIREGUARD_STALE_SECONDS=300.

This handles the failure mode where wg-quick@... is still active but the runtime tunnel stops refreshing handshakes. Configure it in config/system-stack.env:

ENABLE_WIREGUARD_WATCH=1
WIREGUARD_WATCH_INTERVAL=30
WIREGUARD_STALE_SECONDS=300
WIREGUARD_RESTART_COOLDOWN=300