SaonBD | Paragraph logo

Subscribe to SaonBD | Paragraph

Get new posts delivered straight to your inbox.

All posts

Self-Hosting a Private Mesh Network with Headscale on Linux

A practical guide to deploying an open-source, encrypted Tailscale control server on Linux without cloud dependencies.

Self-Hosting a Private Mesh Network with Headscale on Linux

Headscale is an open-source implementation of the Tailscale control server. It allows you to create a secure mesh network on your own infrastructure. All traffic between nodes travels through encrypted WireGuard tunnels.

This guide shows you how to install Headscale on a Linux server. You will configure the server, create a user, and connect your devices.

Prerequisites

Before you start, make sure that you have the following items:

  • A Linux server with a public IP address.

  • A domain name pointing to your server IP address.

  • Root or sudo access on the server.

Step 1: Install Headscale

Download the latest Headscale release binary from GitHub.

wget https://github.com/juanfont/headscale.git

Move the binary to your system executable path.

sudo mv headscale /usr/local/bin/headscale
sudo chmod +x /usr/local/bin/headscale

Create a system user for Headscale.

sudo useradd --system --home-dir /var/lib/headscale --create-home --shell /bin/false headscale

Create directory structures for configuration files and state storage.

sudo mkdir -p /etc/headscale
sudo mkdir -p /var/lib/headscale
sudo mkdir -p /var/run/headscale

Step 2: Configure Headscale

Download the default configuration file template.

sudo wget https://raw.githubusercontent.com/juanfont/headscale/v0.22.3/config-example.yaml -O /etc/headscale/config.yaml

Open the configuration file in a text editor.

sudo nano /etc/headscale/config.yaml

Update the following values in the configuration file:

  • Set server_url to your domain URL: https://headscale.example.com:443

  • Set listen_addr to 0.0.0.0:8080

  • Set private_key_path to /var/lib/headscale/private.key

  • Set db_type to sqlite3

  • Set db_path to /var/lib/headscale/db.sqlite

Save the file and exit the editor.

Change ownership of the configuration and data paths to the headscale user.

sudo chown -R headscale:headscale /etc/headscale
sudo chown -R headscale:headscale /var/lib/headscale

Step 3: Create a Systemd Service

Create a systemd service file to manage Headscale.

sudo nano /etc/systemd/system/headscale.service

Add the following service configuration:

[Unit]
Description=headscale controller
After=network.target

[Service]
Type=simple
User=headscale
Group=headscale
ExecStart=/usr/local/bin/headscale serve
Restart=always
RestartSec=5
WorkingDirectory=/var/lib/headscale

[Install]
WantedBy=multi-user.target

Reload the systemd manager.

sudo systemctl daemon-reload

Start the Headscale service.

sudo systemctl enable --now headscale

Verify that the Headscale service is active.

sudo systemctl status headscale

Step 4: Create a User and Register Devices

Create a user account in Headscale to register nodes.

sudo headscale users create admin

Install the official Tailscale client on your local machine.

Run the login command to direct your local client to your Headscale server.

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

The command displays a registration URL. Open the URL in your browser or run the registration command on the server.

sudo headscale nodes register --user admin --key <YOUR_MACHINE_KEY>

Verify that the device appears in the node list.

sudo headscale nodes list

Step 5: Verify Connectivity

Run the ping command from your client node to another node on the mesh network.

tailscale ping <TARGET_NODE_IP>

Verify that traffic routes through the encrypted tunnel without passing through external servers.

CAUTION: Store your database backup files in a secure remote location. Loss of the database file will break node authentication across the network.

Related guides

Join the discussion

Have a thought or a correction? Send it over — your message opens in your email app.

Subscribe

Get new posts delivered to your inbox.