前言

在前些日子,写了一篇文章关于headscale服务器的,这次有更深的理解,希望谷歌出来这篇文章的朋友有所帮助

环境

系统debian11 并root用户登录

开启端口

有用的就8080端口其他端口有需要开放

## 服务器服务端口
8080

安装headscale

创建相关目录与文件

mkdir -p /etc/headscale
mkdir -p /var/lib/headscale
touch /var/lib/headscale/db.sqlite
touch /etc/headscale/config.yaml

headscale从 GitHub 的发布页面下载最新的二进制文件重命名为headscale

上传到/root目录

mv /root/headscale /usr/local/bin/
chmod +x /usr/local/bin/headscale

复制Github仓库里的示例配置内容到config.yaml文件`

nano /etc/headscale/config.yaml

配置文件修改内容 如下 证书配置绝对不要双引号直接配置为绝对路径

server_url: http://127.0.0.1:8080
修改为 这选项需要配置域名
server_url: https://he.gao4.top:8080
配置自定义本地证书
tls_cert_path: ""
tls_key_path: ""
修改如下 
tls_cert_path: /root/.acme.sh/he.gao4.top/fullchain.cer
tls_key_path: /root/.acme.sh/he.gao4.top/he.gao4.top.key
配置客户端证书模式
tls_client_auth_mode: relaxed
修改为
tls_client_auth_mode: disabled

创建 SystemD service 配置文件

nano  /etc/systemd/system/headscale.service

内容如下

[Unit]
Description=headscale
After=network.target

[Service]
WorkingDirectory=/etc/headscale
ExecStart=/usr/local/bin/headscale serve
# Disable debug mode
Environment=GIN_MODE=release

[Install]
WantedBy=multi-user.target

重载SystemD配置文件

systemctl daemon-reload

管理headscale


systemctl start headscale.service
systemctl restart headscale.service
systemctl enable headscale.service
systemctl status headscale.service

查看端口占用 这一步可以看到headscale

没有端口占用的话就没启动成功

ss -tulnp|grep headscale

创建命名空间default可以理解为 用户

headscale namespaces create default

Linux端链接服务端

tailscale up --login-server=https://he.gao4.top:8080 --accept-routes=true --accept-dns=false

win下链接服务端

访问你的服务域名比如说我的https://he.gao4.top:8080/windows

查看已创建命名空间

headscale namespaces list

查看所有节点情况

headscale nodes list

删除节点 3 注意带sudo

sudo headscale nodes del -i 3

查看节点5 子网路由是否开启

headscale routes list -i 5

开启节点5的子网路由

headscale routes  enable -i 5 -r 192.168.100.0/24

oopenwrt登录节点关闭dns并通告子网路由网段

tailscale up --accept-dns=false --accept-routes --login-server=https://he.gao4.top:8080 --advertise-routes=192.168.100.0/24
最后修改:2022 年 06 月 05 日
如果觉得我的文章对你有用,请随意赞赏