diff --git a/config/config.go b/config/config.go index 35929849..6425934e 100644 --- a/config/config.go +++ b/config/config.go @@ -1144,6 +1144,9 @@ func parseDNS(rawCfg *RawConfig, hosts *trie.DomainTrie[resolver.HostValue], rul } // check default nameserver is pure ip addr for _, ns := range dnsCfg.DefaultNameserver { + if ns.Net == "system" { + continue + } host, _, err := net.SplitHostPort(ns.Addr) if err != nil || net.ParseIP(host) == nil { u, err := url.Parse(ns.Addr) diff --git a/dns/system_windows.go b/dns/system_windows.go index 3e9736d0..2e0aa237 100644 --- a/dns/system_windows.go +++ b/dns/system_windows.go @@ -12,10 +12,6 @@ import ( "golang.org/x/sys/windows" ) -var ( - defaultNS = []string{"114.114.114.114:53"} -) - type dnsConfig struct { servers []string // server addresses (in host:port form) to use } @@ -27,7 +23,6 @@ func loadSystemResolver() (clients []dnsClient, err error) { } nameservers := content.servers if len(nameservers) == 0 { - err = fmt.Errorf("no nameserver found in windows system") return } servers := make([]NameServer, 0, len(nameservers)) @@ -42,11 +37,6 @@ func loadSystemResolver() (clients []dnsClient, err error) { func dnsReadConfig() (conf *dnsConfig, err error) { conf = &dnsConfig{} - defer func() { - if len(conf.servers) == 0 { - conf.servers = defaultNS - } - }() aas, err := adapterAddresses() if err != nil { return conf, err diff --git a/dns/util.go b/dns/util.go index 948687ac..d85deb17 100644 --- a/dns/util.go +++ b/dns/util.go @@ -82,7 +82,11 @@ func transform(servers []NameServer, resolver *Resolver) []dnsClient { case "system": clients, err := loadSystemResolver() if err != nil { - log.Warnln("[DNS:system] load system resolver failed: %s", err.Error()) + log.Errorln("[DNS:system] load system resolver failed: %s", err.Error()) + continue + } + if len(clients) == 0 { + log.Errorln("[DNS:system] no nameserver found in system") continue } ret = append(ret, clients...) diff --git a/docs/config.yaml b/docs/config.yaml index 2be8be37..66cab25c 100644 --- a/docs/config.yaml +++ b/docs/config.yaml @@ -177,7 +177,7 @@ dns: - 8.8.8.8 - tls://1.12.12.12:853 - tls://223.5.5.5:853 - - system:// # get DNS server from system's configuration + - system:// # append DNS server from system configuration. If not found, it would print an error log and skip. enhanced-mode: fake-ip # or redir-host fake-ip-range: 198.18.0.1/16 # fake-ip 池设置