# 引入地址 https://github.com/tailscale/tailscale/blob/main/wgengine/magicsock/debugknobs.go # 原理:有环境变量可以强制使用derp TS_DEBUG_ALWAYS_USE_DERP=true # Windows下,使用PowerShell在管理员模式下执行 # 启用环境变量 $reg = "HKLM:\SYSTEM\CurrentControlSet\Services\Tailscale" $val = "TS_DEBUG_ALWAYS_USE_DERP=true" if (Get-ItemProperty -Path $reg -Name Environment -ErrorAction SilentlyContinue) { $cur = Get-ItemPropertyValue -Path $reg -Name Environment if ($cur -notcontains $val) { Set-ItemProperty -Path $reg -Name Environment -Value ($cur + $val) } } else { New-ItemProperty -Path $reg -Name Environment -Value $val -PropertyType MultiString } Restart-Service Tailscale -Force # 禁用环境变量 $reg = "HKLM:\SYSTEM\CurrentControlSet\Services\Tailscale" $val = "TS_DEBUG_ALWAYS_USE_DERP=true" if (Get-ItemProperty -Path $reg -Name Environment -ErrorAction SilentlyContinue) { $cur = Get-ItemPropertyValue -Path $reg -Name Environment $new = $cur | Where-Object { $_ -ne $val } if ($new.Count -eq 0) { Remove-ItemProperty -Path $reg -Name Environment } else { Set-ItemProperty -Path $reg -Name Environment -Value $new } } Restart-Service Tailscale -Force