跳转至

AX3 Phantun 隧道配置

背景

中国运营商对 UDP 流量有 QoS 限速,AWG/WireGuard 走 UDP 会被针对。 Phantun 把 UDP 包裹成 TCP,运营商看到的只是普通 TCP 连接。

架构

ax3 (10.10.10.2)                          HK VPS (10.10.10.1)
-------------                             ------------------
WG wg-phantun                             WG wg0 (wireguard-go)
    |                                          ^
    | UDP :51820                               | UDP :51820
    v                                          |
phantun-client (容器) ----TCP----> VPS:1699 ---> phantun-server (容器)
192.168.88.8:51820        运营商看到         TUN0 192.168.201.2
                          普通 TCP

部署清单

HK VPS (8.218.128.166, CentOS 8)

步骤 操作 说明
WG 服务端 wireguard-go userspace CentOS 8 内核 4.18 无 WG 模块,用 golang 编译
WG 配置 10.10.10.1/24, 端口 51820 仅 127.0.0.1 内部
phantun-server xyzvps/phantun:latest --network host, --device /dev/net/tun
iptables DNAT TCP 1699 -> 192.168.201.2 phantun TUN peer 地址
iptables INPUT/FORWARD 1699/tcp 放行 -

ax3 (hAP ax3, RouterOS 7.23, arm64)

步骤 命令 说明
VETH veth-ph 192.168.88.8/24 接入 bridge
路由 192.168.200.2/32 -> 192.168.88.8 关键!返回数据回容器
镜像源 docker.m.daocloud.io 国内 Docker Hub 被墙
phantun-client xyzvps/phantun:latest (arm64) cmd 覆盖 entrypoint
WG 接口 wg-phantun 10.10.10.2/24 listen-port 51821
WG Peer endpoint 192.168.88.8:51820 指向 phantun 容器 VETH

RouterOS 关键命令

# VETH + bridge
/interface veth add address=192.168.88.8/24 comment=phantun gateway=192.168.88.1 name=veth-ph
/interface bridge port add bridge=bridge interface=veth-ph

# 关键路由
/ip route add dst-address=192.168.200.2/32 gateway=192.168.88.8 comment=phantun

# 容器
/container config set registry-url=docker.m.daocloud.io
/container add comment=Phantun interface=veth-ph logging=yes name=phantun \
  remote-image=docker.m.daocloud.io/xyzvps/phantun:latest \
  root-dir=/usb1/phantun start-on-boot=yes \
  cmd="phantun_client --local 0.0.0.0:51820 --remote 8.218.128.166:1699 --ipv4-only"

# WG
/interface wireguard add listen-port=51821 mtu=1420 name=wg-phantun private-key="..."
/ip address add address=10.10.10.2/24 interface=wg-phantun
/interface wireguard peers add allowed-address=0.0.0.0/0 endpoint-address=192.168.88.8 \
  endpoint-port=51820 interface=wg-phantun persistent-keepalive=25s \
  public-key="<VPS_WG公钥>"

VPS 关键命令

# wireguard-go 编译(CentOS 8 无内核模块)
docker run --rm -v /usr/local/bin:/out golang:alpine sh -c "
  apk add git && git clone --depth 1 https://git.zx2c4.com/wireguard-go /tmp/wg &&
  cd /tmp/wg && CGO_ENABLED=0 go build -o /out/wireguard-go .
"

# WG userspace 启动
WG_I_PREFER_BUGGY_USERSPACE_TO_POLISHED_KMOD=1 wg-quick up wg0.conf

# phantun-server
docker run -d --name phantun-server --restart unless-stopped \
  --network host --cap-add=NET_ADMIN --device /dev/net/tun \
  xyzvps/phantun:latest \
  phantun_server --local 1699 --remote 127.0.0.1:51820 --ipv4-only

# iptables
iptables -A INPUT -p tcp --dport 1699 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp --dport 1699 -j DNAT --to-destination 192.168.201.2:1699
iptables -A FORWARD -i eth0 -o tun0 -p tcp --dport 1699 -j ACCEPT
iptables -A FORWARD -i tun0 -o eth0 -p tcp --sport 1699 -j ACCEPT

踩坑记录

原因 解决
Docker Hub 拉不动 国内被墙 daocloud 镜像源
CentOS 8 无 WG 模块 内核 4.18 编译 wireguard-go userspace
phantun --local 只接端口号不是 IP:PORT --local 1699
phantun 不直接 listen 靠 TUN+DNAT 加 iptables DNAT 规则
EBADF 错误 缺 /dev/net/tun 加 --device
ROS 7.23 无 auto-restart-interval 参数改名 直接用 start-on-boot
ROS cmd 引号 SSH 传参转义复杂 外层单引号,内层双引号

验证

ax3 -> ping 10.10.10.1: 10/10 通, avg 102ms, 0% loss

参考

  • phantun 官方: https://github.com/dndx/phantun
  • 多架构镜像: https://hub.docker.com/r/xyzvps/phantun
  • 恩山论坛 RouterOS 部署: https://www.right.com.cn/forum/thread-8450962-1-1.html
  • wireguard-go: https://git.zx2c4.com/wireguard-go