6

Tailscale 异地组网/P2P内网穿透

 1 year ago
source link: https://y4er.com/posts/tailscale/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Tailscale 异地组网/P2P内网穿透

 2023-01-04  2023-01-04  约 1007 字   预计阅读 3 分钟 

疫情居家办公期间,折腾了一段时间的cloudflare tunnel,但是网速时好时坏,rdp卡成ppt,向日葵在mac上也不好用,后来在v2ex上发现了Tailscale和ZeroTier两款点对点穿透工具,折腾一下发现比cf tunnel好用一万倍,nat打洞成功之后ping只有5ms,这里记录下折腾的笔记。

用GitHub账号登录就行

传统的vpn结构如图

Tailscale的网络结构如图

两台机器链接如果可以穿透nat打洞成功,那么就是直连,否则就是走Tailscale的中继服务器(derp)。

两台机器其实都是基于wireguard的实现,链接上Tailscale的机器会加一个网卡用于wireguard链接。

更详细的原理见官方的博客 https://tailscale.com/blog/how-nat-traversal-works/

没啥好讲的,安装对应的客户端,然后登录账号就行了。

MagicDNS

Tailscale提供了一个类似内网dns的服务,将所有加入到Tailscale网络中的节点分配一个对应的ip和dns,这样用户不需要记ip了。

自动打洞,work机器和poop机器在同一局域网,所以打洞用的192的段,我测试公司电脑和家里电脑同城打洞成功后只有5ms延迟,没打洞成功就是走的图中的中继DERP服务器了。

exit node

tailscale可以实现FQ,需要先开启ip转发 https://tailscale.com/kb/1103/exit-nodes/#enable-ip-forwarding

If your Linux system has a /etc/sysctl.d directory, use:

echo 'net.ipv4.ip_forward = 1' | sudo tee -a /etc/sysctl.d/99-tailscale.conf
echo 'net.ipv6.conf.all.forwarding = 1' | sudo tee -a /etc/sysctl.d/99-tailscale.conf
sudo sysctl -p /etc/sysctl.d/99-tailscale.conf


Otherwise, use:

echo 'net.ipv4.ip_forward = 1' | sudo tee -a /etc/sysctl.conf
echo 'net.ipv6.conf.all.forwarding = 1' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p /etc/sysctl.conf
If your Linux node uses firewalld, you may need to also allow masquerading due to a known issue. As a workaround, you can allow masquerading with this command:

firewall-cmd --permanent --add-masquerade

通过在国外vps上运行

sudo tailscale up --advertise-exit-node

然后网页控制台中这个节点点击Edit route settings开启此功能

然后在windows的托盘图标中,可以选择本机所有流量走出口节点

Subnet routers

因为每个账号只有20台设备数,所以可能会遇到需要开放一整个网段192.168.1.1/24的情况,我还没遇到,读者看文档自己配置吧。

https://tailscale.com/kb/1019/subnets/

中继服务器

打洞成功率和网络情况有关系,所以为了链接成功率和保证低延迟,可以自建derp中继服务器,我不需要,所以读者移步 https://icloudnative.io/posts/custom-derp-servers/

向日葵、蒲公英、anydesk、todesk什么的都不考虑

  1. parsec
  2. Nebula
  3. ZeroTier

相对来说tailscale界面好看,功能也不差,主要是稳定。

这篇文章更多是记录一下自己折腾的东西,水文。

文笔垃圾,措辞轻浮,内容浅显,操作生疏。不足之处欢迎大师傅们指点和纠正,感激不尽。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK