请知悉:本文最近一次更新为 1 year 前,文中内容可能已经过时。

之前讲了Tailscale虚拟局域网组网的方式,有自己VPS,追求更高性能和速度的同学,完全可以不适用官方中继节点,自建中继节点提升虚拟局域网节点间的访问速度。

首先,需要安装Go语言:

ARM实例安装Go语言指令

wget https://go.dev/dl/go1.20.1.linux-arm64.tar.gz
tar -C /usr/local -xzf go1.20.1.linux-arm64.tar.gz
echo "export GOROOT=/usr/local/go" >> /etc/profile
echo "export GOPATH=$HOME/go" >> /etc/profile
echo "export PATH=$GOPATH/bin:$GOROOT/bin:$PATH" >> /etc/profile
source /etc/profile
go version

X86实例安装Go语言指令

wget https://go.dev/dl/go1.20.1.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.20.1.linux-amd64.tar.gz
echo "export GOROOT=/usr/local/go" >> /etc/profile
echo "export GOPATH=$HOME/go" >> /etc/profile
echo "export PATH=$GOPATH/bin:$GOROOT/bin:$PATH" >> /etc/profile
source /etc/profile
go version

安装derper服务

国外服务器:

go install tailscale.com/cmd/derper@main

国内服务器:

go env -w GOPROXY=https://goproxy.cn
go install tailscale.com/cmd/derper@main

安装supervisord服务

自己按自己操作系统,安装supervisord服务。之后执行指令增加配置:

cat <<EOF > /etc/supervisord.d/derper.ini
[program:derper]
command=bash -c "/root/go/bin/derper -c=/root/derper.conf -hostname=你自己的域名 -stun --verify-clients"
autostart=true
autorestart=true
startsecs=3
daemonize=no
stderr_logfile=/var/log/derper.log
EOF

解析好你的域名到服务器。

运行derper

supervisorctl update
supervisorctl start derper

稍等片刻,访问443端口,展示html页面表示服务部署完毕。

之后回到Tailscale的后台,进入权限设置页,贴入如下配置信息:

{
"Groups": {
"group:example": ["user1@example.com", "user2@example.com"],
},
// Declare convenient hostname aliases to use in place of IP addresses.
"Hosts": {
"example-host-1": "100.100.100.100",
},
"ACLs": [
{"Action": "accept", "Users": ["*"], "Ports": ["*:*"]},
],
"derpMap": {
"OmitDefaultRegions": true,
"Regions": {"900": {
"RegionID": 900,
"RegionCode": "derper",
"Nodes": [{
"Name": "1",
"RegionID": 900,
"HostName": "你的域名",
}],
}},
},
}

保存后,稍等,再返回设备列表,随便进入一个设备,查看Relays,只显示:Relay #900表示节点已经只通过你的中继服务器构建局域网了。

注意,由于我们默认启用了OmitDefaultRegions,所以derper节点上也要运行tailscale,以此作为鉴权,从而规避其他未授权用户白嫖的情况。


derper 一些参数说明

使用用其他端口,参数:-a=:端口

禁用80监听,参数:-http-port=-1

自定义SSL证书,参数:-certdir=/ssl -certmode=manual,注意,证书命名必须为域名本身,然后放入crt和key即可。


参考资料

tailscale部署私有中继服务器

tailscale自建derper服务器中转,使用自定义端口


如您从本文得到了有价值的信息或帮助,请考虑扫描文末二维码捐赠和鼓励。

尊重他人劳动成果。转载请务必附上原文链接,我将感激不尽。


与《Tailscale 私有中继服务器 DERP 搭建教程》相关的博文:


留言

avatar
😀
😀😁😂😅😭🤭😋😘🤔😰😱🤪💪👍👎🤝🌹👌