chore: Remove default DNS in system resolver

This commit is contained in:
gVisor bot 2023-05-01 12:41:36 +08:00
parent 77dac1090d
commit e4a0b3b2f1
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 // check default nameserver is pure ip addr
for _, ns := range dnsCfg.DefaultNameserver { for _, ns := range dnsCfg.DefaultNameserver {
if ns.Net == "system" {
continue
}
host, _, err := net.SplitHostPort(ns.Addr) host, _, err := net.SplitHostPort(ns.Addr)
if err != nil || net.ParseIP(host) == nil { if err != nil || net.ParseIP(host) == nil {
u, err := url.Parse(ns.Addr) u, err := url.Parse(ns.Addr)

View file

@ -12,10 +12,6 @@ import (
"golang.org/x/sys/windows" "golang.org/x/sys/windows"
) )
var (
defaultNS = []string{"114.114.114.114:53"}
)
type dnsConfig struct { type dnsConfig struct {
servers []string // server addresses (in host:port form) to use servers []string // server addresses (in host:port form) to use
} }
@ -27,7 +23,6 @@ func loadSystemResolver() (clients []dnsClient, err error) {
} }
nameservers := content.servers nameservers := content.servers
if len(nameservers) == 0 { if len(nameservers) == 0 {
err = fmt.Errorf("no nameserver found in windows system")
return return
} }
servers := make([]NameServer, 0, len(nameservers)) servers := make([]NameServer, 0, len(nameservers))
@ -42,11 +37,6 @@ func loadSystemResolver() (clients []dnsClient, err error) {
func dnsReadConfig() (conf *dnsConfig, err error) { func dnsReadConfig() (conf *dnsConfig, err error) {
conf = &dnsConfig{} conf = &dnsConfig{}
defer func() {
if len(conf.servers) == 0 {
conf.servers = defaultNS
}
}()
aas, err := adapterAddresses() aas, err := adapterAddresses()
if err != nil { if err != nil {
return conf, err return conf, err

View file

@ -82,7 +82,11 @@ func transform(servers []NameServer, resolver *Resolver) []dnsClient {
case "system": case "system":
clients, err := loadSystemResolver() clients, err := loadSystemResolver()
if err != nil { 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 continue
} }
ret = append(ret, clients...) ret = append(ret, clients...)

View file

@ -177,7 +177,7 @@ dns:
- 8.8.8.8 - 8.8.8.8
- tls://1.12.12.12:853 - tls://1.12.12.12:853
- tls://223.5.5.5: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 enhanced-mode: fake-ip # or redir-host
fake-ip-range: 198.18.0.1/16 # fake-ip 池设置 fake-ip-range: 198.18.0.1/16 # fake-ip 池设置