The VPN (Headscale / Tailscale)
The VPN links the zones, the coordination server and remote devices : Headscale 🡕 coordinates from the HCS, Tailscale 🡕 is the client on each node. This page gathers the operating procedures. Routing, DNS, MagicDNS, access policy and keys are explained in How the tailnet works.
Enable the VPN
Section titled “Enable the VPN”Enabling coordination and declaring the HCS (profile: hcs) is enough :
network: coordination: enable: true hostname: "hcs" domain: "headscale"The role of each node follows from the topology :
| Node | Identity | Role |
|---|---|---|
| HCS | tag:hcs | coordination, pivot DNS, global services, exit node (closed) |
| Gateway | tag:gw-<zone> | subnet router : advertises the /16 of its zone |
| Admin workstation | tag:admin | SSH to all machines |
| Personal device | its owner | services, according to its groups |
An admin workstation is a host whose groups contains admin and whose host file enables the client :
darkone.service.tailscale.enable = true;darkone.service.tailscale.autoPauseOnLan.enable = true;autoPauseOnLan pauses the client when the laptop is plugged into a zone (NetworkManager required).
Enroll a machine
Section titled “Enroll a machine”Machines join the tailnet without a shared key : the HCS creates a single-use key
for each one, with its declared tags. just configure handles it,
so does just full-install. The recipe alone can be rerun at any time :
just tailnet-enroll gw[ DNF ] TAILNET • gw not enrolled, backend NeedsLogin: sending a single-use key...[ DNF ] TAILNET • gw: gw tag:gw-maison 100.64.0.8It is idempotent :
| Situation | Effect |
|---|---|
| Node enrolled, name and tags compliant | nothing (already enrolled) |
| Tags or name differ | corrected on the HCS, without reconnection |
| Never enrolled, deleted or reinstalled | new key, registration |
| Old node with the same name offline | deleted, the new one takes the name |
| Old node with the same name online | refused : two machines carry this name |
| Host without Tailscale client | ignored |
The mechanism is detailed in Activation keys and enrollment.
Register a gateway
Section titled “Register a gateway”A gateway enrolls like any machine ; two points are specific to it.
-
Check the route of its zone
The gateway advertises the
/16of its zone, which the policy approves automatically fortag:gw-<zone>. On the HCS :Fenêtre de terminal sudo headscale nodes list-routes -
Declare its tailnet address
The HCS reaches the zone resolver through this address (pivot DNS), as do the services that target it (backups, monitoring). Read it from the output of
just tailnet-enroll, then report it :etc/config.yaml zones:maison:gateway:vpn:ipv4: "100.64.0.8" -
Propagate the address
Fenêtre de terminal just generatejust apply hcsjust apply gw-atelier # passerelle du poste d'administration, si autre zonejust apply gwThe admin workstation resolves the short name
gwthrough its zone’s gateway. If not redeployed sincegwwas added, it ignores it andjust apply gwfails.Applying the gateway closes its public SSH (WAN, open until then). Also redeploy the other gateways and the hosts targeting this address.
HeadscaleNodeDriftreports a declared address that no longer matches.
Connect a personal device
Section titled “Connect a personal device”A smartphone or personal computer connects with the Kanidm identity of its owner : no key, no manual validation.
| Can connect | Condition in etc/config.yaml |
|---|---|
| Administrator | admin or nix-admin profile |
| Member of a zone | zone-<zone> group |
| Member of an AI space | in the users of an ai-space host |
These accounts form the Kanidm group tailnet, provisioned automatically ; Kanidm
refuses the others. To open access, add the group to the user,
regenerate, then just apply hcs. The user then follows Connect a
device.
The device joins the web services (HTTPS) of its zones, of those of its AI spaces and of the HCS, nothing else. A Samba share, a printer or SSH requires a rule : see Adapting the access policy.
The device belongs to the person (alice@) and expires after 180 days :
they then reconnect with their login.
Removing access : remove the group, just apply hcs, then delete their
devices. Otherwise, they keep the DNS and HTTPS of the HCS until they expire
(alert HeadscaleUnexpectedNode).
sudo headscale nodes list # appareils, propriétaires, expirationsudo headscale nodes expire -i <id> # forcer une reconnexionsudo headscale nodes delete -i <id> # retirer l'appareilAdapt the access policy
Section titled “Adapt the access policy”The policy is generated from the topology : its rules are detailed in Access policy. Options adjust it, on the HCS :
Option darkone.service.headscale. | Default | Effect |
|---|---|---|
policy.adminDevices | { } | personal devices allowed SSH : name → tailnet IPv4 |
policy.exitNodeSources | [ ] | sources allowed to exit to the Internet via the HCS |
policy.extraHosts | { } | aliases of undeclared devices : name → CIDR |
policy.extraAcls | [ ] | rules added after the generated rules |
policy.enforce | true | false : everything allowed, for migration only |
nodeExpiry | "180d" | expiry of personal devices (0 : never) |
Each declared host of a zone is already an alias (its name → its LAN address) :
a rule targets nas:445 without going through extraHosts.
darkone.service.headscale.policy = {
# SSH depuis le téléphone d'Alice (adresse lue dans `headscale nodes list`) adminDevices.phone-alice = "100.64.0.9";
# Exit node du HCS ouvert aux administrateurs exitNodeSources = [ "group:admins" ];
# Imprimante réseau pour tous les appareils personnels extraHosts.printer = "10.0.4.10/32"; extraAcls = [ { action = "accept"; src = [ "autogroup:member" ]; dst = [ "printer:631" ]; }
# Partage Samba du serveur `nas` (hôte déclaré) pour Alice { action = "accept"; src = [ "alice@" ]; dst = [ "nas:445" ]; } ];};Then just apply hcs : the policy is checked at build time, and Headscale
reloads it without restarting.
Administration
Section titled “Administration”On the HCS (just enter hcs) :
| Command | Usage |
|---|---|
sudo headscale nodes list | nodes, owner, tags, addresses, expiry |
sudo headscale nodes list-routes | advertised and approved routes |
sudo headscale nodes rename -i <id> <nom> | rename a node |
sudo headscale nodes expire -i <id> | force a reconnection |
sudo headscale nodes delete -i <id> | delete a node |
sudo headscale users list | personal device owners |
sudo headscale preauthkeys list | pre-authorized keys : tags, usage, expiry |
sudo headscale policy get | served policy |
sudo dnf-tailnet-enroll status <hôte> | declared identity of a host |
Tags and routes are not set by hand : just tailnet-enroll sets the declared
tags, the policy approves the routes. The other client settings (advertised routes,
Tailscale SSH disabled, exit node) are realigned by
tailscaled-autoconnect, at startup and during deployments that change them.
Inspect and troubleshoot
Section titled “Inspect and troubleshoot”On a node
Section titled “On a node”| Command | Answers |
|---|---|
tailscale status | peers, online or not, direct path or relay |
tailscale ping <nœud> | real path : via <ip>:41641 (direct) or via DERP |
tailscale whois <ip> | node, tags or owner behind an address |
tailscale dns status | MagicDNS, split DNS, search domains received |
journalctl -u tailscaled-autoconnect | last record or realignment of settings |
Test a policy
Section titled “Test a policy”Without a --bypass… option, headscale policy check compiles a file against the real nodes and runs its tests block, without touching the policy in place.
-
Start from the served policy :
Fenêtre de terminal sudo headscale policy get > /tmp/policy.json -
Add a
testsblock : a source, then the expected destinations, each a single host (address and port) :"tests": [{ "src": "alice@", "accept": ["100.64.0.8:443"], "deny": ["100.64.0.8:22"] }] -
Check :
Fenêtre de terminal sudo headscale policy check -f /tmp/policy.json
Common failures
Section titled “Common failures”| Symptom | Check | Remedy |
|---|---|---|
TailscaleUnhealthy, backend NeedsLogin | tailscale status on the node | just tailnet-enroll <hôte> |
Login showing headscale auth register | HeadscaleOidcFallback alert | sudo systemctl restart headscale on the HCS |
| Kanidm refuses access to Headscale VPN | user’s groups | admin profile, zone-<zone> or AI space member, just apply hcs |
| Zone unreachable from the tailnet | headscale nodes list-routes | gateway enrolled with its tag, route approved |
| Zone service refused to a device | user’s groups, tailscale whois <ip> | add zone-<zone>, just apply hcs |
| Non-web service unreachable (Samba, ping) | policy rules | policy.extraAcls rule |
| SSH refused on a tailnet address | tag:admin workstation or adminDevices device | declare the device |
| Internal names unresolved outside the zone | tailscale dns status | enable “Use Tailscale DNS” |
| Login page not found | “Use Tailscale DNS” active | disable it for the duration of the login |
| Slow traffic | tailscale ping shows via DERP | outbound UDP filtered, or strict NAT on both sides |
no declared tailnet identity | tagged host, HCS deployed from its declaration | just apply hcs |
named … is online, not deleting it | two machines carry the same name | turn off the old one or rename the host |
Audit and alerts
Section titled “Audit and alerts”Every 15 minutes, headscale-audit compares the real nodes to the declared topology, without changing anything. Details of the discrepancies are in its log :
journalctl -u headscale-audit -n 20| Alert | Reports | After |
|---|---|---|
HeadscaleNodeDrift | HCS or gateway missing, wrong tags, address different from the declared one | 30 min |
HeadscaleUnexpectedNode | undeclared tagged node, or device of an account outside the tailnet group | immediately |
HeadscalePolicyInvalid | policy refused, or served policy different from the file | 30 min |
HeadscaleOidcFallback | Kanidm absent at Headscale startup : OIDC connections cut | immediately |
HeadscaleNodeExpiring | personal device expiring within 7 days | 1 h |
HeadscaleAuditStale | audit without success for more than one hour | immediately |
All are warning, on the Prometheus that monitors the HCS. An absent admin workstation is not an anomaly ; when present, its tags are checked.
Client self-repair
Section titled “Client self-repair”A tailscaled can silently drop off Headscale : the control connection is lost while the service stays “active”, and a gateway’s subnet becomes unreachable. A local watchdog detects and fixes this case, on every Tailscale client.
| Aspect | Behavior |
|---|---|
| Probe | every 60 s : tailscale status (backend, online state) |
| Debounce | 3 consecutive failed probes (~3 min) before acting |
| Fix | restarts tailscaled, which reconnects to the control plane |
| Anti-loop | one fix per 10 min window |
| Unenrolled node | no restart (NeedsLogin) : just tailnet-enroll |
| Paused laptop | watchdog stopped, metric removed |
| Observability | dnf_tailscale_healthy, dnf_tailscale_selfheal_restarts_total (textfile node_exporter) |
Two alerts accompany the mechanism :
TailscaleUnhealthy: still disconnected after 10 min, despite the fix ;TailscaleFlapping: more than 3 fixes in one hour.
Control plane bootstrap
Section titled “Control plane bootstrap”On a gateway, dnsmasq sends every domain.tld query to the HCS resolver through the tailnet : the client would need the VPN to find the server that brings up the VPN. At boot, moreover, the local resolver is not yet listening.
Each Tailscale client therefore receives the HCS public address in its /etc/hosts, derived from etc/config.yaml (the HCS itself is excluded). dnsmasq answers this name from that file, without ever forwarding it :
grep headscale /etc/hosts # 203.0.113.10 headscale.domain.tldThe client thus connects without any resolver, including when local DNS is down, precisely when self-repair must be able to act.
Outside a zone
Section titled “Outside a zone”- Personal device : see Connect a personal device.
- Admin laptop : when away, it reaches all zones through the tailnet (
just enter <hôte>). Plugged back into a zone, its client pauses and the local gateway takes over again.