Find out tailnet name from script?

Tailscale version


Your operating system & version

Various Linux (Debian buster to bullseye) and MacOS from Catalina to Ventura.

I am attempting automate a few deployment things I am doing and to my surprise I did not find an easy way to find my own tailnet name. I looked at the various tail scale subcommands but could not find anything. I am I looking at the wrong places? Do I need to use the API to find out?

If you add the --json flag to the tailscale status command, you’ll get back a verbose JSON where you can find your tailname under MagicDNSSuffix. (It pops up in multiple places throughout the JSON though.)
I don’t know where you would have to look if you didn’t use MagicDNS though.

EDIT: If you have jq installed, you can use this command to extract the MagicDNS name:
tailscale status --json | jq -j '.MagicDNSSuffix' (The -j removes the double quotes from the returned value.)

EDIT 2: Ah shoot, you ninja’d my first edit. :smiley:

Indeed, that is what I was looking for! The following works for me:

tailscale status --json|jq '.MagicDNSSuffix'

I believe what values I will settle on are these:

tailscale status --json|jq -j '.Self.HostName,"\n",.Self.DNSName,"\n"'

And using that as the starting value for my scripts. Thanks for the pointer!

1 Like