Headscale is an open source coordination server that speaks the Tailscale protocol. You keep using the normal Tailscale client; you only tell it where to log in.
sudo tailscale login --login-server=https://headscale.example.com
The same flag works with tailscale up. Without it, the client uses Tailscale’s own server at controlplane.tailscale.com. The login link it prints goes to your Headscale instance, and Headscale’s docs explain how you approve the device there, or how to make a pre-auth key so you can pass --auth-key and skip that step.
Each client stores which server it belongs to, so after the first login a plain tailscale up keeps using Headscale.
Going back is the part people get stuck on. Tailscale’s docs say to start with tailscale logout. If that does not reset the client, stop tailscaled and remove its state file (/var/lib/tailscale/tailscaled.state on Linux), then start it again. That wipes the device’s local Tailscale state, so treat it as the last resort.
Headscale does not do everything the hosted service does, so I’d check its docs for a feature before planning around it. Things like Funnel depend on Tailscale’s own infrastructure.
Further reading: Use a custom control server, Headscale