---
title: "连接与运行时错误 | Wantastic Docs"
description: "解决服务启动失败、配置错误、TUN 问题、没有握手以及 DNS 警告。"
url: "https://wantastic.app/zh/docs/errors-connect-runtime"
category: "Troubleshooting"
reading_time: "7 分钟"
---

# 连接与运行时错误

解决服务启动失败、配置错误、TUN 问题、没有握手以及 DNS 警告。

> **Outcome:** wantasticd status 显示 Connected，且设备处于 Online 状态。

## Before you start

- 设备上的 root 或管理员权限。
- 服务日志（参见 故障排查：从这里开始 → 收集日志）。

## 如何阅读日志

- 以 "Failed to load configuration:" 或 "Failed to start agent:" 开头的行会使服务停止，随后服务管理器每 5 秒重启一次服务。
- 正常启动以 "Wantastic agent started successfully" 结束。
- 每 30 秒出现一次 "Device health check failed"，表示代理在运行，但隧道没有流量通过。
- P2P、端口映射和 DNS 提示大多只是信息性的。

## 检查要点

1. 服务循环重启：读取第一条 "Failed to …" 行，并在下文中查找。最常见的原因是配置为空。
2. 服务在运行但没有握手：放行出站 UDP 51820，然后检查时钟。
3. 握手正常但无法访问某个对端：检查 Topology 中的组链接。

*失败：设备未认领: 服务以空配置启动并循环重启。*

```
$ $ sudo journalctl -u wantasticd -n 3 --no-pager
wantasticd[812]: Failed to load configuration: validate config: private key required
systemd[1]: wantasticd.service: Scheduled restart job, restart counter is at 14.
```

*已修复：认领后重启: 使用 genkey 认领设备，按 Ctrl+C，然后重启服务。*

```
$ $ sudo wantasticd genkey
Device claimed. Configuration saved to /etc/wantastic/config.conf
$ $ sudo systemctl restart wantasticd
wantasticd[901]: Wantastic agent started successfully
```

## 速查表

| 错误 | 最简单的修复方法 |
| --- | --- |
| Config not found at … / private key required | 使用 genkey 认领，然后重启。 |
| server public key … / server endpoint required | 删除配置，重新认领。 |
| failed to resolve endpoint <host> | 修复 DNS；服务会自动重试。 |
| /dev/net/tun does not exist | 安装 kmod-tun 或加载 tun 模块。 |
| operation not permitted | 以 root 身份运行或添加 NET_ADMIN。 |
| Device health check failed | 放行 UDP 51820；校正时钟。 |
| the running daemon is older than this CLI… | 重启服务。 |
| DNS: tunnel DNS not written (…) | 设置 WANTASTIC_DNS_MODE=off。 |

## Verify the result

- wantasticd status 显示 Connected。
- wantasticd peers 显示 (server)，且握手时间在几秒之前。

## Common issues

### connect 找不到配置。

```
Config not found at <cfg>. Run `wantasticd genkey --out <key>` to create a claim key and wait for claim, or pass --wait-claim with an existing key.
```

- **Where:** wantasticd connect
- **Likely cause:** 设备从未认领过，或配置位于其他位置。
- **Fix:** 使用 genkey 认领设备，然后重启服务。

Shell:

```bash
sudo wantasticd genkey
# after "Device claimed": press Ctrl+C, then:
sudo systemctl restart wantasticd
```

- **Verify:** 日志中出现 "Wantastic agent started successfully"。

### 安装后服务立即失败。

```
Failed to load configuration: validate config: private key required
```

- **Where:** wantasticd 日志
- **Likely cause:** 设备尚未认领，因此配置为空。
- **Fix:** 使用 genkey 认领设备，按 Ctrl+C，然后重启服务。

Shell:

```bash
sudo wantasticd genkey
# after "Device claimed": press Ctrl+C, then:
sudo systemctl restart wantasticd
```

- **Verify:** wantasticd status 显示 Connected。

### 配置缺少中心节点密钥。

```
Failed to load configuration: validate config: server public key required
```

- **Where:** wantasticd 日志
- **Likely cause:** 配置不完整，或被手动编辑过。
- **Fix:** 移走损坏的配置并重新认领设备。

Shell:

```bash
sudo mv /etc/wantastic/config.conf /etc/wantastic/config.conf.bad
sudo wantasticd genkey
# after "Device claimed": press Ctrl+C, then:
sudo systemctl restart wantasticd
```

- **Verify:** 服务启动。

### 中心节点密钥无效。

```
Failed to load configuration: validate config: server public key must be a base64-encoded 32-byte WireGuard key
```

- **Where:** wantasticd 日志
- **Likely cause:** 配置只是占位内容（例如 Windows 登录失败后），或密钥在复制粘贴时损坏。
- **Fix:** 移走损坏的配置并重新注册。在 Windows 上，使用新令牌登录。

Shell:

```bash
sudo mv /etc/wantastic/config.conf /etc/wantastic/config.conf.bad
sudo wantasticd genkey
# after "Device claimed": press Ctrl+C, then:
sudo systemctl restart wantasticd
```

- **Verify:** 服务启动。

### 配置中没有端点。

```
Failed to load configuration: validate config: server endpoint required
```

- **Where:** wantasticd 日志
- **Likely cause:** 配置不完整。
- **Fix:** 移走损坏的配置并重新认领设备。

Shell:

```bash
sudo mv /etc/wantastic/config.conf /etc/wantastic/config.conf.bad
sudo wantasticd genkey
# after "Device claimed": press Ctrl+C, then:
sudo systemctl restart wantasticd
```

- **Verify:** 服务启动。

### 启动时无法解析中心节点主机名。

```
Failed to load configuration: validate config: failed to resolve endpoint <host>: …
```

- **Where:** wantasticd 日志
- **Likely cause:** 启动时 DNS 尚未就绪，或解析器故障（"no IP addresses found for hostname"）。
- **Fix:** 检查 DNS。服务会自动重试。

Shell:

```bash
nslookup wg.wantastic.app
sudo systemctl restart wantasticd
```

- **Verify:** 日志中出现 "WireGuard device up. Peer endpoint: …"。

### 无法创建隧道接口。

```
Failed to start agent: create device: create tun: CreateTUN("wantastic0") failed; /dev/net/tun does not exist
```

- **Where:** wantasticd 日志
- **Likely cause:** 缺少 TUN 内核模块（OpenWrt 未安装 kmod-tun），或容器中没有 /dev/net/tun。
- **Fix:** 安装或加载 TUN，然后重启服务。

Shell:

```bash
opkg update && opkg install kmod-tun   # OpenWrt
sudo modprobe tun                       # Linux
docker run --device /dev/net/tun --cap-add NET_ADMIN …   # Docker
```

- **Verify:** 日志中出现 "Created TUN interface: wantastic0"。

### 接口或路由出现权限错误。

```
operation not permitted
```

- **Where:** wantasticd 日志
- **Likely cause:** wantasticd 未以 root 身份运行，或容器没有 NET_ADMIN 权限。
- **Fix:** 使用已安装的服务（它以 root 身份运行），或为容器添加 --cap-add NET_ADMIN。

Shell:

```bash
sudo systemctl restart wantasticd
```

- **Verify:** 服务启动。

### 启动重试次数已用完。

```
failed to start agent after 10 attempts: …
```

- **Where:** wantasticd 日志
- **Likely cause:** 另一个错误反复出现。冒号后面的文字才是真正的原因。
- **Fix:** 在此列表中查找冒号后面的文字，修复后重启服务。

- **Verify:** 服务启动。

### 监听端口被占用。

```
Port N in use, using random port
```

- **Where:** wantasticd 日志
- **Likely cause:** 另一个程序占用了该端口。"Port %d in use, retrying with port %d..." 含义相同，仅为提示信息。
- **Fix:** 无需操作。

- **Verify:** 握手正常。

### 隧道中没有对端。

```
WARNING: No peers configured in WireGuard device!
```

- **Where:** wantasticd 日志
- **Likely cause:** 配置中没有 [Peer] 部分。
- **Fix:** 移走配置并重新认领设备。

Shell:

```bash
sudo mv /etc/wantastic/config.conf /etc/wantastic/config.conf.bad
sudo wantasticd genkey
# after "Device claimed": press Ctrl+C, then:
sudo systemctl restart wantasticd
```

- **Verify:** wantasticd peers 列出 (server)。

### 健康检查持续失败。

```
Device health check failed: …
```

- **Where:** wantasticd 日志（每 30 秒）
- **Likely cause:** 与中心节点没有握手：出站 UDP 51820 被阻止、时钟错误或 MTU 过大。
- **Fix:** 在上游防火墙上放行出站 UDP 51820，并校正时钟。

Shell:

```bash
sudo timedatectl set-ntp true
wantasticd peers
```

- **Verify:** wantasticd peers 显示握手时间在几秒之前。

### 本地控制端口失败。

```
IPC API Error: failed to find open port
```

- **Where:** wantasticd 日志
- **Likely cause:** 端口 127.0.0.1:9034 及后续端口均被占用。"Warning: failed to start local IPC API" 和 "IPC API Error binding to …, trying next port..." 与此相关。
- **Fix:** 停止占用该端口的程序，或使用 WTC_IPC_PORT 设置其他端口。

Shell:

```bash
sudo ss -ltnp | grep 9034
```

- **Verify:** wantasticd status 正常工作。

### CLI 版本比服务新。

```
the running daemon is older than this CLI and has no /api/…; restart it to load the installed version (sudo systemctl restart wantasticd)
```

- **Where:** wantasticd status / peers / ping
- **Likely cause:** 二进制文件已更新，但服务仍在运行旧版本。
- **Fix:** 重启服务。

Shell:

```bash
sudo systemctl restart wantasticd
```

- **Verify:** wantasticd status 显示新版本。

### CLI 无法与服务通信。

```
daemon returned HTTP N: …
```

- **Where:** wantasticd CLI
- **Likely cause:** 本地控制 API 失败。"decode daemon response" 情况类似。
- **Fix:** 重启服务后重试。

Shell:

```bash
sudo systemctl restart wantasticd
```

- **Verify:** wantasticd status 正常工作。

### 对端一直走中继。

```
direct handshake timeout
```

- **Where:** wantasticd 日志
- **Likely cause:** NAT 阻止了直连路径。"promotion queue full"、"gateway does not answer NAT-PMP"、"no UPnP internet gateway found" 和 "router's external address is not public (CGNAT)" 同样无害。
- **Fix:** 无需操作，中继可以正常工作。如需直连路径，请在路由器上启用 UPnP 或 NAT-PMP。

- **Verify:** 流量正常通过。

### 本地访问找不到局域网。

```
enable local access: no directly connected private IPv4 LAN subnet found
```

- **Where:** wantasticd (--allow-local-access)
- **Likely cause:** 该设备没有私有 IPv4 局域网。
- **Fix:** 在此设备上使用 --allow-local-access=false 关闭该选项。

- **Verify:** 重启后不再报错。

### macOS 或 Windows 上的本地访问。

```
automatic local-access subnet routing is not supported on macOS yet
```

- **Where:** wantasticd (--allow-local-access)
- **Likely cause:** 此功能仅适用于 Linux 和 OpenWrt（Windows 显示 "… on Windows yet"）。
- **Fix:** 使用 Linux 或 OpenWrt 设备作为局域网网关。

- **Verify:** 通过 Linux 或 OpenWrt 设备的本地访问正常工作。

### 伪装（masquerade）规则失败。

```
iptables masquerade on <if>: …
```

- **Where:** wantasticd (--allow-local-access)
- **Likely cause:** 缺少 iptables。
- **Fix:** 安装 iptables。

Shell:

```bash
sudo apt-get install -y iptables
opkg install iptables-nft   # OpenWrt
```

- **Verify:** 本地访问正常工作。

### 无法启用转发。

```
enable forwarding: …
```

- **Where:** wantasticd (--allow-local-access)
- **Likely cause:** 系统设置为只读（例如在容器中）。
- **Fix:** 在宿主机上启用 IP 转发。

Shell:

```bash
sudo sysctl -w net.ipv4.ip_forward=1
```

- **Verify:** 本地访问正常工作。

### 本地访问设备过多。

```
too many tenant local-access advertisers
```

- **Where:** wantasticd (--allow-local-access)
- **Likely cause:** 你的账号中共享局域网的设备过多。
- **Fix:** 在不需要的设备上关闭 --allow-local-access。

- **Verify:** 错误消失。

### 无法写入 DNS。

```
DNS: tunnel DNS not written (…)
```

- **Where:** wantasticd 日志
- **Likely cause:** 另一个程序在管理 DNS。相关消息："write <f>: read-only filesystem; remount it read-write or manage DNS through the platform resolver"、"<x> owns /etc/resolv.conf; DNS cannot be changed safely"、"<if> is not managed by NetworkManager"。
- **Fix:** 让系统管理 DNS：为该服务设置 WANTASTIC_DNS_MODE=off。

Shell:

```bash
sudo mkdir -p /etc/systemd/system/wantasticd.service.d
printf '[Service]\nEnvironment=WANTASTIC_DNS_MODE=off\n' | sudo tee /etc/systemd/system/wantasticd.service.d/dns.conf
sudo systemctl daemon-reload && sudo systemctl restart wantasticd
```

- **Verify:** 重启后不再出现 DNS 警告。

### 更新检查警告。

```
Update check failed; will retry in an hour: …
```

- **Where:** wantasticd 日志
- **Likely cause:** 设备无法访问 get.wantastic.app。隧道仍正常工作。
- **Fix:** 允许访问 get.wantastic.app 的 HTTPS。

Shell:

```bash
curl -I https://get.wantastic.app/latest
```

- **Verify:** 下一次每小时检查时不再出现警告。

### 出现两个隧道，或出现 wantastic1 接口。

- **Where:** ip link / wantasticd 日志
- **Likely cause:** genkey 或 login 仍在前台与服务同时运行。
- **Fix:** 在 genkey 窗口中按 Ctrl+C，然后重启服务。

Shell:

```bash
pgrep -a wantasticd
sudo systemctl restart wantasticd
```

- **Verify:** 只有一个 wantasticd 进程和一个 wantastic0 接口。

## Continue with

- [Troubleshooting: start here](https://wantastic.app/zh/docs/troubleshooting): Fix most problems in 3 steps. If that does not work, find your exact error in the table and open the matching guide.
- [wantasticd CLI reference and operations](https://wantastic.app/zh/docs/wantasticd): The most used wantasticd commands first, then every command and flag, environment variables, config and state paths per OS, log lines, local access, exit node, and the claim flow (genkey / --wait-claim).
- [Login, token and claim errors](https://wantastic.app/zh/docs/errors-login-claim): Fix claim problems (genkey, QR code, Claim Device), "Login failed: …" messages and token errors.
- [OpenWrt and embedded device errors](https://wantastic.app/zh/docs/errors-openwrt-embedded): kmod-tun, read-only flash, procd, full flash, wrong clocks and BusyBox issues on routers and modules.
- [macOS and Windows errors](https://wantastic.app/zh/docs/errors-macos-windows): launchd, Gatekeeper, tray, sc.exe and Windows service errors with the easiest fixes.
- [Run in Docker (community pattern)](https://wantastic.app/zh/docs/install-docker): Run wantasticd in a Docker container built from the official release: build a small image, claim it once with genkey, then run it detached. Not an official image.
