- use 127.0.0.1 as a resolver address when DNS binding address is 0.0.0.0

This commit is contained in:
Simon Zolin 2019-04-23 19:37:14 +03:00
parent 3087c54a15
commit 528c1a72ca
2 changed files with 10 additions and 2 deletions

6
dns.go
View File

@ -50,7 +50,11 @@ func generateServerConfig() dnsforward.ServerConfig {
FilteringConfig: config.DNS.FilteringConfig, FilteringConfig: config.DNS.FilteringConfig,
Filters: filters, Filters: filters,
} }
newconfig.ResolverAddress = fmt.Sprintf("%s:%d", config.DNS.BindHost, config.DNS.Port) bindhost := config.DNS.BindHost
if config.DNS.BindHost == "0.0.0.0" {
bindhost = "127.0.0.1"
}
newconfig.ResolverAddress = fmt.Sprintf("%s:%d", bindhost, config.DNS.Port)
if config.TLS.Enabled { if config.TLS.Enabled {
newconfig.TLSConfig = config.TLS.TLSConfig newconfig.TLSConfig = config.TLS.TLSConfig

View File

@ -323,7 +323,11 @@ func customDialContext(ctx context.Context, network, addr string) (net.Conn, err
return con, err return con, err
} }
resolverAddr := fmt.Sprintf("%s:%d", config.DNS.BindHost, config.DNS.Port) bindhost := config.DNS.BindHost
if config.DNS.BindHost == "0.0.0.0" {
bindhost = "127.0.0.1"
}
resolverAddr := fmt.Sprintf("%s:%d", bindhost, config.DNS.Port)
r := upstream.NewResolver(resolverAddr, 30*time.Second) r := upstream.NewResolver(resolverAddr, 30*time.Second)
addrs, e := r.LookupIPAddr(ctx, host) addrs, e := r.LookupIPAddr(ctx, host)
log.Tracef("LookupIPAddr: %s: %v", host, addrs) log.Tracef("LookupIPAddr: %s: %v", host, addrs)