Skip to main content

Using MagicDNS and Extra Records in Headscale

· 4 min read
Larktun Contributor

Remembering dynamic tailnet IP addresses quickly becomes painful once your private network grows past a handful of servers, NAS appliances, and laptops. Enabling MagicDNS in headscale solves this by automatically publishing readable hostnames for every enrolled node, and pairing it with extra_records_path lets you map internal LAN services and 4via6 routes to stable DNS names.

This guide covers how to configure MagicDNS in Headscale, structure extra-records.json, apply updates cleanly without disrupting connected clients, and verify DNS resolution end to end.

Why Enable MagicDNS in Headscale​

Without MagicDNS, every SSH session, browser bookmark, and monitoring target has to hardcode 100.64.x.y overlay addresses. Enabling MagicDNS provides three immediate operational benefits:

  • Readable device hostnames: Reach machines by short hostname or FQDN (nas.example.com) instead of memorizing overlay IPs.
  • Cross-platform consistency: Tailscale and Larktun clients receive the DNS map directly from the control plane. On Windows, the client synchronizes peer mappings transparently; on Linux and macOS, the local MagicDNS stub resolver (100.100.100.100) intercepts queries for your base domain.
  • Cleaner 4via6 and internal service aliases: When routing overlapping RFC 1918 LAN subnets with 4via6, raw IPv6 ULA addresses (fd7a:115c:a1e0:...) are nearly impossible to type by hand. Custom DNS records turn them into predictable service names.

Configuring MagicDNS in config.yaml​

Open your Headscale config.yaml and configure the dns block. Below is a production-ready baseline:

dns:
magic_dns: true
base_domain: internal.example.com
override_local_dns: false

nameservers:
global:
- 1.1.1.1
- 1.0.0.1

search_domains: []
extra_records_path: /var/lib/headscale/extra-records.json

Key Options Explained​

  • magic_dns: true: Turns on automatic hostname-to-tailnet-IP resolution for all devices registered in the tailnet.
  • base_domain: The private DNS suffix appended to node names. Avoid reusing a public domain you actively resolve on the internet unless you intentionally want split-horizon DNS; a dedicated subdomain such as tailnet.example.com or internal.example.com prevents accidental collisions.
  • override_local_dns: false: Keeps the client's existing local DNS resolvers for normal internet traffic and sends only MagicDNS queries through the configured global nameservers. Set this to true only if you want every client's DNS traffic forced through nameservers.global.
  • extra_records_path: Points to an external JSON file containing custom A and AAAA records. Compared with inlining extra_records directly in config.yaml, keeping records in a separate file makes automation, GitOps updates, and day-to-day maintenance much cleaner.

Managing Custom Records with extra-records.json​

Create /var/lib/headscale/extra-records.json (ensure the headscale service user has read permissions) and add your custom mappings:

[
{
"name": "nas.internal.example.com",
"type": "A",
"value": "100.64.0.12"
},
{
"name": "192-168-6-1-via-7.internal.example.com",
"type": "AAAA",
"value": "fd7a:115c:a1e0:b1a:0:7:c0a8:601"
}
]

Operational Tips for extra-records.json​

  • Supported record types: Use A for IPv4 addresses (tailnet IPs or advertised subnet IPs) and AAAA for IPv6 addresses (including 4via6 mapped targets).
  • Initial migration: The first time you switch from inline extra_records inside config.yaml to extra_records_path, restart the headscale daemon once so it registers the file watcher cleanly.
  • Ongoing updates: After extra_records_path is active, editing extra-records.json pushes updated DNS maps to connected clients without requiring a full service restart. Always validate JSON syntax (jq . /var/lib/headscale/extra-records.json) before saving so malformed JSON does not prevent a reload.

Verifying Resolution on Clients​

Once headscale is running with MagicDNS enabled and clients have re-synced their network map, test resolution from any enrolled machine:

# Inspect advertised DNS names for peers
tailscale status

# Query a custom extra record directly against MagicDNS
nslookup 192-168-6-1-via-7.internal.example.com 100.100.100.100

# Verify reachability over the overlay
ping -c 3 nas.internal.example.com

If clients also consume subnet routes alongside MagicDNS, confirm that the subnet route is approved on the control plane and accepted on the client (--accept-routes).

Headscale route table update with MagicDNS active

MagicDNS query returning the configured custom record

Common Troubleshooting Checks​

  • Client ignores MagicDNS names: Make sure the client has not disabled DNS acceptance (tailscale up --accept-dns=true).
  • Custom record resolves to NXDOMAIN: Verify that the record name in extra-records.json matches your base_domain suffix and that the JSON file is readable by the headscale process.
  • Public domain shadowed by MagicDNS: If internal hosts fail to reach public websites under the same root domain, move base_domain to a dedicated subdomain such as mesh.example.com.