tailscale

package module
v0.0.0-...-2977748 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2025 License: MIT Imports: 21 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

tailscale

Name

tailscale - serves DNS records for Tailscale nodes with subdomain resolution support.

Description

The tailscale plugin serves DNS records for Tailscale nodes in your Tailnet. It automatically creates A and AAAA records for all Tailscale machines and supports CNAME records via Tailscale tags. Additionally, it provides subdomain resolution - any subdomain of a registered Tailscale machine will resolve to the same IP address as the base machine.

This plugin allows:

  • Integrating Tailscale machines into your existing DNS domain
  • Creating CNAME records via Tailscale node tags
  • Resolving arbitrary subdomains of Tailscale machines (wildcard-like behavior)

The plugin retrieves node information through the local machine's Tailscale socket, so only machines visible to the hosting Tailscale node (visible in tailscale status) will be included in DNS responses.

Syntax

tailscale ZONE {
    [authkey KEY
    hostname NAME]
    [fallthrough [ZONES...]]
}
  • ZONE is the zone that plugin should be authoritative for.

Subdirectives:

  • authkey KEY - optional - Tailscale auth key for connecting to the Tailnet. If not provided, the plugin will connect to the local tailscaled instance.
  • hostname NAME - optional - hostname to use for the Tailscale node. If not provided, the plugin will use "coredns" as the hostname.
  • fallthrough [ZONES...] - optional - if the tailscale plugin cannot provide an answer for a query, fall through to the next plugin. If specific zones are listed, the fallthrough will only happen for those zones.

Metrics

If monitoring is enabled (via the prometheus directive) the following metrics are exported:

  • coredns_tailscale_requests_total{server,type} - count of DNS requests processed by record type
  • coredns_tailscale_responses_total{server,rcode} - count of DNS responses by return code
  • coredns_tailscale_request_duration_seconds{server} - histogram of request processing time
  • coredns_tailscale_nodes_total{server} - number of Tailscale nodes in the Tailnet

The server label indicates which server handled the request, the type label indicates the DNS record type requested (A, AAAA, CNAME, etc.), and the rcode label indicates the DNS response code (NOERROR, NXDOMAIN, etc.).

Ready

This plugin reports readiness to the ready plugin once it has successfully loaded the Tailscale node information.

Examples

Enable tailscale plugin for the example.com zone:

example.com {
  tailscale example.com
  log
  errors
}

With this configuration:

  1. Tailscale machines will resolve as machinename.example.com
  2. Machines with Tailscale tags like cname-app will create app.example.com records pointing to that machine
  3. Subdomains like web.machinename.example.com will resolve to the same IP as machinename.example.com

Enable metrics for monitoring:

example.com {
  tailscale example.com
  prometheus
  log
  errors
}

This configuration:

  1. Serves DNS records for Tailscale machines on example.com
  2. Exports Prometheus metrics for the tailscale plugin
  3. Makes metrics available at http://localhost:9153/metrics

CNAME Records via Tailscale Tags

A CNAME record can be created by adding a Tailscale machine tag prefixed with cname-. The text after the prefix becomes the hostname:

  • Machine server1 with tag cname-app creates:
    app.example.com IN CNAME server1.example.com.
    server1.example.com IN A <Tailscale IPv4>
    server1.example.com IN AAAA <Tailscale IPv6>
    

Subdomain Resolution

Any subdomain of a Tailscale machine or CNAME will resolve to the same IP address:

server1.example.com          → <Tailscale IP>
web.server1.example.com      → <Same Tailscale IP>
api.web.server1.example.com  → <Same Tailscale IP>

app.example.com              → <Tailscale IP via cname-app tag>
admin.app.example.com        → <Same Tailscale IP via cname-app tag>

This is particularly useful for:

  • Running multiple services on the same Tailscale machine
  • Creating wildcard-like behavior without actual wildcard DNS records
  • Simplifying service discovery within a Tailnet

Also See

See the CoreDNS manual and the original repository this fork is based on.

Documentation

Index

Constants

View Source
const (
	TypeAll = iota
	TypeA
	TypeAAAA
)

Variables

View Source
var (
	// RequestCount exports a prometheus metric that is incremented every time a DNS request is processed.
	RequestCount = promauto.NewCounterVec(prometheus.CounterOpts{
		Namespace: plugin.Namespace,
		Subsystem: "tailscale",
		Name:      "requests_total",
		Help:      "Counter of DNS requests processed by record type.",
	}, []string{"server", "type"})

	// RcodeCount exports a prometheus metric that counts responses by return code.
	RcodeCount = promauto.NewCounterVec(prometheus.CounterOpts{
		Namespace: plugin.Namespace,
		Subsystem: "tailscale",
		Name:      "responses_total",
		Help:      "Counter of DNS responses by return code.",
	}, []string{"rcode", "server"})

	// RequestDuration exports a prometheus metric that tracks the duration of DNS requests.
	RequestDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
		Namespace: plugin.Namespace,
		Subsystem: "tailscale",
		Name:      "request_duration_seconds",
		Buckets:   plugin.TimeBuckets,
		Help:      "Histogram of the time each DNS request took to resolve.",
	}, []string{"server"})

	// NodeCount exports a prometheus metric that shows the number of Tailscale nodes in the Tailnet.
	NodeCount = promauto.NewGaugeVec(prometheus.GaugeOpts{
		Namespace: plugin.Namespace,
		Subsystem: "tailscale",
		Name:      "nodes_total",
		Help:      "Number of Tailscale nodes in the Tailnet.",
	}, []string{"server"})
)

Variables declared for monitoring.

Functions

This section is empty.

Types

type Tailscale

type Tailscale struct {
	// contains filtered or unexported fields
}

func (*Tailscale) Name

func (t *Tailscale) Name() string

Name implements the Handler interface.

func (*Tailscale) ServeDNS

func (t *Tailscale) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址