Fallback to the system resolver if the fallback resolver doesn't work

This is useful if fallback_resolver has been set to random junk, or
to an external resolver, but port 53 is blocked.

At least, it may allow the server to start.
This commit is contained in:
Frank Denis 2019-11-17 22:00:08 +01:00
parent b03e7f993f
commit ad40c6c54b
2 changed files with 6 additions and 2 deletions

View File

@ -198,8 +198,7 @@ cert_refresh_delay = 240
fallback_resolver = '9.9.9.9:53' fallback_resolver = '9.9.9.9:53'
## Never let dnscrypt-proxy try to use the system DNS settings; ## Always use the fallback resolver before the system DNS settings
## unconditionally use the fallback resolver.
ignore_system_dns = true ignore_system_dns = true

View File

@ -279,6 +279,10 @@ func (xTransport *XTransport) resolveWithCache(host string) (err error) {
} }
} }
} }
if err != nil && xTransport.ignoreSystemDNS {
dlog.Noticef("Fallback resolver [%v] didn't respond - Trying with the system resolver as a last resort", xTransport.fallbackResolver)
foundIP, ttl, err = xTransport.resolveUsingSystem(host)
}
if ttl < MinResolverIPTTL { if ttl < MinResolverIPTTL {
ttl = MinResolverIPTTL ttl = MinResolverIPTTL
} }
@ -323,6 +327,7 @@ func (xTransport *XTransport) Fetch(method string, url *url.URL, accept string,
return nil, 0, errors.New("Onion service is not reachable without Tor") return nil, 0, errors.New("Onion service is not reachable without Tor")
} }
if err := xTransport.resolveWithCache(host); err != nil { if err := xTransport.resolveWithCache(host); err != nil {
dlog.Errorf("Unable to resolve [%v] - Make sure that the system resolver works, or that `fallback_resolver` has been set to a resolver that can be reached", host)
return nil, 0, err return nil, 0, err
} }
req := &http.Request{ req := &http.Request{