Skip to content

Instantly share code, notes, and snippets.

@varenc
Created July 25, 2024 19:25
Show Gist options
  • Save varenc/971796720a31c3b16e6c99903794bc1e to your computer and use it in GitHub Desktop.
Save varenc/971796720a31c3b16e6c99903794bc1e to your computer and use it in GitHub Desktop.
Tailscale on macOS DNS resolver workaround to https://github.com/tailscale/tailscale/issues/12244
# Workaround for https://github.com/tailscale/tailscale/issues/12244 on macOS
### Usage
# Just put this in a shell RC file (~/.zshrc) and run `tailscaleDNSHack`
# With no params it sets the tailscale DNS to what your `NET_SERVICE`'s DNS is.
# Or pass in an argument to set that as the DNS
function tailscaleDNSHack () {
local NET_SERVICE="Wi-Fi"
if [ -z $1 ]
then
local NEW_DNS="$(networksetup -getdnsservers "$NET_SERVICE")"
echo "No DNS passed in, using primary interface default: $NEW_DNS"
else
local NEW_DNS="$1"
fi
local TS_UUID="$(scutil --nc list | awk '/io.tailscale.ipn.macos/ {print $3}')"
echo "Setting DNS for Tailscale service UUID '$TS_UUID' to '$NEW_DNS'"
sudo scutil <<EOF
open
d.init
d.add ServerAddresses * $NEW_DNS
set State:/Network/Service/$TS_UUID/DNS
quit
EOF
echo "Done setting DNS for Tailscale service UUID '$TS_UUID' to '$NEW_DNS'! Here's the result:"
echo "show State:/Network/Service/${TS_UUID}/DNS" | scutil
}
@varenc
Copy link
Author

varenc commented Oct 17, 2024

To clear this easily I've been using this script:

function tsClearDNS () {
	local TS_UUID="$(tsUUID)"
	echo "Will remove DNS for Tailscale service UUID '$TS_UUID', existing settings:"
	echo "show State:/Network/Service/${TS_UUID}/DNS" | scutil
	echo "pausing... Ctrl-C to cancel...."
	sleep 3
	echo "remove State:/Network/Service/${TS_UUID}/DNS" | sudo scutil
	echo "Removed DNS for Tailscale service UUID '$TS_UUID'! Here's the result:"
	echo "show State:/Network/Service/${TS_UUID}/DNS" | scutil
}
function tsUUID () {
	scutil --nc list | awk '/io.tailscale.ipn.macos/ {print $3}'
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment