Files
ykxmz/_build/fix_tunnel_ipv4.sh
xmz7891 b62ac865ea ykxmz 1.5.0:修复手表端 TLS 证书校验 + MTU 修复网络稳定性
被控端
- 修复 MTU 问题:夹 MSS + 路径 MTU 探测(公网可用率 48% -> 100%)
- 复用 HTTP 连接(免掉每次新建 TLS 的 30% 握手失败)
- 每分钟回头找局域网,自动切回快 400 倍的路径
- 画面心跳帧:静止时省流量,客户端仍知道流是活的
- 锁屏时给出可操作的提示

手表端
- 内置 GTS Root R4 / GlobalSign Root CA,修 SSLHandshakeException
- 连接错误翻译成人话(证书/时间/解析/超时分别提示)
- 经中转连上后用服务器报的地址刷新已配对记录
- 新增局域网连接页面、服务器延迟检测

服务器端
- 支持 chunked 请求体(修每 16 秒一次的连接错乱与大面积 502)
- 网络调优脚本 net-tune.sh(开机自动应用)
- 管理页:批量删除、网络体检、下载区
- 隧道改 HTTP/2 + 双连接

文档
- 许可协议 / 安装前必读 / 安装后须知(作者:小麦子)
2026-10-06 19:01:05 +08:00

98 lines
2.8 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# 强制隧道走 IPv4 + HTTP2。
#
# 根因:这条 4G 线路**分配了 IPv6 地址但实际不通**。
# Cloudflare 边缘默认优先 IPv6(日志里是 2606:4700:a8::10),
# 于是每次建隧道都在等一个永远连不上的地址 -> context deadline exceeded。
#
# 修法:
# --edge-ip-version 4 只走 IPv4
# --protocol http2 用 TCP 而不是 QUIC(有些 4G 会拦 UDP)
set -u
RELAY_DIR=/root/lanremote-relay
echo "===== 确认 IPv4 / IPv6 ====="
timeout 6 curl -4 -s -o /dev/null -w ' IPv4 -> %{http_code}\n' https://www.cloudflare.com || echo ' IPv4 不通'
timeout 6 curl -6 -s -o /dev/null -w ' IPv6 -> %{http_code}\n' https://www.cloudflare.com || echo ' IPv6 不通(这就是根因)'
echo
echo "===== 更新 systemd 服务,加 IPv4 参数 ====="
systemctl stop lanremote-tunnel 2>/dev/null || true
pkill -f 'cloudflared tunnel' 2>/dev/null || true
sleep 2
cat > /etc/systemd/system/lanremote-tunnel.service <<'UNIT'
[Unit]
Description=LanRemote Cloudflare 隧道
After=network-online.target lanremote-relay.service
Wants=network-online.target
Requires=lanremote-relay.service
[Service]
Type=simple
# 这条 4G 线路的 IPv6 有地址但不通,必须强制 IPv4;
# 同时用 http2 而不是 QUIC,避开某些 4G 对 UDP 的拦截。
ExecStart=/usr/local/bin/cloudflared tunnel --no-autoupdate \
--edge-ip-version 4 --protocol http2 \
--url http://127.0.0.1:8080
Restart=always
RestartSec=5
MemoryMax=128M
StandardOutput=append:/root/lanremote-relay/tunnel.log
StandardError=append:/root/lanremote-relay/tunnel.log
[Install]
WantedBy=multi-user.target
UNIT
systemctl daemon-reload
systemctl enable lanremote-tunnel >/dev/null 2>&1
rm -f "$RELAY_DIR/tunnel.log"
systemctl start lanremote-tunnel
echo " 服务已更新并启动"
echo
echo "===== 等公网地址(最多 100 秒)====="
URL=""
for i in $(seq 1 50); do
sleep 2
URL=$(grep -oE 'https://[a-z0-9]+(-[a-z0-9]+)+\.trycloudflare\.com' \
"$RELAY_DIR/tunnel.log" 2>/dev/null | tail -1)
if [ -n "$URL" ]; then
echo " 第 $((i*2)) 秒拿到: $URL"
break
fi
done
if [ -z "$URL" ]; then
echo " 还是没拿到,日志尾部:"
tail -12 "$RELAY_DIR/tunnel.log"
exit 1
fi
echo "$URL" > "$RELAY_DIR/public_url.txt"
echo
echo "===== 公网可达性 ====="
for i in 1 2 3 4 5; do
if curl -s --max-time 20 "$URL/v1/health" | grep -q '"ok"'; then
echo " 第 $i 次: 通了"
break
fi
echo " 第 $i 次: 还没通"
sleep 4
done
echo
echo "===== 走的是 IPv4 吗 ====="
curl -s --max-time 15 -o /dev/null -w ' 连接对端 IP: %{remote_ip}\n' "$URL/v1/health"
echo
echo "===== 服务状态 ====="
systemctl is-active lanremote-relay lanremote-tunnel
echo
free -m | head -2
echo
echo "PUBLIC_URL=$URL"