Skip to main content

Get a map of IP addresses for devices in my tailnet

  • Posted
  • Also filed in jq

Here’s a jq snippet that prints the hostname and IP addresses of every device in my tailnet (or at least, every device my current machine can see):

$ tailscale status --json \
    | jq '[.Self] + [.Peer[]] | map({(.DNSName): (.TailscaleIPs)}) | add'
{
  "phaenna-mac-mini.tailfa84dd.ts.net.": [
    "100.76.19.1",
    "fd7a:115c:a1e0::fb01:1301"
  ],

}

How it works:

Here’s a variant that keys the map by MagicDNS name:

$ tailscale status --json \
    | jq '[.Self] + [.Peer[]] | map({(.DNSName | split(".")[0]): (.TailscaleIPs)}) | add'
{
  "phaenna-mac-mini": [
    "100.76.19.1",
    "fd7a:115c:a1e0::fb01:1301"
  ],

}

And another variant that just extracts the IPv4 address:

$ tailscale status --json \
    | jq '[.Self] + [.Peer[]] | map({(.DNSName | split(".")[0]): (.TailscaleIPs[0])}) | add'
{
  "phaenna-mac-mini": "100.76.19.1",
  "go": "100.107.83.99",
  "alexs-macbook-pro": "100.109.169.87",

}

I’m planning to paste this directly into the hosts section of my policy file.

Tested with Tailscale 1.95.104. Disclaimer: At time of writing, I’m employed by Tailscale.