GuidesNetwork and VPNHeadscale for Tailscale

Headscale: run your own Tailscale control server with Docker

Headscale on Debian 13, the open-source control server for Tailscale's apps, in rootless Docker under a user of its own, with its own relay, so your private network runs without Tailscale's servers.

Tested on Docker steps follow the tested rootless Docker base guide on Debian 13 with Docker Engine 29.10.1, Compose 5.8.1 and rootlesskit 3.3.0; the app version and app-specific behaviour are from the tested Podman guide on a Melonslab server. Not re-tested end to end under Docker. Updated November 28, 2026

Recommended server for this guide

SSD RAID 1 · ECC DDR4 · 10 Gbit

VC-P Alloy · 2 vCPU · 8 GB Memory · 60 GB Storage

Month to month, no lock-in 7-day money-back guarantee

€8.99/mo

Deploy now

Quick install on a fresh VM

This command sets up a rootless container engine and a directory for this service. Podman is the default; add --engine docker to the command to use Docker instead.

curl -fsSL https://www.melonslab.com/install/rootless.sh | bash -s -- --app headscale-docker --manifest headscale --sha256 6ed2cdfc0b21d5fe79462e2f4f8b7ec715045cf7cda3215f65f8934bb8a81fb6
View the script

SHA-256: 97785be3e3e91393181a4a7caeab5f4b52803bf52e960dd488945cb38c6473a2

Run this guide on Melonslab

We ran every step below on our own server. For this workload we recommend VC-P Alloy at €8.99/mo. Order it, pick Debian 13, and follow the guide.

  1. 1. Order the server. Use the button below to order the recommended plan. Choose Debian 13 when the installer asks for an operating system.
  2. 2. Add IPv4 if needed. Add it on the order form when the guide publishes a service on the internet. It is a paid add-on, not included in the plan.
  3. 3. Connect over SSH. Log in as root with the address and credentials from your order, then run the commands below.
  4. 4. Follow the verified steps. Every command in this guide was run on a Melonslab server before it was published.
Deploy now
On this page

What you will set up

Tailscale joins your devices into one private network, a tailnet, wherever each of them is. Devices connect to each other directly, encrypted with WireGuard, and each gets a fixed address and a name. A control server keeps the list of devices and hands out their keys. Normally Tailscale Inc. runs it, and relays traffic for devices that cannot reach each other directly.

Headscale is an open-source control server you run yourself. The Tailscale apps work with it as they are: you only point them at your server. The list of your devices stays on your server, and so does the relay, so no part of your tailnet goes through Tailscale's servers. The Tailscale apps do send their own logs to Tailscale, until you turn that off on each device (step 7).

This Docker version follows the tested rootless Docker base guide on Debian 13. Here it runs as a Compose service under a user of its own called headscale, behind Caddy from the Docker guide. Only the relay's address check, STUN, is open to the internet directly. The results below come from the tested Podman guide on a Melonslab server and were not measured again under Docker.

In that test on a Melonslab server with Debian 13:

  • Two Tailscale 1.104.7 clients on Linux joined: one with a key, and one through the login link, as phones and laptops do.
  • A client at home reached one on the server directly, and through the server's own relay when UDP between them was blocked.
  • STUN reported the home client's real public address, and device names resolved with MagicDNS.
  • Headscale logged the client's real address, and everything came back after a reboot.
  • With a policy, a device reached only the port the policy allowed. A port that ufw blocked from the internet answered over the tailnet once the policy allowed it.
  • A Linux client connected to log.tailscale.com until its logging was turned off.

In that test, Headscale used about 50 MB of memory. The steps for phones, Windows and macOS follow Headscale's own documentation.

Before you start

You need:

  • a server set up as in the Docker guide, with Caddy running;
  • an A record and an AAAA record for headscale.example.com pointing at your server;
  • the Tailscale app on each device, version 1.80 or newer, from tailscale.com/download.

The examples use headscale.example.com, 203.0.113.10 for your server's IPv4 address and 2001:db8:1f::a for its IPv6 address. ip -brief address show eth0 shows yours. Replace them throughout.

Headscale is a tailnet for your devices to reach each other. To browse the internet through your server instead, see the WireGuard guide.

1. Open the STUN port

Devices ask the relay on UDP port 3478 which public address they appear from, which helps them connect directly. As root, if you use ufw as in the security guide:

ufw allow 3478/udp

coturn from the calls guide also uses port 3478. If you run it, use 3479 here and in steps 3 and 4 instead.

2. Create the user

useradd -m -s /bin/bash headscale
loginctl enable-linger headscale
uid=$(id -u headscale)

The uid is looked up so the commands below work for any user. Keep it in this shell. Everything up to step 5 runs as headscale.

3. Write the configuration

As root, create the app directory:

mkdir -p /home/headscale/headscale/data

Create /home/headscale/headscale/config.yaml:

server_url: https://headscale.example.com
listen_addr: 0.0.0.0:8080
metrics_listen_addr: 127.0.0.1:9090
grpc_listen_addr: 127.0.0.1:50443
# Caddy's connections reach the container from the server's own IPv4 address.
trusted_proxies:
  - 203.0.113.10/32

noise:
  private_key_path: /var/lib/headscale/noise_private.key

prefixes:
  v4: 100.64.0.0/10
  v6: fd7a:115c:a1e0::/48

derp:
  server:
    enabled: true
    region_id: 999
    region_code: headscale
    region_name: Headscale
    stun_listen_addr: ":3478"
    private_key_path: /var/lib/headscale/derp_server_private.key
    ipv4: 203.0.113.10
    ipv6: 2001:db8:1f::a
  # Only this server relays traffic, not Tailscale's public relays.
  urls: []

database:
  type: sqlite
  sqlite:
    path: /var/lib/headscale/db.sqlite

dns:
  magic_dns: true
  base_domain: tail.example.com
  nameservers:
    global:
      - 9.9.9.9
      - 149.112.112.112
      - 2620:fe::fe
      - 2620:fe::9

What the parts do:

  • trusted_proxies lets Headscale log each device's real address, which Caddy passes on.
  • prefixes are the address ranges Tailscale normally uses for tailnets.
  • derp switches on Headscale's relay. It carries traffic between devices that cannot connect directly, still encrypted end to end. urls: [] leaves Tailscale's public relays out, so your server is the only relay. To keep theirs as a fallback, list https://controlplane.tailscale.com/derpmap/default under urls instead.
  • dns gives every device a name, such as laptop.tail.example.com. base_domain must not be example.com itself, because the server's own name is under it, so a subdomain like tail.example.com is used. Lookups for other names go to Quad9.

4. Describe the container

Create /home/headscale/headscale/compose.yaml:

services:
  headscale:
    image: docker.io/headscale/headscale:0.29
    container_name: headscale
    command: serve
    read_only: true
    tmpfs:
      - /var/run/headscale
    volumes:
      - /home/headscale/headscale/config.yaml:/etc/headscale/config.yaml:ro
      - /home/headscale/headscale/data:/var/lib/headscale
    # Control and relay, reached through Caddy only
    ports:
      - "127.0.0.1:8091:8080"
      # STUN, open to the internet
      - "3478:3478/udp"
    restart: always

Start it as the user:

chown -R headscale:headscale /home/headscale/headscale
runuser -u headscale -- env HOME=/home/headscale XDG_RUNTIME_DIR=/run/user/$uid \
  DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
  bash -lc 'cd /home/headscale/headscale && docker compose up -d && docker compose logs headscale'

The log shows stun server started at [::]:3478 and listening and serving HTTP on: 0.0.0.0:8080. A warning that it is listening without TLS is expected: Caddy handles HTTPS.

5. Put Caddy in front

As root, switch to runuser -u caddy -- /bin/bash, and add these two blocks to the end of ~/Caddyfile:

http://headscale.example.com {
    # Tailscale checks for captive portals here
    handle /generate_204 {
        respond 204
    }
    handle {
        redir https://{host}{uri}
    }
}

headscale.example.com {
    reverse_proxy 127.0.0.1:8091 {
        header_up True-Client-IP {remote_host}
        header_up X-Real-IP {remote_host}
    }
}

The first block answers the check Tailscale makes to find out whether a Wi-Fi network is holding traffic back until you log in, and sends everything else to HTTPS. The two header_up lines replace any address a device claims for itself with the one Caddy sees, so nobody can fake theirs in Headscale's log.

Restart Caddy with runuser -u caddy -- env HOME=/home/caddy XDG_RUNTIME_DIR=/run/user/$(id -u caddy) DOCKER_HOST=unix:///run/user/$(id -u caddy)/docker.sock PATH=/usr/bin:/bin bash -lc 'cd /home/caddy/caddy && docker compose restart caddy', and check from any computer:

curl https://headscale.example.com/health

It answers {"status":"pass"}.

6. Create a user

As root, run the commands below as headscale. Every device belongs to a user. Create one, and list the users to see its ID:

runuser -u headscale -- env HOME=/home/headscale XDG_RUNTIME_DIR=/run/user/$uid \
  DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
  bash -lc 'cd /home/headscale/headscale && \
    docker compose exec headscale headscale users create anna && \
    docker compose exec headscale headscale users list'

7. Connect your devices

Each app opens a page on your server with a command to run. Run it as the headscale user, with USERNAME replaced by the user from step 6, anna here:

runuser -u headscale -- env HOME=/home/headscale XDG_RUNTIME_DIR=/run/user/$uid \
  DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
  bash -lc 'cd /home/headscale/headscale && \
    docker compose exec headscale headscale auth register --auth-id hskey-authreq-... --user anna'

It answers Node ... registered, and the device joins. How to start from each app:

  • Linux: sudo tailscale up --login-server https://headscale.example.com, and open the link it prints.
  • Windows: in PowerShell, tailscale login --login-server https://headscale.example.com.
  • macOS: tailscale login --login-server https://headscale.example.com, or hold Option, click the Tailscale icon, and under Debug, Custom Login Server, choose Add Account.
  • Android: open the settings menu at the top right, then Accounts. In the three-dot menu, choose Use an alternate server, and enter https://headscale.example.com.
  • iPhone and iPad: tap the account icon at the top right and Log in…. In the options menu, choose Use custom coordination server, and enter https://headscale.example.com.

https://headscale.example.com/apple and /windows show the same steps for those systems.

For a server, or any device without a browser, make a key instead. --user takes the ID from users list:

runuser -u headscale -- env HOME=/home/headscale XDG_RUNTIME_DIR=/run/user/$uid \
  DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
  bash -lc 'cd /home/headscale/headscale && \
    docker compose exec headscale headscale preauthkeys create --user 1'

The key starts with hskey-, and works once within an hour. On the device:

sudo tailscale up --login-server https://headscale.example.com --authkey hskey-...

Tailscale's logs. The Tailscale app sends its logs to Tailscale's server, log.tailscale.com, even when it uses Headscale. We saw a Linux client connect there as soon as it started. To turn that off on Linux, add this line to /etc/default/tailscaled, and run sudo systemctl restart tailscaled:

TS_NO_LOGS_NO_SUPPORT=true

With it, our client made no more connections to log.tailscale.com. It is the same as starting tailscaled with --no-logs-no-support. The name says the price: Tailscale cannot help with a problem it has no logs of, which matters little with Headscale. For Windows, macOS and phones, Tailscale's documentation on client logging describes the settings; we tested Linux only.

8. Check it

On any connected device:

tailscale status
tailscale ping laptop
tailscale netcheck

tailscale status lists every device with its address. tailscale ping answers pong from laptop (100.64.0.1) via 203.0.113.10:41641 or similar for a direct connection, or via DERP(headscale) when the traffic goes through your relay. tailscale netcheck shows Nearest DERP: Headscale, and your public IPv4 address under IPv4, as STUN saw it. Run on the server that hosts Headscale, it shows an address starting with 169.254, because the container sees local connections that way; test from another machine.

Devices reach each other by name, laptop.tail.example.com, as long as the app is allowed to set DNS, which it is by default. Every device can reach every other device on the tailnet, on every port. Step 9 limits that.

9. Limit who reaches what

Out of the box, every device on the tailnet reaches every port on every other device. A policy limits that. As headscale, create /home/headscale/headscale/policy.hujson, here with the user anna from step 6 as the admin, and 100.64.0.1 as the address of a server on the tailnet, which tailscale status shows:

{
  // Names for addresses, used in the rules below
  "hosts": {
    "server": "100.64.0.1/32"
  },
  "acls": [
    // anna reaches every device, on every port
    { "action": "accept", "src": ["anna@"], "dst": ["*:*"] },
    // everyone reaches the server's web port, and nothing else
    { "action": "accept", "src": ["*"], "dst": ["server:443"] }
  ]
}

Each rule lets the devices in src reach the addresses and ports in dst, and everything else is refused. anna@ means every device of the user anna, * every device, and server:443 port 443 on the address named server. Add this to the end of /home/headscale/headscale/config.yaml:

policy:
  mode: file
  path: /etc/headscale/policy.hujson

And this line under volumes: in compose.yaml:

      - /home/headscale/headscale/policy.hujson:/etc/headscale/policy.hujson:ro

Restart, and check the policy:

runuser -u headscale -- env HOME=/home/headscale XDG_RUNTIME_DIR=/run/user/$uid \
  DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
  bash -lc 'cd /home/headscale/headscale && \
    docker compose restart headscale && \
    docker compose exec headscale headscale policy check -f /etc/headscale/policy.hujson'

In our test, a device of another user reached port 443 on the server, but not port 22 or 8888. After each later change to the policy, run the policy check command first, which answers Policy is valid, and then restart the container.

Know one thing about firewalls: the Tailscale app adds its own firewall rules on each device, ahead of ufw's. Traffic that arrives over the tailnet is accepted there, and ufw never sees it. In our test, a port that ufw blocked from the internet answered over the tailnet. On a tailnet, the policy is your firewall.

10. Keep it up to date

Add the weekly update timer from the Docker guide and test it once:

runuser -u headscale -- env XDG_RUNTIME_DIR=/run/user/$uid \
  DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$uid/bus PATH=/usr/bin:/bin \
  systemctl --user enable --now docker-update.timer
runuser -u headscale -- env XDG_RUNTIME_DIR=/run/user/$uid \
  DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$uid/bus PATH=/usr/bin:/bin \
  systemctl --user start docker-update.service

The timer runs docker compose pull and docker compose up -d from /home/headscale/headscale. The 0.29 tag gets every fix within Headscale 0.29. Headscale must be updated one minor version at a time, 0.29 to 0.30 and so on, without skipping any. Before each, read its release notes, back up as in step 11, then change the tag.

11. Back up

As root:

umask 077
mkdir -p /root/backup
runuser -u headscale -- env HOME=/home/headscale XDG_RUNTIME_DIR=/run/user/$uid \
  DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
  bash -lc 'cd /home/headscale/headscale && docker compose stop'
tar -czf /root/backup/headscale.tar.gz -C /home/headscale headscale
runuser -u headscale -- env HOME=/home/headscale XDG_RUNTIME_DIR=/run/user/$uid \
  DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
  bash -lc 'cd /home/headscale/headscale && docker compose start'

That saves the database, with every user and device, the server's private keys, its settings and the policy in one directory owned by headscale. Copy /root/backup to another machine afterwards, and keep it private.

Troubleshooting

Headscale stops at start with server_url cannot be part of base_domain. base_domain in step 3 contains the server's own name. Use a subdomain, such as tail.example.com.

tailscale netcheck shows UDP: false, or no Nearest DERP. The STUN port is not reachable. Check the ufw rule from step 1, and that the port is the same in steps 1, 3 and 4.

A device stays offline after the login page. The auth register command has not been run, or ran with a user that does not exist. docker compose exec headscale headscale nodes list from /home/headscale/headscale shows every registered device.

Run it on your own server

SSD RAID 1 · ECC DDR4 · 10 Gbit

VC-P Alloy

€8.99/mo

vCPU
2
Memory
8 GB
Storage
60 GB
Transfer
10 TB
Performance
SSD · RAID 1
  • Full root access
  • Native /64 IPv6
  • RAID-protected storage
  • Malmö, Sweden
  • Month to month, no lock-in
  • 7-day money-back guarantee

Related comparisons and alternatives

All guides