环境更好的内网穿透方案Ubuntu18.04.3(理论上所有支持systemctl的Linux发行版都可以搭建)8080端口版本是v0.11注意事项官方当前时间也是这个文章写的时间。最新版本的配置文件不兼容。版本号是v0.12.1。构建过程下载二进制文件和源代码headscale_0.11.0_linux_amd64[2]源代码(zip)[3]文件上传headscale_0.11.0_linux_amd64文件到/usr/local/bin并重命名为headscale并授予执行权限$chmod755/usr/local/bin/headscale登录服务器创建目录和文件$mkdir/etc/headscale$cd/etc/headscale$touchdb.sqlite$touchconfig.yaml$touchderp.yaml注意在0.12版本,无需生成密钥,会自动生成。也许你需要安装wireguard。我们是0.11版本,所以需要手动生成$apt-getupdate$apt-getinstallwireguard$wggenkey>private.key最终目录结构如下root@10-255-1-181:/etc/headscale#tree.├──config.yaml├──db.sqlite├──derp.yaml└──private.key0目录,4个文件root@10-255-1-181:/etc/headscale#填写config.yaml的内容,内容来自解压后的v0.11.0.zip压缩包config-example.yaml内容config-example填写derp.yaml的内容来自解压后的v0.11.0.zip压缩包derp-example。yaml内容derp-examplewriteheadscale.service#/etc/systemd/system/headscale.service[Unit]Description=headscaleAfter=network.target[Service]WorkingDirectory=/etc/headscaleExecStart=/usr/local/bin/headscaleserve#禁用调试模式Environment=GIN_MODE=release[Install]WantedBy=multi-user.target重载服务并设置启动$systemctldaemon-reload$systemctlenableheadscale$systemctlstartheadscalestatus最后附上我的配置文件参考[4]功能先,查看帮助文件,帮助组网和互联功能。在控制终端命令行下创建命名空间myfirstnamespace。你能理解用户吗?$headscalenamespacescreatemyfirstnamespace客户端执行:$tailscaleup--login-serverYOUR_HEADSCALE_URL##示例tailscaleup--login-serverhttp://headscale.gao4.top:8080YOUR_HEADSCALE_URL是服务器链接回到服务器命令行,执行以下命令,意思是添加一个myfirstnamespace命名空间,YOURMACHINEKEY就是上面命令返回的key很难找到,可以参考这本英文教材:https://leffler.tech/2021/10/22/headscale-notes/Linux下设置Ipv4和ipv6路由转发$echo'net.ipv4.ip_forward=1'|tee/etc/sysctl.d/ipforwarding.conf$echo'net.ipv6.conf.all.forwarding=1'|tee-a/etc/sysctl.d/ipforwarding.conf$sysctl-p/etc/sysctl.d/ipforwarding.conf客户端通告网段$tailscaleup--advertise-routes=192.168.0.0/24--login-server=https://headscale.domain.com查看路由是否开启,可以看到结果关闭:$headscalerouteslist--namespace$NAMESPACE$NODE_NAMRoute||启用192.168.0.0/24|true其他节点查看路由结果$tailscaleup--accept-routes--login-server=https://headscale.domain.com参考如何设置或迁移头标[5]运行头标[6]
