VPN mode
The phone watches itself, no computer needed. The catch: it keeps the iOS VPN slot busy (iOS allows only one VPN at a time), so it is off by default.
Guide · Agent keep-alive
Install a watchdog on an always-on Linux host or VM on your network. When ketec is killed, hangs or the phone restarts, it re-mounts the developer disk image and launches ketec again. No VPN on the phones — built for device racks and fleets.
Agent mode needs ketec to stay running, and iOS does not let an app relaunch itself. So ketec's Agent keep-alive comes in two modes:
The phone watches itself, no computer needed. The catch: it keeps the iOS VPN slot busy (iOS allows only one VPN at a time), so it is off by default.
An always-on Linux host or VM on your network watches all phones: when ketec is killed, hangs or the phone restarts, it re-mounts the developer disk image and launches ketec. No VPN on the phones. Made for device racks and fleets.
Four steps in total: install the service on the host → pair each phone once on a Mac → register the pairing files on the host → turn on “LAN keep-alive” in the app.
You need a watchdog host, a Mac (only for the first pairing) and phones that already run ketec.
49152–49160 and 9800 open from the host to the phones.9811 on the host (used to report a new address after an IP change; see What if a phone changes its IP?).ketec-lan pair-host, see the FAQ).Run one command on the host. The script downloads and verifies ketec-lan, installs it as the systemd service ketec-lan-watch (starts at boot, restarts 5 seconds after a crash), generates an access token and opens port 9811 in firewalld / ufw.
curl -fsSL https://ketec.top/lan/install.sh | sudo bash
When it finishes it prints something like this (the token is random; shown here as <token>):
==> 下载 ketec-lan(lan-v1.0.0) / downloading ketec-lan
==> 安装到 /opt/ketec-lan / installing
==> firewalld 已放行 9811/tcp
✅ ketec-lan-watch 已运行 / running(已登记 0 台设备 / 0 device(s) registered)
下一步 Next:
1. 在 Mac 上用数据线配对每台手机 / pair each iPhone over USB on a Mac:
ketec-lan pair --name 01
2. 把 ~/.ketec-lan/pairings/<UDID>.plist 拷到本机,然后登记 / copy it here, then register:
ketec-lan add /path/<UDID>.plist --host <手机IP> --name 01
3. 看状态 / status:
curl -H "Authorization: Bearer <token>" http://192.168.1.50:9811/api/watch
日志 / logs: journalctl -u ketec-lan-watch -f
令牌 Token: <token> (保存在 /etc/ketec-lan/env)
教程 Guide: https://ketec.top/guide-lan-keepalive.html/etc/ketec-lan/env (mode 600). You need it to read the status and call the API. Forgot it? Run sudo cat /etc/ketec-lan/env.http://host-ip:9811/api/watch — see “Check it works” below./opt/ketec-lan/ (command ketec-lan); pairing files and the device list live in /var/lib/ketec-lan/.Uninstall (pairing files stay in /var/lib/ketec-lan; delete them yourself once you are sure you no longer need them):
curl -fsSL https://ketec.top/lan/install.sh | sudo bash -s -- --uninstall
Pairing gives the host the key it needs to talk to the phone. Do it once per phone.
Download ketec-lan-macos-arm64 (checksums in SHA256SUMS). In Terminal, go to the download folder, make it executable and remove the quarantine flag:
cd ~/Downloads chmod +x ketec-lan-macos-arm64 xattr -d com.apple.quarantine ketec-lan-macos-arm64
If it says No such xattr, the file has no quarantine flag — just carry on.
Connect the phone to the Mac with a cable and pair. --name is a name you choose for this phone; later commands accept it instead of the UDID:
./ketec-lan-macos-arm64 pair --name 01
When the phone asks “Trust This Computer?”, tap Trust and enter the passcode.
The pairing file is saved as ~/.ketec-lan/pairings/<UDID>.plist. Unplug the phone and repeat for the next one (names 02, 03 and so on).
ls ~/.ketec-lan/pairings/
On the Mac, copy the pairing files to the host (replace <code>user</code> with your user name on the host):
scp ~/.ketec-lan/pairings/*.plist user@192.168.1.50:~/
Register each phone on the host. --host is the phone's fixed IP. As a regular user, just put sudo in front of the command (not needed as root):
sudo ketec-lan add ~/<UDID>.plist --host 192.168.1.101 --name 01 rm ~/<UDID>.plist
add copies the pairing file into /var/lib/ketec-lan/pairings/ (mode 600) and tries the phone once. check.ok: true in the reply means the host can reach it; false is fine too (for example, the screen is off) — the watchdog keeps retrying. Then delete the copy in your home directory (the second line above).
Within 15 seconds of registering, the watchdog starts watching the phone. No service restart needed.
With many devices, put one line per phone — “UDID IP name” — in devices.txt and register them in a loop:
00008110-000000000000001A 192.168.1.101 01 00008110-000000000000001B 192.168.1.102 02 00008110-000000000000001C 192.168.1.103 03
while read -r udid ip name; do [ -z "$udid" ] && continue sudo ketec-lan add "$HOME/$udid.plist" --host "$ip" --name "$name" && rm -f "$HOME/$udid.plist" done < devices.txt sudo ketec-lan devices
Open ketec on the phone, go to the “Agent keep-alive” card in Settings and turn on the “LAN keep-alive” row (this turns “VPN keep-alive” off). Tap ⓘ at the right of a row for details; the LAN keep-alive info has a “Setup guide” button that opens this page.
Once it is on, check the status line: “Watched by LAN host (192.168.1.50)” means the host is watching this phone; “No LAN host detected yet” means the host has not reached it yet — see “Check it works” above and the FAQ.
Read the watch status on the host. Only root can read the token file, so fetch the token with sudo first; from another computer, paste the token in directly:
TOKEN=$(sudo sed -n 's/^KETEC_LAN_TOKEN=//p' /etc/ketec-lan/env) curl -H "Authorization: Bearer $TOKEN" http://192.168.1.50:9811/api/watch
Sample reply — one entry per device, keyed by the device name (or the UDID if it has no name):
{
"success": true,
"data": {
"now": 1796380000,
"devices": {
"01": {
"udid": "00008110-000000000000001A",
"state": "watching",
"addr": "192.168.1.101:49152",
"appRunning": true,
"httpOk": true,
"pid": 1146,
"launches": 3,
"activations": 1,
"relaunches": 0,
"remounts": 1,
"lastCheck": 1796379998,
"lastLaunch": 1796376112,
"lastError": ""
}
}
}
}| Field | Meaning |
|---|---|
state | watching watching · connecting connecting · offline phone unreachable · reconnecting reconnecting after a drop |
addr | Address of the phone in use |
appRunning | Whether the ketec process is running |
httpOk | Whether ketec's HTTP service (port 9800) responds |
pid | ketec's process ID |
launches | Times ketec was launched because it was not running |
activations | Times ketec was brought to the foreground because its process was there but HTTP was down |
relaunches | Times ketec was killed and restarted after bringing it forward did not help |
remounts | Times the developer disk image was re-mounted (usually after a phone restart) |
lastCheck | Time of the last check (Unix time, seconds) |
lastLaunch | Time of the last launch / foreground / restart (Unix time, seconds) |
lastError | Last connection error; empty when all is well |
Follow the log:
journalctl -u ketec-lan-watch -f
Sample log:
Dec 04 21:18:02 lan-host ketec-lan[812]: [ketec-lan] 状态接口已启动:http://0.0.0.0:9811/api/watch(需要令牌) Dec 04 21:18:02 lan-host ketec-lan[812]: [ketec-lan] 看门狗启动:1 台设备,每 5 秒检查一次 top.ketec.app(每 15 秒重读登记表,新加的设备自动看守) Dec 04 21:18:04 lan-host ketec-lan[812]: [ketec-lan] [01] 已连上(192.168.1.101:49152),开始看守 top.ketec.app Dec 04 21:25:41 lan-host ketec-lan[812]: [ketec-lan] [01] top.ketec.app 不在运行,已拉起(pid 1146) Dec 04 22:03:17 lan-host ketec-lan[812]: [ketec-lan] [01] 已重挂开发者镜像 Dec 04 22:03:18 lan-host ketec-lan[812]: [ketec-lan] [01] 已连上(192.168.1.101:49152),开始看守 top.ketec.app Dec 04 22:03:34 lan-host ketec-lan[812]: [ketec-lan] [01] 进程在但 HTTP 不通,已切到前台(pid 1187)
The service logs in Chinese for now. In order, the lines say: status API started; watchdog started; connected to 01 and watching top.ketec.app; ketec was not running and was launched; the developer disk image was re-mounted after a restart; the process was there but HTTP was down, so ketec was brought to the foreground.
The watchdog keeps one persistent connection per phone and checks every 5 seconds:
| Scenario | Recovery time |
|---|---|
| ketec killed | about 15 s |
| ketec hung (process there, HTTP down) | about 30 s |
| Phone restarted | about 30 s after the phone is back on the network, Agent is usable again |
A pairing file identifies the phone itself, not its IP: a phone with a new IP does not need to be paired again — the host just needs to learn the new address. In most cases that now happens automatically:
POST /api/hello every 30 seconds. The host updates its record only after a handshake with the pairing file succeeds (forged check-ins do nothing), then reconnects to the new address right away — about 2 seconds in our tests. Requirement: the phone can reach port 9811 on the host (the reverse direction must work too).sudo ketec-lan host <device> <new-ip>. That is why a fixed IP reserved on the router is still recommended.When a check-in succeeds, the host log shows:
Dec 04 22:40:12 lan-host ketec-lan[812]: [ketec-lan] [01] App 报到新地址 192.168.1.102:49152,握手验证通过,已更新登记 Dec 04 22:40:14 lan-host ketec-lan[812]: [ketec-lan] [01] 已连上(192.168.1.102:49152),开始看守 top.ketec.app
Run these on the host; as a regular user, put sudo in front. <device> can be the name, the UDID or the IP.
| Command | What it does |
|---|---|
ketec-lan devices | List registered devices |
ketec-lan host 01 192.168.1.111 | Phone has a new IP: updates the record only; the watchdog uses the new address on its next reconnect, no restart needed |
ketec-lan rename 01 A01 | Rename a device |
ketec-lan forget 01 | Stop watching a phone and delete its pairing file |
ketec-lan launch 01 top.ketec.app · ketec-lan stop 01 top.ketec.app | Launch / stop an app by hand |
ketec-lan up 01 | Manual recovery: re-mount the developer disk image if needed, then launch ketec |
systemctl status ketec-lan-watch · systemctl restart ketec-lan-watch | Service status / restart |
journalctl -u ketec-lan-watch -f | Follow the log |
curl -fsSL https://ketec.top/lan/install.sh | sudo bash -s -- --uninstall | Uninstall the service (pairing files are kept) |
Port 9811 also serves control endpoints, authorized with the same token (Authorization: Bearer), so you can plug the host into your own fleet tools. Request bodies are JSON:
| Method | Path | What it does |
|---|---|---|
| GET | /api/watch | Watch status of all devices (see “Check it works”) |
| GET | /api/devices | Registered devices |
| POST | /api/launch {"device","bundleId","kill"?} | Launch an app; add "kill": true to stop it first |
| POST | /api/stop {"device","bundleId"} | Stop an app |
| POST | /api/up {"device","bundleId"?} | Re-mount the developer disk image if needed, then launch the app (bundleId defaults to top.ketec.app) |
| POST | /api/hello {"ip","rpPort"} | Phone reports its new address after an IP change (called by the app; no token) |
TOKEN=$(sudo sed -n 's/^KETEC_LAN_TOKEN=//p' /etc/ketec-lan/env)
curl -X POST http://192.168.1.50:9811/api/launch \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"device":"01","bundleId":"top.ketec.app"}'Success returns {"success": true, "data": …}, failure {"success": false, "message": "…"}; a wrong token gets 401. For ketec's own endpoints on the phone, see the HTTP API reference.
/api/hello needs no token. Body: {"ip": "phone-ip", "rpPort": 0}; reply: {"matched": "<UDID>", "addr": "ip:port"} or {"matched": null} (wrapped in data as usual). The reported address is only a candidate: the host must complete a handshake with a registered pairing file at that address before it updates anything, so a forged check-in cannot change a thing.
curl -X POST http://192.168.1.50:9811/api/hello \
-H "Content-Type: application/json" \
-d '{"ip":"192.168.1.102","rpPort":0}'
{"success":true,"data":{"matched":"00008110-000000000000001A","addr":"192.168.1.102:49152"}}
{"success":true,"data":{"matched":null}}In most cases the host follows the new address automatically — see What if a phone changes its IP? above. Only if the IP changed while ketec was not running do you need sudo ketec-lan host <device> <new-ip>.
Check in this order: is the screen off (Auto-Lock must be Never)? Is the phone on Wi‑Fi rather than cellular only? Across subnets, do your router and firewall allow TCP 49152–49160 and 9800 from the host to the phone? A phone with a passcode must be unlocked once after a restart. The lastError field and the journalctl log show the exact reason.
A pairing file is the debugging key to that phone: whoever has it can control the phone over the network. Keep it only on the watchdog host (ketec-lan stores it with mode 600), delete the copies on the Mac and in your home directory on the host once registered, and encrypt any backup. After “Reset Location & Privacy”, “Reset All Settings” or “Erase All Content and Settings” on the phone, the old pairing stops working and you need to pair again.
Not yet — please pair on a Mac with Apple silicon. The watchdog host itself only needs Linux.
Yes. Run sudo ketec-lan pair-host --name lan-host on the host, then on the phone open Settings → Privacy & Security → Developer Mode → Pair, pick the host and enter the 6-digit code shown in the host's terminal. Host and phone must be on the same subnet (discovery uses Bonjour). The device is registered on the host right away; rename it with sudo ketec-lan rename.
Each phone uses one persistent connection and very little resources, so dozens to a hundred or more phones are fine.
Not recommended. The two are mutually exclusive in the app: turning on LAN keep-alive switches VPN keep-alive off.