Skip to content

Instantly share code, notes, and snippets.

@luckman212
Last active December 9, 2025 16:49
Show Gist options
  • Select an option

  • Save luckman212/356dfc72396b838a055ec10d315b042b to your computer and use it in GitHub Desktop.

Select an option

Save luckman212/356dfc72396b838a055ec10d315b042b to your computer and use it in GitHub Desktop.
#!/bin/zsh --no-rcs
# https://github.com/tailscale/tailscale/issues/18101
# https://gist.github.com/luckman212/356dfc72396b838a055ec10d315b042b
zmodload zsh/datetime
#get a random peer
ts_json=$(tailscale status --json)
all_peers=$(jq '.Peer | to_entries | map(select(.value.DNSName!="")) | map(.value.DNSName)' <<< "$ts_json")
num_peers=$(jq 'length' <<< "$all_peers")
ts_domain=$(jq -r '.MagicDNSSuffix' <<< "$ts_json")
peer=$(jq -r --argjson i $(( RANDOM % num_peers )) '.[$i] | sub("\\.$";"")' <<< "$all_peers")
[[ -n $peer ]] && [[ -n $ts_domain ]] || exit 1
# install quad100 resolver stub
stub="/etc/resolver/$ts_domain"
if [[ ! -e $stub ]]; then
echo "adding DNS override at $stub"
sudo ${SUDO_ASKPASS:+-A} mkdir -p /etc/resolver
echo "nameserver 100.100.100.100" | sudo ${SUDO_ASKPASS:+-A} tee >/dev/null "$stub"
fi
case $1 in
-f|--flush)
echo "flushing DNS cache"
sudo ${SUDO_ASKPASS:+-A} killall -q -HUP mDNSResponder
sudo ${SUDO_ASKPASS:+-A} dscacheutil -flushcache
;;
esac
start=$EPOCHSECONDS
# bug should appear after 15 seconds
while true; do
ts_status=$(tailscale status --json | jq -r '.Health | map(select(test("unstable")|not))[] // "healthy"')
case $ts_status in
healthy) : ;; #no-op
*) echo -e "\033[1;31m${ts_status}\033[0m";;
esac
printf 'elapsed: [%3.fs] %s ' $(( EPOCHSECONDS - start )) "querying $peer using dscacheutil:"
dscacheutil -q host -a name "$peer" | grep ip_address || echo '?'
sleep 1
done
@luckman212
Copy link
Author

luckman212 commented Dec 6, 2025

⚠️ N.B. The version of this script posted prior to 2025-12-07 contained an error, which is fixed now

Install & run

curl -Lso tsbug https://gist.github.com/luckman212/356dfc72396b838a055ec10d315b042b/raw && chmod +x tsbug
./tsbug

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