tailscale创建derp中继服务器

服务器环境

  1. Ubuntu Server 24.04 LTS 64位

安装步骤

  1. 在安全组中放开 TCP:12345 UDP:3478

  2. sudo su 切换到root用户

  3. curl -fsSL https://tailscale.com/install.sh | sh 安装tailscale

  4. 安装完成运行 tailscale up 会让你登陆 连接复制出来去登陆就好 这是为了后面derper启动加验证 防止白嫖

  5. snap install go --classic 安装go环境

  6. go env -w GOPROXY=https://goproxy.cn,direct 设置国内源

  7. go install tailscale.com/cmd/derper@latest 安装derper服务

  8. cp ~/go/bin/derper /usr/bin/ 复制命令到全局

  9. DERP_IP="服务器ip" 设置环境变量

  10. openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes -keyout ${DERP_IP}.key -out ${DERP_IP}.crt -subj "/CN=${DERP_IP}" -addext "subjectAltName=IP:${DERP_IP}" 生成证书

  11. mkdir cert 创建证书文件夹

  12. mv *.crt *.key cert/ 移动到证书文件夹里

  13. derper --hostname="服务器ip" -certmode manual -certdir ./cert --verify-clients 启动derper服务

  14. 进入tailscale控制台找 Access Controls,加入下面的内容

    "derpMap": {
        //"OmitDefaultRegions": true,  //加入这个会只用自己的节点
        "Regions": {
            "901": {
                "RegionID":   901,
                "RegionCode": "song",
                "RegionName": "随便起名",
                "Nodes": [
                    {
                        "Name":     "随便起名",
                        "RegionID": 901,
                        "HostName":         "随便起名", //这个随便写
                        "IPv4":             "12.12.12.12", //改成自己的IP -- 使用ipv6 可以把这个注释掉
                        "IPv6":             "xxx" //服务器ipv6地址
                        "InsecureForTests": true,
                    },
                ],
            },
        },
    },
    
  15. tailscale netcheck 查看如果只有自己刚才添加的节点 说明添加成功

  16. 使用ipv6 路由器需要开启ipv6模式

  17. derper -a :4453 --hostname="xxxx" -http-port -1 -certmode manual -certdir /home/ubuntu/cert --verify-clients -a DERP端口重定义 -http-port -1 不用https端口

posted @ 2025-07-10 12:25  狂客  阅读(253)  评论(0)    收藏  举报