五、两种使用模式
模式一:全局模式(推荐新手)
所有流量都走 exit node。配置最简单,一条命令搞定:
sudo tailscale up --exit-node=<VPS_IP> --exit-node-allow-lan-access=true
手机上就是在 Tailscale 里选一下 exit node。
适合:个人电脑、手机、不需要分流的场景。
模式二:仅终端模式(适合只用 Claude Code 的场景)
很多人的需求是:只有 Claude Code 要走外网,浏览器和其他应用走原来的网络。
核心思路:不开全局 exit node。只用 Tailscale 的内网组网能力把你的电脑和 VPS 连通,在 VPS 上跑一个 SOCKS5 代理,终端通过环境变量直接指向 VPS 的 Tailscale 内网 IP。干净、不侵入系统网络。
第一步:在 VPS 上装一个轻量 SOCKS5 代理
用 dante-server(也叫 danted),一个成熟的 SOCKS5 实现:
sudo apt install dante-server -y
编辑配置文件 /etc/danted.conf:
# 监听 Tailscale 内网接口,只有 tailnet 内的设备能访问
internal: tailscale0 port = 1080
external: eth0
# 不需要认证(因为只有 tailnet 内部能访问,已经足够安全)
socksmethod: none
clientmethod: none
client pass {
from: 100.64.0.0/10 to: 0.0.0.0/0 # 只允许 Tailscale 网段
}
socks pass {
from: 100.64.0.0/10 to: 0.0.0.0/0
}
启动:
sudo systemctl enable danted
sudo systemctl start danted
这个代理监听在 VPS 的 Tailscale 接口上(tailscale0),只有你 tailnet 里的设备能连,公网完全不可见。
第二步:本地终端设置环境变量
export ALL_PROXY=socks5://100.69.90.25:1080
export HTTP_PROXY=socks5://100.69.90.25:1080
export HTTPS_PROXY=socks5://100.69.90.25:1080
curl -I https://api.anthropic.com
只有设了环境变量的终端窗口走代理,其他终端和应用完全不受影响。不需要开 exit node,不需要改系统路由,不需要维护 SSH session。
进阶:写个 alias 一键切换
alias proxy-on='export ALL_PROXY=socks5://100.69.90.25:1080 HTTP_PROXY=socks5://100.69.90.25:1080 HTTPS_PROXY=socks5://100.69.90.25:1080 && echo "Proxy ON"'
alias proxy-off='unset ALL_PROXY HTTP_PROXY HTTPS_PROXY && echo "Proxy OFF"'
之后在任何终端里,proxy-on 开启,proxy-off 关闭。干净利落。
为什么这比 SSH 隧道更好?
| 对比 |
SSH 隧道 |
Tailscale + danted |
| 加密 |
SSH 加密 |
WireGuard 加密 |
| 稳定性 |
SSH session 断了要重连 |
Tailscale 自动维护连接 |
| 开机自启 |
需要手动 |
systemd 管理 |
| 配置复杂度 |
中等 |
一次配置,永久有效 |
| 资源占用 |
每个 session 占端口 |
单一 SOCKS5 端口 |
整个链路就是:终端 → Tailscale 加密隧道 → VPS 上的 SOCKS5 → 出去。