Skip to content

Tailscale 启用后建议自动放行 UDP 端口以支持打洞直连(避免 DERP 中继) #1257

@urjoe

Description

@urjoe

问题描述

在 Asus RT-AX86U Pro (Merlin) 路由器上启用 ShellCrash 的 Tailscale 功能后,即使路由器有公网 IP,远程设备连接时仍然走 DERP 中继,延迟较高,无法建立 UDP 直连。

原因

Tailscale 底层使用 WireGuard,需要通过 UDP 打洞建立直连。CrashCore 每次启动时 Tailscale 绑定的 UDP 端口是随机的,但路由器防火墙默认拦截入站 UDP,导致对端无法直接连入,只能回退到 DERP 中继。

$ netstat -ulnp | grep CrashCore
udp   0.0.0.0:<随机端口>   0.0.0.0:*   CrashCore    ← Tailscale 随机端口
udp   :::1053               :::*        CrashCore    ← DNS
udp   :::7893               :::*        CrashCore    ← 代理

手动添加 iptables 放行规则后即可直连:

iptables -I INPUT -p udp --dport <Tailscale端口> -j ACCEPT

安全性

开放 WireGuard UDP 端口是安全的:

  • 未授权数据包静默丢弃,端口扫描看起来像关闭状态
  • 强加密认证,不存在暴力破解可能

建议

ts_service=ON 时,ShellCrash 在启动 CrashCore 后自动检测 Tailscale 使用的 UDP 端口并添加防火墙放行规则。例如在 bfstart.sh 中 CrashCore 启动后(exit 0 之前)加入:

if [ "$ts_service" = ON ]; then
  (sleep 30 && \
   ts_port=$(netstat -ulnp 2>/dev/null | grep CrashCore | grep '0.0.0.0:' | grep -v ':1053\|:7893' | awk -F: '{print $2}' | awk '{print $1}') && \
   [ -n "$ts_port" ] && \
   iptables -C INPUT -p udp --dport "$ts_port" -j ACCEPT 2>/dev/null || \
   iptables -I INPUT -p udp --dport "$ts_port" -j ACCEPT) &
fi

目前的临时解决方案

用户需自行创建防火墙脚本,在 bfstart.shexit 0 之前后台调用(延迟等待 CrashCore 端口就绪后放行)。

环境信息

  • 路由器:Asus RT-AX86U Pro (Merlin)
  • ShellCrash 版本:1.9.4release
  • 内核:SingBoxR 1.13.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions