chore: Remove default DNS in system resolver

This commit is contained in:
H1JK 2023-05-01 12:41:36 +08:00
parent f35ff24d0c
commit 969c235490
4 changed files with 9 additions and 12 deletions

View file

@ -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)

View file

@ -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

View file

@ -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...)

View file

@ -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 池设置