Skip to content

How the tailnet works

The tailnet is the network’s mesh VPN: it connects zones, the coordination server (HCS) and remote devices. Headscale 🡕 coordinates it, Tailscale 🡕 brings it to life on each node. This page explains who is on it, how packets and DNS queries travel, who can reach what, and how a machine joins. Operational procedures are in VPN.

Headscale distributes information, never traffic: nodes exchange directly with each other, encrypted with WireGuard 🡕.

Diagram
PlaneCarried byContent
ControlHeadscale on the HCS (HTTPS)identities, public keys, addresses, routes, DNS, ACL filters
Dataeach Tailscale client (UDP 41641)the traffic, from one node to another
RelayTailscale public DERP serversthe encrypted traffic, when no direct path exists
  • Nodes punch through NAT to connect directly. UDP port 41641 is open on the HCS and on the gateways’ WAN, which helps behind strict NAT.
  • Without a direct path (filtered UDP, strict NAT on both sides), traffic goes through a DERP relay: always end-to-end encrypted, but slower.
  • HCS unavailable: established tunnels keep working, but nothing changes (new node, new route, new policy) until it is back.

Two kinds of identity coexist : machines, identified by a tag that states their role, and personal devices, attached to their owner.

NodeIdentityObtained byExpiry
HCStag:hcssingle-use key (just tailnet-enroll)never
Zone gatewaytag:gw-<zone>single-use keynever
Administration workstationtag:adminsingle-use keynever
Personal deviceits owner (alice@)sign-in with Kanidm180 days
  • Tags are inferred from the topology : profile hcs, zone gateway, host whose groups contains admin and which enables the Tailscale client.
  • A tagged node belongs to no one (tagged-devices in Headscale).
  • Only accounts of the Kanidm group tailnet connect a device : administrators, members of a zone (group zone-<zone>) and members of an AI space.
  • The free-form tags of a host in etc/config.yaml grant no rights.
  • Each node carries a MagicDNS name : <node>.tailnet.internal.

The tailnet gives every node an address and links the zone subnets. Path of a workstation in the maison zone to a server in the atelier zone:

Diagram
PathRouteMechanism
Workstation of one zone → another zoneits gateway, the tailnet, the remote gatewaysubnet routes
Remote device → a zone’s servicethe tailnet, the zone’s gatewaythe zone’s subnet route
Remote device → global servicethe tailnet, the HCSHCS tailnet address
Node → nodedirect100.64.x.y addresses
Node → Internetits own connectionHCS exit node closed by default
  • Addresses: Headscale assigns them in order, within 100.64.0.0/10 (and fd7a:115c:a1e0::/48). A reinstalled machine (new machine key) gets a new one.
  • Advertised routes: each gateway advertises its zone’s /16. The policy approves it outright for tag:gw-<zone> only: a gateway cannot divert another zone’s subnet.
  • Accepted routes: each client installs the other zones’ /16 in Tailscale’s routing table 52, consulted before the main table. A gateway does not install its own zone there.
  • Without SNAT: a gateway relays without masking the source (--snat-subnet-routes=false). A machine in the zone sees the real tailnet address and answers through its default route, the gateway; hence the gateways’ permissive reverse-path filtering (rule R12 of security).
  • Exit node: the HCS advertises itself as an Internet exit, approved outright, but no rule authorizes it while policy.exitNodeSources is empty.
  • Filtering: the policy applies on arrival. For a zone, its gateway is what filters what enters from the tailnet.

What a gateway lets through is detailed in What crosses a gateway.

Each machine queries a different resolver, but the names of a zone always end up at the same owner: the gateway of that zone.

MachineResolverZone namesGlobal servicesInternet
Machine in a zone, gatewaygateway’s dnsmasq, behind AdGuard Home if enableddnsmasq, or the zone’s gatewaydnsmasq, or the HCS’s unboundPublic DNS, filtered by AdGuard Home
HCSunbound, localthe zone’s gatewayunboundQuad9, encrypted
Remote deviceMagicDNS (100.100.100.100)via the HCS’s unboundvia the HCS’s unboundthe visited network’s resolver
Diagram
  • Gateway : dnsmasq knows the machines of every zone and the declared services. An unknown name from another zone goes to that zone’s gateway (LAN address, through the tailnet) ; the rest of domain.tld goes to unbound, on the HCS.
  • Services of a zone : each declared service <name>.<zone>.domain.tld points to the gateway’s LAN address of the zone, which serves it behind its proxy.
  • Global services served by a zone (git.domain.tld on a gateway) : unbound answers with the LAN address to the tagged machines only, that the policy lets into the zones. The other devices receive the HCS’s public address, which only relays HTTPS. Machines’ tailnet addresses read in Headscale by unbound-tailnet-view.
  • HCS : unbound listens on 127.0.0.1 and on the HCS’s tailnet address, for tailnet addresses only. It forwards <zone>.domain.tld to the gateway’s resolver, at its tailnet address : hence the importance of declaring vpn.ipv4.
  • headscale.domain.tld : never queried from the tunnel it helps to set up, see Control plane bootstrapping.

MagicDNS is the small resolver each Tailscale client embeds, at the address 100.100.100.100. Headscale enables it for the whole tailnet and pushes its settings to it:

SettingValueEffect
Node namestailnet.internalgw-atelier.tailnet.internal → tailnet address, kept up to date by Headscale
Search domaintailnet.internalssh gw-atelier is enough
Split DNSdomain.tld → HCS unboundinternal names go, through the tunnel, to the pivot resolver
Global resolvernonethe rest goes to the device’s usual resolver

A client only uses it as a resolver if it accepts the tailnet’s DNS (--accept-dns).

Machine--accept-dnsMagicDNS role
Personal device, laptop away from its zoneyessystem resolver: node names and split DNS
Laptop reconnected to its zoneclient pausednone, the local gateway takes over
Gatewaynoreverse names of 100.x addresses, for AdGuard Home statistics
HCSyespresent, but the system queries unbound (127.0.0.1)
Zone workstationno clientnone
  • Name nodes outside zones: a laptop on the move reaches gw-atelier directly over the tailnet, without relying on a subnet route or a zone’s DNS. That is what just enter gw-atelier does away from home.
  • Resolve internal names everywhere: split DNS is enough, without routing all DNS through the VPN.
  • Keep the Internet out of the tunnel: if the VPN path weakens, public name resolution holds (why).
  • Leave control to gateways: they keep their own DNS (--accept-dns=false), which their zone and its clients depend on.

A remote device opens a service in the home zone :

Diagram
  1. MagicDNS recognizes domain.tld and forwards the query, through the tunnel, to unbound.
  2. unbound forwards it to the home gateway’s resolver, at its tailnet address.
  3. The answer is the gateway’s LAN address (10.0.1.1).
  4. The device reaches it through the subnet route of the zone ; the policy allows it on port 443 (gateway-maison).

On the tailnet, nothing passes by default. Headscale compiles a policy into filters it pushes to each node; each drops whatever no rule allows. For a zone, filtering happens at its gateway.

The policy is not hand-written: DNF generates it from etc/config.yaml (zones, hosts, users), validates it at build time (headscale policy check), then Headscale hot-reloads it at deployment.

Building blockGenerated content
groupsgroup:admins (profiles admin, nix-admin), group:zone-<zone> (group zone-<zone>), group:space-<host> (members of the AI space of a local zone)
tagOwnerstag:hcs, tag:gw-<zone>, tag:admin, owned by group:admins
hostszone-<zone> (subnet), gateway-<zone> (LAN address of the gateway), each host of a zone (its LAN address), adminDevices, extraHosts
autoApproversroute of each zone → tag:gw-<zone> ; exit node → tag:hcs
aclsthe rules below
#SourceDestinationPurpose
1tagged machines, zone subnetsall machines and zones, all portsinfrastructure : DNS, monitoring, backups, deployment
2personal devices (autogroup:member)HCS, ports 53 and 443internal DNS, global services
3group:adminsgateways of all zones, port 443the services of all zones
4group:zone-<zone>gateway of the zone, port 443the services of its zones
5group:space-<host>gateway of the space’s zone, port 443the services of that zone
6personal devicesdevices of the same ownerbetween its own devices
7tag:admin, administration workstations, adminDevicesall machines and zones, port 22SSH administration
8policy.exitNodeSourcesInternetthe HCS exit node, if it is open
9policy.extraAclsfreethe network’s own needs
  • SSH follows the workstation, not the person : an administrator on their phone has no SSH, unless the device is declared in adminDevices.
  • gateway-<zone> in addition to the tag : the services of a zone resolve to the LAN address of its gateway, which tag:gw-<zone> does not cover (it designates only its tailnet addresses).
  • An empty group disappears from the policy : a rule citing it would cause the whole rule to be denied.
  • Open mode (policy.enforce = false) : a single rule allows everything. Reserved for a migration, while nodes are being tagged.

The options that adjust the policy are described in Adapt the access policy.

A node proves once to Headscale that it is allowed in. After that, its node key is enough: forever if tagged, until expiry for a personal device.

KeyWhereRole
Machine keythe node’s /var/lib/tailscaleidentifies the machine to Headscale; lost on reinstall
Node keythe node’s /var/lib/tailscaleencrypts traffic; Headscale publishes its public part to peers
Pre-authorized keycreated by Headscaleauthorizes enrollment without a browser, with the tags it carries
OIDC sessionKanidmauthorizes a personal device’s enrollment

just tailnet-enroll <host> enrolls a machine, without a shared key:

Diagram
  • Forced tags: the HCS creates the key for the host’s declared tags (dnf-tailnet-enroll), whatever the caller asks for.
  • Single use, 10 minutes: worthless once served.
  • No trace: the key goes through a pipe, never through a command line, a variable, a disk or sudo’s input/output journal (rules NOLOG_INPUT and NOLOG_OUTPUT).
  • Held in memory: dnf-tailnet-join puts it in /run/tailscale-enroll, tailscaled-autoconnect uses it (tailscale up --force-reauth) then erases it.
  • Portable in pause in its zone: it registers without routes or DNS, then pauses again.
  • Final control: adopt sets the declared tags and name, replaces an old offline node with the same name, and the recipe checks the result.
  1. The Tailscale application contacts Headscale, which redirects it to Kanidm.
  2. Kanidm only accepts members of the tailnet group ; Headscale checks this too.
  3. Headscale displays the device (name, machine key) and waits for its confirmation (Confirm registration).
  4. The device is registered in the person’s name (alice@) and expires after 180 days (nodeExpiry) : the person then reconnects.