#!/bin/bash # 隧道还是不稳 —— 深挖一层 set -u echo "════════ 1. 服务与连接 ════════" echo " relay: $(systemctl is-active lanremote-relay)" echo " tunnel: $(systemctl is-active lanremote-tunnel)" echo " 连接数: $(curl -s --max-time 5 http://127.0.0.1:20241/metrics 2>/dev/null | grep '^cloudflared_tunnel_ha_connections' | awk '{print $2}')" echo echo "════════ 2. watchdog 最近 20 行(它在报什么)════════" tail -20 /root/lanremote-relay/watchdog.log 2>/dev/null | sed 's/^/ /' echo echo "════════ 3. watchdog 是怎么被调起来的 ════════" systemctl is-active lanremote-watchdog 2>&1 | sed 's/^/ 服务: /' crontab -l 2>/dev/null | grep -i watch | sed 's/^/ cron: /' ls -la /etc/systemd/system/ | grep -i watch | sed 's/^/ unit: /' ps aux 2>/dev/null | grep '[w]atchdog' | head -3 | sed 's/^/ 进程: /' echo echo "════════ 4. 隧道日志最后 25 行 ════════" tail -25 /root/lanremote-relay/tunnel.log 2>/dev/null | sed 's/^/ /' echo echo "════════ 5. 本机 relay 通不通 ════════" for i in 1 2 3; do printf " 本机 %d: HTTP %s\n" "$i" "$(curl -s -o /dev/null -w '%{http_code}' --max-time 8 http://127.0.0.1:8080/v1/health)" sleep 1 done echo echo "════════ 6. 公网连打 10 次看规律 ════════" for i in $(seq 1 10); do curl -s -o /dev/null -w " $i: HTTP %{http_code} %{time_total}s\n" \ --max-time 20 -H 'User-Agent: LanRemote/1.4.0' https://relay.xxmxxs.top/v1/health sleep 1 done echo echo "════════ 7. 隧道出口 IP 的可达性(现在还通吗)════════" python3 - <<'PY' import socket import time # 看隧道日志里出现过的 IP ips = ["198.41.192.107", "198.41.200.33", "198.41.192.227", "198.41.200.63", "198.41.192.37"] for ip in ips: s = socket.socket() s.settimeout(3) t = time.perf_counter() try: s.connect((ip, 7844)) print(" %-16s %.0f ms" % (ip, (time.perf_counter() - t) * 1000)) except OSError as e: print(" %-16s 不通 (%s)" % (ip, e.__class__.__name__)) finally: s.close() PY echo echo "════════ 8. 网络本身的质量 ════════" echo " 丢包测试(ping 1.1.1.1 10 次):" ping -c 10 -W 2 1.1.1.1 2>/dev/null | tail -3 | sed 's/^/ /' echo " 到 Cloudflare 边缘的丢包:" ping -c 10 -W 2 198.41.192.107 2>/dev/null | tail -3 | sed 's/^/ /'