Complete Setup Guide
CGNAT can prevent direct access to devices on a home connection. This guide builds a self-hosted VPN for secure remote access to private services and IoT devices, with control over coordination, authentication and network policies.
The deployment uses:
- VPS: Public server hosting the services.
- Headscale: Self-hosted Tailscale control server; coordinates devices and distributes network configuration.
- Headplane: Web administration interface for Headscale.
- Nginx: Public reverse proxy and TLS termination point.
- Tailscale clients: Installed on participating devices.
- DERP: Relays traffic when direct peer-to-peer connectivity fails.
Architecture:
INTERNET
|
|
PUBLIC DNS
|
|
+--------------+
| VPS |
| |
| Nginx |
| | |
| +------------------+
| | |
| Headscale Headplane
| :8080 :3000
| | |
| +------------------+
| |
| DERP / STUN
| |
+--------------+
|
|
TAILSCALE NETWORK
|
+-------------+-------------+
| | |
Desktop Laptop Mobile
| | |
+-------------+-------------+
|
PRIVATE NETWORK
Acquiring a VPS
A low-cost Linux VPS is sufficient for a small deployment. I use IONOS. Headscale mainly coordinates connections; size the VPS for device count, DERP relay traffic and any exit-node workload.
Choose a VPS with:
- Operating system: Debian 13, as used throughout this guide.
- Architecture: Preferably AMD64, although ARM64 is also supported by the relevant software.
- RAM: 1 GB is a reasonable starting point for a small deployment. More may be required if running additional services.
- Storage: Allow enough space for the operating system, application binaries, database, logs and backups.
- Network: Ensure that the provider allows the necessary inbound and outbound TCP/UDP traffic.
- Public IP: A publicly reachable IPv4 address is recommended, particularly for DERP and STUN.
This guide is based on a Debian 13 VPS. You will need to own a domain in order to set everything up smoothly.
Create these DNS records, replacing example.com with your domain:
| Hostname | Purpose |
|---|---|
headscale.example.com |
Headscale control server |
headplane.example.com |
Headplane administration interface |
Point both records to the VPS public IP. Cloudflare's standard HTTP proxy does not support the UDP traffic used by DERP/STUN; use DNS-only records for those services.
Generate an Ed25519 SSH key pair (Linux or Windows):
ssh-keygen -t ed25519
Upload id_ed25519.pub to the VPS provider. Keep id_ed25519 private and protect it with a passphrase.
You might need to install the openssh-client package on Linux to have the ssh-keygen command.
Display and copy the public key:
notepad $env:USERPROFILE\.ssh\id_ed25519.pub
Copy the file contents to your VPS provider.
cat ~/.ssh/id_ed25519.pub
Copy the output to your VPS provider.
After provisioning, connect using your private key:
ssh -i $env:USERPROFILE\.ssh\id_ed25519 username@<VPS_IP>
ssh -i ~/.ssh/id_ed25519 username@<VPS_IP>
Replace username with your provider's default account. Use cloud-init for initial setup if available.
Configuring the VPS
Update Debian and install the required utilities:
sudo apt update
sudo apt upgrade -y
sudo apt install -y curl wget git gnupg ca-certificates \
lsb-release apt-transport-https unzip tar nano
Check the clock and set the correct timezone if needed:
sudo timedatectl set-timezone Africa/Johannesburg
Accurate time is required for TLS and authentication.
Harden SSH. Cloud-init or provider defaults may override SSH settings. Add a configuration drop-in to disable password authentication and root login:
sudo tee /etc/ssh/sshd_config.d/99-hardening.conf > /dev/null <<EOF
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
KbdInteractiveAuthentication no
PermitEmptyPasswords no
EOF
Validate and reload SSH:
sudo sshd -t && sudo systemctl reload sshd
From a new terminal, without closing the current one, test if you can SSH into the VPS. If you cannot, retry the steps and if failure continues, reset everything by running:
sudo rm /etc/ssh/sshd_config.d/99-hardening.conf && sudo systemctl reload sshd
Install and configure UFW:
sudo apt install -y ufw
Set the default policies and allow SSH before enabling the firewall:
sudo ufw default deny incoming
sudo ufw default allow outgoing
Allow SSH before enabling the firewall:
sudo ufw allow 22/tcp
Allow the required inbound ports: TCP 22 (SSH), TCP 80/443 (HTTP/HTTPS) and UDP 3478 (STUN). If the VPS will also act as an exit node, allow UDP 41641 and 40759. Apply compatible rules in both UFW and your provider's firewall:
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw allow 3478/udp
# Optional: Tailscale connectivity and exit-node support
sudo ufw allow 41641/udp
sudo ufw allow 40759/udp
Enable the firewall:
sudo ufw enable
sudo ufw status verbose
Both firewalls must allow the required traffic; opening a port with your provider does not open it in Debian.
Do not expose administrative interfaces, databases, metrics endpoints or internal application ports unnecessarily. Headscale and Headplane should preferably communicate with Nginx through localhost rather than exposing their application ports publicly.
Configuring and installing Headscale
Headscale coordinates devices and maintains the network state. Unlike a traditional VPN that routes all traffic through one server, Tailscale clients try to establish direct peer-to-peer connections; Headscale helps them negotiate those connections.
Create a Headscale user if one does not already exist:
if ! id headscale >/dev/null 2>&1; then
sudo useradd --system \
--home-dir /var/lib/headscale \
--create-home \
--shell /usr/sbin/nologin \
headscale
fi
Create the required directories and assign permissions:
sudo install -d -o headscale -g headscale /var/lib/headscale
sudo install -d -o headscale -g headscale /var/lib/headscale/cache
sudo install -d -o headscale -g headscale /var/log/headscale
Download the latest Headscale release. Set HEADSCALE_VERSION without the leading v and choose the matching architecture:
HEADSCALE_VERSION="0.29.3" # Check for the latest version in the link above
HEADSCALE_ARCH="amd64" # Or "arm64"
curl -Lo /tmp/headscale.deb \
"https://github.com/juanfont/headscale/releases/download/v${HEADSCALE_VERSION}/headscale_${HEADSCALE_VERSION}_linux_${HEADSCALE_ARCH}.deb"
You can verify the downloaded package before installing it:
file /tmp/headscale.deb
Install:
sudo dpkg -i /tmp/headscale.deb
Alternatively, install the package with APT:
sudo apt install /tmp/headscale.deb
Verify the installation:
headscale version
Check that the service exists:
systemctl status headscale
Configure Headscale
Headscale uses /etc/headscale/config.yaml. Back up the original before editing:
sudo cp /etc/headscale/config.yaml /etc/headscale/config.yaml.bak
Configure:
sudo tee /etc/headscale/config.yaml > /dev/null <<EOF
---
# The URL clients will connect to.
server_url: https://headscale.example.com
# Address to listen to / bind to on the server.
# Nginx will forward requests to this local address.
listen_addr: 127.0.0.1:8080
# Address to listen to /metrics and /debug.
metrics_listen_addr: 127.0.0.1:9090
# Address to listen for gRPC.
grpc_listen_addr: 127.0.0.1:50443
# Allow the gRPC admin interface to run in INSECURE mode.
grpc_allow_insecure: false
# The Noise section includes specific configuration for the
# TS2021 Noise protocol.
noise:
private_key_path: /var/lib/headscale/noise_private.key
# List of IP prefixes to allocate tailaddresses from.
prefixes:
v4: 100.64.0.0/10
v6: fd7a:115c:a1e0::/48
# Strategy used for allocation of IPs to nodes.
allocation: sequential
derp:
server:
enabled: true
region_id: 999
region_code: "Internal DERP"
region_name: "Internal DERP"
verify_clients: true
stun_listen_addr: "0.0.0.0:3478"
private_key_path: /var/lib/headscale/derp_server_private.key
automatically_add_embedded_derp_region: true
ipv4: <Enter IPV4 public address>
urls:
- https://controlplane.tailscale.com/derpmap/default
paths: []
auto_update_enabled: true
update_frequency: 3h
disable_check_updates: false
node:
expiry: 0
ephemeral:
inactivity_timeout: 30m
routes:
ha:
probe_interval: 10s
probe_timeout: 5s
database:
type: sqlite
debug: false
gorm:
prepare_stmt: true
parameterized_queries: true
skip_err_record_not_found: true
slow_threshold: 1000
sqlite:
path: /var/lib/headscale/db.sqlite
write_ahead_log: true
wal_autocheckpoint: 1000
acme_url: https://acme-v02.api.letsencrypt.org/directory
acme_email: ""
tls_letsencrypt_hostname: ""
tls_letsencrypt_cache_dir: /var/lib/headscale/cache
tls_letsencrypt_listen: ":80"
## Use already defined certificates:
tls_cert_path: ""
tls_key_path: ""
log:
level: info
format: text
policy:
mode: database
dns:
magic_dns: true
base_domain: example.com
override_local_dns: false # To avoid clashing with custom hosts files
# List of DNS servers to expose to clients.
nameservers:
global:
- 1.1.1.1
- 1.0.0.1
- 8.8.8.8
- 2606:4700:4700::1111
- 2606:4700:4700::1001
search_domains: []
unix_socket: /var/run/headscale/headscale.sock
unix_socket_permission: "0770"
logtail:
enabled: false
taildrop:
enabled: true
EOF
Key configuration options:
server_url: The publicly accessible URL that Tailscale clients use to communicate with Headscale.listen_addr: The local address on which Headscale listens. Nginx will forward incoming requests to this address.metrics_listen_addr: The local address used for metrics and debugging.prefixes: The IP ranges from which Headscale allocates addresses to connected devices.derp.server: Enables the embedded DERP relay server.derp.urls: Allows clients to retrieve additional DERP server information.database: Defines how Headscale stores its persistent state.dns.magic_dns: Enables MagicDNS for resolving devices using their names.dns.base_domain: The domain suffix used for MagicDNS.taildrop: Enables file transfer between supported clients.
Before starting Headscale, replace these placeholders:
headscale.example.comwith your actual Headscale hostname.example.comunderdns.base_domainwith a dedicated domain for your VPN network.<Enter IPV4 public address>with the VPS public IPv4 address.
Use a dedicated MagicDNS base domain, separate from the public Headscale hostname, to avoid DNS conflicts.
The configuration options and their exact placement are version-dependent. Always compare your configuration with the sample configuration shipped for the Headscale release you install. In particular, verify the DERP, database and TLS options before starting the service.
Restart:
sudo systemctl restart headscale
Enable the service at startup:
sudo systemctl enable headscale
Check the service:
sudo systemctl status headscale
Check the logs if there are any issues:
sudo journalctl -u headscale -f
You can also verify that Headscale is listening on the expected address:
sudo ss -tulpn | grep -E '8080|9090|50443|3478'
Initial Headscale configuration
Create a Headscale user (namespace) for devices joining the VPN:
sudo headscale users create main
List the available users:
sudo headscale users list
Use separate users to organize devices by person or environment. A personal setup may need only one:
sudo headscale users create development
sudo headscale users create administration
Generate a pre-authentication key when a device needs to join without interactive browser authentication:
sudo headscale preauthkeys create \
--user main \
--expiration 24h
A reusable key can be generated where required:
sudo headscale preauthkeys create \
--user main \
--reusable \
--expiration 168h
Pre-authentication keys are credentials. Treat them as secrets, avoid including them in scripts committed to Git and use expiration times appropriate to their purpose.
Useful management commands:
sudo headscale nodes list
List users:
sudo headscale users list
List available routes:
sudo headscale nodes list-routes
These commands will become useful when managing the network through either the command-line interface or Headplane.
Installing Headplane
Headplane provides a web interface for managing Headscale users, devices and other supported settings. Check the latest Headplane release before building it.

Open the selected release tag and inspect go.mod to find its required Go version.

Use package.json to identify the required Node.js and pnpm versions. Match the versions specified by the release; newer versions are not necessarily compatible.
Installing build dependencies
Download the Go version specified in go.mod:
GO_VERSION="" # The one from go.mod
GO_ARCH="amd64" # Or arm64
curl -Lo /tmp/go.tar.gz \
https://go.dev/dl/go${GO_VERSION}.linux-${GO_ARCH}.tar.gz
Clean any previous Go installation and set up the new version:
sudo rm -rf /usr/local/go && \
sudo tar -C /usr/local -xzf /tmp/go.tar.gz
Add export PATH=$PATH:/usr/local/go/bin to ~/.profile.
Add export PATH="$PATH:$(go env GOPATH)/bin" to ~/.profile.
Restart the terminal session.
Run:
go version
to confirm installation.
Install the Node.js version specified in package.json from nodejs.org, then verify the installed versions:
node --version
npm --version
Install pnpm using the version specified by the Headplane release:
npm install -g pnpm@<PNPM_VERSION>
Verify:
pnpm --version
Building Headplane
Create the Headplane directory and permissions:
sudo mkdir -p /var/lib/headplane
sudo chown -R headscale:headscale /var/lib/headplane
Build:
git clone https://github.com/tale/headplane.git /tmp/headplane
cd /tmp/headplane
git checkout <version tag> # e.g "v0.8.2"
./build.sh
The build script compiles the application. Confirm that the server output was created:
ls -la ./build/server/
Installing Headplane
sudo mkdir -p /opt/headplane
sudo mv ./build /opt/headplane/build
sudo chown -R headscale:headscale /opt/headplane
sudo chown -R headscale:headscale /var/lib/headplane
Find the Node.js executable path:
command -v node
Use the returned path in the systemd service configuration.
Create the service:
sudo tee /etc/systemd/system/headplane.service > /dev/null <<EOF
[Unit]
Description=Headplane Service
After=headscale.service
Requires=headscale.service
StartLimitIntervalSec=0
[Service]
Type=simple
User=headscale
WorkingDirectory=/opt/headplane
ExecStart=/usr/bin/node /opt/headplane/build/server/index.js
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target
EOF
If the returned path differs from /usr/bin/node, update ExecStart. Then reload systemd:
sudo systemctl daemon-reload
Enable Headplane:
sudo systemctl enable headplane
Create a Headplane configuration that matches your installed release. Use the example in the Headplane repository and its release documentation.
Create its configuration directory:
sudo mkdir -p /etc/headplane
Create the configuration file:
sudo nano /etc/headplane/config.yaml
Configure its listen address/port, public URL or base path, Headscale URL and Unix socket, authentication, and any release-specific settings.
Ensure that Headplane can access the Headscale Unix socket.
For example, inspect the socket permissions:
sudo ls -l /var/run/headscale/headscale.sock
Grant Headplane access through appropriate group membership and socket permissions. Do not expose the administrative gRPC interface publicly.
Do not assume that Headplane uses the same configuration schema as Headscale. Its configuration belongs in /etc/headplane/config.yaml, not /etc/headscale/config.yaml.
Start the service:
sudo systemctl start headplane
Check its status:
sudo systemctl status headplane
Check its logs:
sudo journalctl -u headplane -f
Verify that the application is listening:
sudo ss -tulpn | grep 3000
Configuring the reverse proxy
Nginx provides the public HTTPS entry point while Headscale and Headplane remain on local ports. It handles:
- TLS termination.
- HTTP to HTTPS redirection.
- Forwarding requests to Headscale.
- Forwarding administration requests to Headplane.
- Forwarding client information through HTTP headers.
- Supporting the required connection upgrade headers.
Install Nginx:
sudo apt install -y nginx
Enable it:
sudo systemctl enable nginx
sudo systemctl start nginx
Configuring SSL certificates
Use Certbot with Let's Encrypt, or provide certificates from another certificate authority. To use Certbot:
sudo apt install -y certbot python3-certbot-nginx
Obtain a certificate for the Headscale hostname:
sudo certbot certonly --nginx \
-d headscale.example.com \
-d headplane.example.com
Certbot will store the certificates under:
/etc/letsencrypt/live/headscale.example.com/
Nginx uses fullchain.pem (certificate chain) and privkey.pem (private key).
Verify the certificate:
sudo certbot certificates
Certbot normally configures automatic renewal through a systemd timer. Verify it and test renewal:
sudo systemctl status certbot.timer
Test renewal:
sudo certbot renew --dry-run
Set reverse proxy
Create an Nginx configuration file:
sudo nano /etc/nginx/sites-available/headscale
Set reverse proxy:
server {
listen 80;
listen [::]:80;
server_name headscale.example.com headplane.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
server_name headscale.example.com;
ssl_certificate /etc/letsencrypt/live/headscale.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/headscale.example.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
location / {
# Headscale runs on the root path.
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
proxy_redirect http:// https://;
proxy_buffering off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
add_header Strict-Transport-Security "max-age=15552000; includeSubDomains" always;
}
}
server {
listen 80;
listen [::]:80;
server_name headplane.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
server_name headplane.example.com;
ssl_certificate /etc/letsencrypt/live/headscale.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/headscale.example.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
location / {
# Headplane is served on its own hostname.
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
proxy_redirect http:// https://;
proxy_buffering off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Alternatively, serve Headplane under /admin/ on the Headscale hostname. Set Headplane's base path to /admin and add this Nginx location:
location /admin/ {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
proxy_redirect http:// https://;
proxy_buffering off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
For this arrangement, Headplane must be configured to serve from the /admin base path.
Define $connection_upgrade in the Nginx http context:
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
Enable the configuration:
sudo ln -s /etc/nginx/sites-available/headscale \
/etc/nginx/sites-enabled/headscale
Test the configuration:
sudo nginx -t
Reload Nginx:
sudo systemctl reload nginx
Both services should now be reachable through their HTTPS hostnames.
Verifying the installation
Verify services, listeners, DNS and HTTPS before enrolling clients:
Check the service statuses:
sudo systemctl status headscale
sudo systemctl status headplane
sudo systemctl status nginx
Check the listening ports:
sudo ss -tulpn
Verify DNS resolution:
dig headscale.example.com
dig headplane.example.com
Test HTTPS connectivity:
curl -I https://headscale.example.com
curl -I https://headplane.example.com
The Headscale endpoint should be reachable even though its application is listening only on localhost.
If a service is unavailable, inspect its logs:
sudo journalctl -u headscale --since "10 minutes ago"
sudo journalctl -u headplane --since "10 minutes ago"
sudo journalctl -u nginx --since "10 minutes ago"
You can also inspect the Nginx error log:
sudo tail -f /var/log/nginx/error.log
Installing Tailscale clients
Install the Tailscale client on each device. Clients are available for:
- Windows
- Linux
- macOS
- Android
- iOS
Downloads are available from the official Tailscale website.
Install the appropriate client on each device.
For Linux, you can use the official installation instructions:
For Debian-based systems, the installation process can be automated using the official installation script:
curl -fsSL https://tailscale.com/install.sh | sh
Verify installation:
tailscale version
Connecting devices to Headscale
Tailscale clients use Tailscale's coordination server by default. Specify your Headscale instance with --login-server:
Linux
Run:
sudo tailscale up \
--login-server=https://headscale.example.com
The client will display an authentication URL or otherwise initiate the authentication process according to the configured authentication method.
If you are using a pre-authentication key:
sudo tailscale up \
--login-server=https://headscale.example.com \
--authkey=<PRE_AUTH_KEY>
Windows
Open PowerShell as administrator and run:
tailscale up --login-server=https://headscale.example.com
If using a pre-authentication key:
tailscale up --login-server=https://headscale.example.com --authkey=<PRE_AUTH_KEY>
macOS
Open Terminal and run:
sudo tailscale up \
--login-server=https://headscale.example.com
Android and iOS
Install the Tailscale application from the respective application store.
The mobile applications also support custom control servers. Select the option to use a custom coordination server and provide:
https://headscale.example.com
Follow the authentication instructions displayed by the client.
Make sure that the Headscale hostname is reachable and has a valid TLS certificate before attempting to connect clients. A certificate error or an incorrect server URL will prevent successful registration.
Managing devices
Connected devices appear in Headscale's node list and in Headplane. Use these commands to inspect and manage them:
sudo headscale nodes list
Remove a device:
sudo headscale nodes delete --identifier <NODE_ID>
Inspect users:
sudo headscale users list
Move a device between users:
sudo headscale nodes move --identifier <NODE_ID> --user <USER_ID>
The exact command syntax may vary between Headscale releases. Use headscale --help and the relevant subcommand's help output when necessary.
On a connected client, verify its status:
tailscale status
Get the assigned VPN IP:
tailscale ip
Test connectivity to another device:
tailscale ping <DEVICE_NAME_OR_IP>
A successful connection indicates that the devices can communicate over the VPN.
Configuring MagicDNS
MagicDNS lets you reach devices by hostname instead of remembering their VPN IP addresses. For example:
100.64.0.2
You can connect using a hostname such as:
desktop.example.com
The DNS configuration in Headscale enables this functionality:
dns:
magic_dns: true
base_domain: example.com
Clients receive this DNS configuration from Headscale. Test name resolution from a connected device:
nslookup desktop.example.com
Or:
ping desktop.example.com
This is useful when managing multiple devices or configuring services that need stable hostnames.
Configuring subnet routers
Subnet routers let VPN clients access devices on networks that do not run Tailscale. For example, a home network might use:
192.168.1.0/24
Configure a device on that network to advertise the subnet. Other VPN clients can then access its resources without installing Tailscale on every device.
On a Linux machine that will act as the subnet router, enable IP forwarding:
sudo tee /etc/sysctl.d/99-tailscale.conf > /dev/null <<EOF
net.ipv4.ip_forward = 1
net.ipv6.conf.all.forwarding = 1
EOF
sudo sysctl --system
Advertise the subnet:
sudo tailscale up \
--login-server=https://headscale.example.com \
--advertise-routes=192.168.1.0/24
Approve the route in Headscale:
List the available routes:
sudo headscale nodes list-routes
Enable the route for the appropriate device using the supported route-management command for your Headscale version.
After approval, VPN clients can reach hosts on the advertised subnet, for example:
For example:
192.168.1.10:80
192.168.1.20:22
192.168.1.30:8080
Subnet routing requires the router device to remain online. If it disconnects, devices relying on that route will lose access to the advertised network.
Configuring exit nodes
An exit node routes a client's general internet traffic through another VPN device. This is useful on public Wi-Fi or when traffic needs to originate from a particular network.
A Linux device can be configured as an exit node by enabling IP forwarding:
sudo sysctl -w net.ipv4.ip_forward=1
sudo sysctl -w net.ipv6.conf.all.forwarding=1
Advertise the exit-node capability:
sudo tailscale up \
--login-server=https://headscale.example.com \
--advertise-exit-node
Approve the advertisement in Headscale before selecting the node on clients.
Once approved, another client can select the exit node:
sudo tailscale set --exit-node=<EXIT_NODE_IP>
To stop using an exit node:
sudo tailscale set --exit-node=
An exit node will carry the internet traffic of the clients using it. Consider its bandwidth, network capacity and firewall configuration before making it available to multiple devices.
Configuring access control policies
As your network grows, use access control policies to define which users, groups, tags and devices can reach specific resources.
For example, you may have the following logical separation:
| User | Purpose |
|---|---|
main |
Personal devices |
development |
Development machines |
administration |
Infrastructure administration |
Use policies to grant only the access each device requires.
Headscale supports policy management through its policy configuration.
For installations using database-backed policies, policies can be managed through the supported Headscale administration functionality.
An example policy structure is:
{
"groups": {
"group:admins": [
"main"
],
"group:developers": [
"development"
]
},
"acls": [
{
"action": "accept",
"src": [
"group:admins"
],
"dst": [
"*:*"
]
},
{
"action": "accept",
"src": [
"group:developers"
],
"dst": [
"tag:development:22",
"tag:development:8080"
]
}
],
"tagOwners": {
"tag:development": [
"group:admins"
]
}
}
This example separates administrative and development access. Adapt it to your registered users, groups and device tags.
Access control policies should be designed around the principle of least privilege. A connected device should only have access to the network resources it needs.
Backing up Headscale
Headscale stores device, user, key and coordination data. Losing it may require devices to be registered again. This setup uses SQLite, with the database at:
/var/lib/headscale/db.sqlite
The Headscale configuration is stored at:
/etc/headscale/config.yaml
Additional important files include:
/var/lib/headscale/noise_private.key
/var/lib/headscale/derp_server_private.key
/var/lib/headscale/cache/
Back up these files regularly. Use SQLite's backup function to account for the database's write-ahead log (WAL):
For example:
sudo sqlite3 /var/lib/headscale/db.sqlite \
".backup '/var/backups/headscale.db'"
Back up the configuration and key material:
sudo tar -czf /var/backups/headscale-config.tar.gz \
/etc/headscale \
/var/lib/headscale/noise_private.key \
/var/lib/headscale/derp_server_private.key
Ensure the backup directory is protected:
sudo chmod 700 /var/backups
sudo chmod 600 /var/backups/headscale-config.tar.gz
Copy backups to separate storage; a backup kept only on the VPS will not protect against VPS loss.
Monitoring and maintenance
Keep Debian and application releases updated, and monitor service health, resource usage and network sockets. Useful commands:
Check Headscale:
sudo systemctl status headscale
Check Headplane:
sudo systemctl status headplane
Check Nginx:
sudo systemctl status nginx
Follow Headscale logs:
sudo journalctl -u headscale -f
Follow Headplane logs:
sudo journalctl -u headplane -f
Follow Nginx logs:
sudo journalctl -u nginx -f
Check disk usage:
df -h
Check memory:
free -h
Check running processes:
top
Check network sockets:
sudo ss -tulpn
Update Debian packages regularly:
sudo apt update
sudo apt upgrade -y
Before updating Headscale or Headplane, check release compatibility, review release notes and back up the configuration and database.
Troubleshooting
Headscale refuses to start
Inspect the logs:
sudo journalctl -u headscale -n 100 --no-pager
Check the configuration file and ensure that the YAML structure is valid.
Also verify that Headscale has permission to access its data directory:
sudo ls -la /var/lib/headscale
Headplane cannot communicate with Headscale
Check whether the Headscale service is running:
sudo systemctl status headscale
Inspect the Unix socket:
sudo ls -l /var/run/headscale/headscale.sock
Verify that the Headplane process has access to the socket and that its configuration references the correct socket location.
Nginx returns a 502 Bad Gateway
A 502 generally means that Nginx cannot communicate with the upstream application.
Check whether Headscale and Headplane are listening:
sudo ss -tulpn | grep -E '8080|3000'
Test the upstream applications directly:
curl -I http://127.0.0.1:8080
curl -I http://127.0.0.1:3000
Inspect Nginx logs:
sudo tail -f /var/log/nginx/error.log
Devices cannot connect to Headscale
Verify DNS resolution:
nslookup headscale.example.com
Check HTTPS connectivity:
curl -Iv https://headscale.example.com
Verify that the TLS certificate is valid and that TCP port 443 is accessible.
Also check the Headscale logs:
sudo journalctl -u headscale -f
Devices can connect but cannot communicate directly
Tailscale attempts to establish direct peer-to-peer connections using NAT traversal.
If direct connectivity is unsuccessful, traffic may be relayed through DERP.
Inspect the client status:
tailscale status
Test connectivity:
tailscale ping <DEVICE_NAME_OR_IP>
A connection using a relay is still functional, but latency and throughput may differ from a direct connection.
Verify that the embedded DERP server is running and that UDP port 3478 is accessible.
Also verify that the VPS public IPv4 address configured in Headscale is correct.
Conclusion
You now have a self-hosted VPN coordination system using Headscale, Headplane and Tailscale clients. It provides secure access to personal devices, private services and remote IoT equipment without exposing every service to the public internet.
You can expand the network with subnet routers, exit nodes and access control policies as your requirements grow, while retaining control over device coordination and network access.
Useful references: