tailscale自建derper服务器中转,使用自定义端口
标签搜索
侧边栏壁纸
  • 累计撰写 6 篇文章
  • 累计收到 14 条评论

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

Lance
2022-11-03 / 4 评论 / 169 阅读 / 正在检测是否收录...

安装golang环境

tailscale项目使用的golang环境比较新,部署自定义derper服务要求golang版本1.16以上。推荐尽可能安装最新的版本,本文安装目前最新版本

golang官网在国外,直接从官网下载会比较慢,可以选择国内镜像站下载

wget https://golang.google.cn/dl/go1.22.0.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.22.0.linux-amd64.tar.gz 

编辑/etc/profile文件,添加如下内容。编辑文件可以使用vim或者宝塔等其他工具。

export GOROOT=/usr/local/go
export GOPATH=/usr/local/gopath
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOROOT/bin
export PATH=$PATH:$GOPATH/bin

保存退出后,执行以下命令使环境变量生效

source /etc/profile

检查golang是否安装成功

go -version

查看golang版本,如果有相应信息返回,则说明golang环境安装成功。

安装derper服务

1. 下载

安装derper服务,执行以下命令
安装之前设置下go代理执行如下代码

go env -w GOPROXY=https://goproxy.cn,direct

然后执行如下代码安装

go install tailscale.com/cmd/derper@main

等待下载安装完成,查看是否安装成功

2. 检查

derper -h
# 如果有以下提示信息

Usage of derper:
  -a string
        server address (default ":443")
  -bootstrap-dns-names string
        optional comma-separated list of hostnames to make available at /bootstrap-dns
  -c string
        config file path
  -certdir string
        directory to store LetsEncrypt certs, if addr's port is :443 (default "/root/.cache/tailscale/derper-certs")
  -dev
        run in localhost development mode
  -hostname string
        LetsEncrypt host name, if addr's port is :443 (default "derp.tailscale.com")
  -logcollection string
        If non-empty, logtail collection to log to
  -mesh-psk-file string
        if non-empty, path to file containing the mesh pre-shared key file. It should contain some hex string; whitespace is trimmed.
  -mesh-with string
        optional comma-separated list of hostnames to mesh with; the server's own hostname can be in the list
  -stun
        also run a STUN server
  -verify-clients
        verify clients to this DERP server through a local tailscaled instance.

则说明derper安装成功

3. 配置

在安装路径下/usr/local/gopath/bin下编写如下脚本,然后保存文件为runderper

#!/bin/sh
cd /usr/local/gopath/bin
nohup ./derper -hostname 你的域名 -c=derper.conf -a :端口 -http-port -1 -certdir 你的证书路径 -certmode manual -stun &
echo $! > app.pid

赋权可执行

chmod +x runderper

编写如下停止脚本,保存为stopderper

#!/bin/sh

kill `cat /usr/local/gopath/bin/app.pid`
rm -rf /usr/local/gopath/bin/app.pid

赋权可执行

chmod +x stopderper

然后在路径/etc/systemd/system目录中添加服务脚本derper.service脚本内容如下

cd /etc/systemd/system
vi derper.service
Description=derper服务
After=network.target
 
[Service]
Type=forking
ExecStart=/usr/local/gopath/bin/runderper
ExecStop=/usr/local/gopath/bin/stopderper
 
[Install]
WantedBy=multi-user.target

然后启动服务并设置开机启动,这样就可以守护程序不被恶意停止,依次执行如下命令

systemctl start derper
systemctl enable derper

然后可以观察日志:

tail -f /usr/local/gopath/bin/console.log

当看到有如下输出

2021/09/18 15:04:31 derper: serving on :81 with TLS
2021/09/18 15:04:31 running STUN server on [::]:3478

登录官方tailscale设置如下代码

代码如下:

// Example/default ACLs for unrestricted connections.
{
  // Declare static groups of users beyond those in the identity service.
  "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": [
    // Match absolutely everything. Comment out this section if you want
    // to define specific ACL restrictions.
    { "Action": "accept", "Users": ["*"], "Ports": ["*:*"] },
  ],
  "derpMap": {
    "OmitDefaultRegions": true,
    "Regions": { "900": {
      "RegionID": 900,
      "RegionCode": "mangoderp",
      "Nodes": [{
          "Name": "1",
          "RegionID": 900,
          "HostName":"你的域名",
          "DERPPort": 端口
      }]
    }}
  }
}


打开如下详情页观察

Relays #900 只有这一条说明已经连上了你的derper 并且只启用了你的derper服务器
注意 DERPPort 设置你的自定义端口

重启客户端 然后相互ping通过则说明服务器正常

服务器需要开启tcp 你设置的端口和udp 3478端口

0

评论 (4)

取消
  1. 头像
    dngybeklme
    Windows 10 · Google Chrome

    新车新盘 嘎嘎稳 嘎嘎靠谱

    回复
  2. 头像
    sgnkrjzpwi
    Windows 10 · Google Chrome

    新车新盘 嘎嘎稳 嘎嘎靠谱coinsrore.com

    回复
  3. 头像
    ajranicxtz
    Windows 10 · Google Chrome

    2025年10月新盘 做第一批吃螃蟹的人coinsrore.com
    新车新盘 嘎嘎稳 嘎嘎靠谱coinsrore.com
    新车首发,新的一年,只带想赚米的人coinsrore.com
    新盘 上车集合 留下 我要发发 立马进裙coinsrore.com
    做了几十年的项目 我总结了最好的一个盘(纯干货)coinsrore.com
    新车上路,只带前10个人coinsrore.com
    新盘首开 新盘首开 征召客户!!!coinsrore.com
    新项目准备上线,寻找志同道合 的合作伙伴coinsrore.com
    新车即将上线 真正的项目,期待你的参与coinsrore.com
    新盘新项目,不再等待,现在就是最佳上车机会!coinsrore.com
    新盘新盘 这个月刚上新盘 新车第一个吃螃蟹!coinsrore.com

    回复
  4. 头像
    kwcbmysqvi
    Windows 10 · Google Chrome

    2025年10月新盘 做第一批吃螃蟹的人coinsrore.com
    新车新盘 嘎嘎稳 嘎嘎靠谱coinsrore.com
    新车首发,新的一年,只带想赚米的人coinsrore.com
    新盘 上车集合 留下 我要发发 立马进裙coinsrore.com
    做了几十年的项目 我总结了最好的一个盘(纯干货)coinsrore.com
    新车上路,只带前10个人coinsrore.com
    新盘首开 新盘首开 征召客户!!!coinsrore.com
    新项目准备上线,寻找志同道合 的合作伙伴coinsrore.com
    新车即将上线 真正的项目,期待你的参与coinsrore.com
    新盘新项目,不再等待,现在就是最佳上车机会!coinsrore.com
    新盘新盘 这个月刚上新盘 新车第一个吃螃蟹!coinsrore.com

    回复