From a7b3ae04b0b3cf3345dd3a021d6a71d3c7eea418 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 3 May 2023 19:37:05 -0700 Subject: [PATCH] cmd/tailscale: use Google as DNS of last resort Sometimes we try a dozen different ways to read the phone's DNS settings and it still comes back empty. In that case, if we're already on a Google-ified Android phone, just use Google's Public DNS servers as the ultimate fallback, as we already do on ChromeOS to work around ChromeOS Android VpnBuilder bugs. Updates tailscale/tailscale#8006 etc etc Signed-off-by: Brad Fitzpatrick --- cmd/tailscale/backend.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cmd/tailscale/backend.go b/cmd/tailscale/backend.go index 0d73465..3573576 100644 --- a/cmd/tailscale/backend.go +++ b/cmd/tailscale/backend.go @@ -426,7 +426,19 @@ func (b *backend) getPlatformDNSConfig() string { return baseConfig } -func (b *backend) getDNSBaseConfig() (dns.OSConfig, error) { +func (b *backend) getDNSBaseConfig() (ret dns.OSConfig, _ error) { + defer func() { + // If we couldn't find any base nameservers, ultimately fall back to + // Google's. Normally Tailscale doesn't ever pick a default nameserver + // for users but in this case Android's APIs for reading the underlying + // DNS config are lacking, and almost all Android phones use Google + // services anyway, so it's a reasonable default: it's an ecosystem the + // user has selected by having an Android device. + if len(ret.Nameservers) == 0 && googleSignInEnabled() { + log.Printf("getDNSBaseConfig: none found; falling back to Google public DNS") + ret.Nameservers = append(ret.Nameservers, googleDNSServers...) + } + }() b.logDNSConfigMechanisms() baseConfig := b.getPlatformDNSConfig() lines := strings.Split(baseConfig, "\n")