#!/bin/bash # 收尾验证:确认调优在重启后依然生效。 set -u RELAY_DIR=/root/lanremote-relay echo "===== 1. 持久化配置在位吗 =====" echo -n " sysctl 文件: " [ -f /etc/sysctl.d/99-lanremote-mtu.conf ] && echo "有" || echo "缺!" echo -n " 开机服务: " systemctl is-enabled lanremote-nettune.service 2>/dev/null || echo "没启用!" echo -n " 调优脚本: " [ -x "$RELAY_DIR/net-tune.sh" ] && echo "有且可执行" || echo "缺!" echo echo "===== 2. 模拟重启:停掉服务 -> 清掉规则 -> 重新应用 =====" systemctl stop lanremote-nettune.service >/dev/null 2>&1 # 手工清掉规则和 sysctl,模拟重启后的初始状态 for chain in OUTPUT POSTROUTING; do for v in 1300 1360 1400 1440; do while iptables -t mangle -C "$chain" -p tcp --tcp-flags SYN,RST SYN \ -j TCPMSS --set-mss "$v" 2>/dev/null; do iptables -t mangle -D "$chain" -p tcp --tcp-flags SYN,RST SYN \ -j TCPMSS --set-mss "$v" 2>/dev/null || break done done done sysctl -w net.ipv4.tcp_mtu_probing=0 >/dev/null 2>&1 echo " 清理后:" echo " tcp_mtu_probing = $(cat /proc/sys/net/ipv4/tcp_mtu_probing)" echo " MSS 规则 $(iptables -t mangle -L -n 2>/dev/null | grep -ci mss) 条" echo echo " 启动开机服务(模拟开机自动执行)…" systemctl start lanremote-nettune.service sleep 2 echo " 应用后:" echo " tcp_mtu_probing = $(cat /proc/sys/net/ipv4/tcp_mtu_probing)" echo " MSS 规则 $(iptables -t mangle -L -n 2>/dev/null | grep -ci mss) 条" iptables -t mangle -L -n 2>/dev/null | grep -i mss | sed 's/^/ /' echo echo "===== 3. 确认三项服务都在 =====" for s in lanremote-nettune.service lanremote-relay lanremote-tunnel \ lanremote-watchdog.timer; do printf " %-30s %-10s %s\n" "$s" \ "$(systemctl is-active "$s" 2>/dev/null)" \ "$(systemctl is-enabled "$s" 2>/dev/null)" done echo echo "===== 4. 应用后快速验证(12 次)=====" ok=0 for i in $(seq 1 12); do c=$(timeout 12 curl -4 -s -o /dev/null -w '%{http_code}' \ -H 'User-Agent: LanRemote/1.4.0' https://relay.xxmxxs.top/v1/health 2>/dev/null) [ "$c" = "200" ] && ok=$((ok+1)) sleep 2 done echo " 公网可用 $ok/12" echo echo "===== 结论 =====" if [ "$(cat /proc/sys/net/ipv4/tcp_mtu_probing)" = "1" ] \ && [ "$(iptables -t mangle -L -n 2>/dev/null | grep -ci mss)" -ge 2 ]; then echo " ✓ 调优能自动恢复(重启后开机服务会应用)" else echo " ✗ 持久化有问题" fi