From e680acf42df7718720dbe5181180681037cd02e1 Mon Sep 17 00:00:00 2001 From: fatedier Date: Thu, 23 May 2024 16:09:58 +0800 Subject: [PATCH] android: only use google dns server when the default dns server cannot be obtained (#4236) --- Release.md | 1 + pkg/util/system/system_android.go | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Release.md b/Release.md index ef65ec1c..5cb27c3e 100644 --- a/Release.md +++ b/Release.md @@ -5,3 +5,4 @@ ### Changes * Updated the default value of `transport.tcpMuxKeepaliveInterval` from 60 to 30. +* On the Android platform, the Google DNS server is used only when the default DNS server cannot be obtained. diff --git a/pkg/util/system/system_android.go b/pkg/util/system/system_android.go index bfcf401d..6fcfdbc1 100644 --- a/pkg/util/system/system_android.go +++ b/pkg/util/system/system_android.go @@ -59,8 +59,12 @@ func fixDNSResolver() { // Note: If there are other methods to obtain the default DNS servers, the default DNS servers should be used preferentially. net.DefaultResolver = &net.Resolver{ PreferGo: true, - Dial: func(ctx context.Context, network, _ string) (net.Conn, error) { - return net.Dial(network, "8.8.8.8:53") + Dial: func(ctx context.Context, network, addr string) (net.Conn, error) { + if addr == "127.0.0.1:53" || addr == "[::1]:53" { + addr = "8.8.8.8:53" + } + var d net.Dialer + return d.DialContext(ctx, network, addr) }, } }