#!/bin/bash # 把网络调优做成开机自动应用。 # # 为什么需要: # MSS 规则和 sysctl 都是**运行时的**,重启就没了 —— # 不持久化的话,设备一重启就回到 48% 可用率。 set -u RELAY_DIR=/root/lanremote-relay echo "===== 1. 确保调优脚本在位 =====" if [ ! -x "$RELAY_DIR/net-tune.sh" ]; then echo " 找不到 $RELAY_DIR/net-tune.sh" exit 1 fi echo " $RELAY_DIR/net-tune.sh 就绪" echo echo "===== 2. 装 sysctl 配置(内核参数持久化)=====" cat > /etc/sysctl.d/99-lanremote-mtu.conf <<'EOF' # LanRemote: 修路径 MTU 问题 # 实测接口 MTU 1500 时大包会被丢(1488/1500 全丢), # 导致 TLS 握手约 30% 失败。打开探测让内核自己收敛。 net.ipv4.tcp_mtu_probing = 1 EOF sysctl -p /etc/sysctl.d/99-lanremote-mtu.conf 2>/dev/null | sed 's/^/ /' echo echo "===== 3. 装开机服务 =====" cat > /etc/systemd/system/lanremote-nettune.service <&1 | sed 's/^/ /' systemctl start lanremote-nettune.service sleep 1 echo echo "===== 4. 确认 =====" echo " 服务: $(systemctl is-active lanremote-nettune.service) / $(systemctl is-enabled lanremote-nettune.service)" echo " tcp_mtu_probing = $(cat /proc/sys/net/ipv4/tcp_mtu_probing)" echo " MSS 规则:" iptables -t mangle -L -n 2>/dev/null | grep -i mss | sed 's/^/ /' echo echo "===== 5. 重启隧道让它用新参数建连接 =====" systemctl restart lanremote-tunnel sleep 35 echo " 隧道: $(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}')"