Skip to content

VPN (Headscale / Tailscale)

The VPN connects all zones and remote machines: Headscale 🡕 is the coordinator (on the HCS), Tailscale 🡕 is the client on each node. Overview in Network.

Enabling coordination and declaring the HCS (profile: hcs) is sufficient:

etc/config.yaml
network:
coordination:
enable: true
hostname: "hcs"
domain: "headscale"

Roles are derived from each host’s profile:

  • HCS: mesh coordination (Headscale).
  • Gateway: subnet router + exit node: publishes its zone’s subnet.
  • Other nodes: Tailscale clients.
  1. On the HCS: create the attachment user and a key

    Fenêtre de terminal
    just enter hcs
    sudo headscale users create nix --display-name "Nix Admin" --email "nix@domain.tld"
    sudo headscale preauthkeys create --reusable --expiration "1d" --user 1
  2. Fill in the key in secrets

    Fenêtre de terminal
    just sops # edits usr/secrets/secrets.yaml → tailscale/authKey key

    The gateway then registers automatically (on the next just apply).

  3. On the gateway: advertise the subnet

    Fenêtre de terminal
    sudo tailscale set --advertise-routes 10.0.0.0/16 --advertise-exit-node \
    --accept-routes --accept-dns=false --ssh --snat-subnet-routes=false
  4. On the HCS: approve the routes

    Fenêtre de terminal
    sudo headscale nodes list # find the gateway ID
    sudo headscale nodes approve-routes --identifier <id> --routes 10.0.0.0/16

The headscale command (alias h = sudo headscale) on the HCS:

Fenêtre de terminal
sudo headscale users list # users
sudo headscale nodes list # connected clients
sudo headscale nodes routes # advertised / approved routes

To join the network from outside a zone, see Connecting from outside.