These notes cover setting up Headscale on Gentoo Linux and moving the Tailscale control plane onto my own server.
Installation
Headscale is already in the Gentoo repository, so install it directly:
emerge -av headscale
Configuration
Edit /etc/headscale/config.yaml and at minimum change the listen address, server_url and IP pool:
unix_socket: /run/headscale/headscale.sock
server_url: http://<your-ip>:8080
listen_addr: 0.0.0.0:8080
prefixes:
v4: 100.64.0.0/10
v6: fd7a:115c:a1e0::/48
Headscale 0.23 renamed
ip_prefixestoprefixes, and thenode/usercommands became plural. The syntax below targets 0.23 and later; older versions need the old syntax.
Start it and enable it at boot:
systemctl start headscale
systemctl status headscale
systemctl enable headscale
Create a user:
headscale users create homelab
Joining a Client
On the Linux client:
tailscale up --login-server=http://<your-ip>:8080 --accept-routes=true --accept-dns=false
Open the login link it prints; the page shows a registration command like this:
headscale nodes register --user homelab --key nodekey:df596243a3e117f45dbdcc7bba8741297e68efd731798c252b65586cacddf756
List nodes:
headscale nodes list
Running Your Own DERP Relay
DERP can be deployed independently of Headscale, and you can run several of them. I use an image I packaged myself; the source is at slchris/derp-server.
Deploying DERP requires:
- A VPS with a public IP; machines behind NAT need port forwarding
- A domain with A/AAAA/CNAME records pointing at that machine
- A certificate
Get a certificate with certbot first:
docker run -it --rm --name certbot \
-p 80:80 \
-v "/etc/letsencrypt:/etc/letsencrypt" \
-v "/var/lib/letsencrypt:/var/lib/letsencrypt" \
certbot/certbot certonly --standalone --agree-tos -m [email protected] -d example.com
Start derper:
docker run --restart always \
--name derper -p 12345:443 -p 3478:3478/udp \
-v /etc/letsencrypt/live/example.com/fullchain.pem:/app/certs/example.com.crt \
-v /etc/letsencrypt/live/example.com/privkey.pem:/app/certs/example.com.key \
-e DERP_CERT_MODE=manual \
-e DERP_DOMAIN=example.com \
-d ghcr.io/slchris/derp-server:v1
Replace
example.comwith your domain, and update the DERP config in Headscale to match.
Write the DERP config on the Headscale server at /etc/headscale/derp.yaml:
regions:
800:
regionid: 800
regioncode: hangzhou
regionname: Hangzhou, China
nodes:
- name: hz
regionid: 800
hostname: hz.plz.ac
stunport: 3478
derpport: 12345
Reference it from the main config /etc/headscale/config.yaml:
derp:
paths:
- /etc/headscale/derp.yaml
auto_update_enabled: true
update_frequency: 24h
Restart Headscale:
systemctl restart headscale
Restart the client as well, then check the connection:
systemctl restart tailscaled
tailscale netcheck
Comments