feat(dns): use system nameservers from /etc/resolv.conf as fallback
When no forwarder or dns metadata is configured, the DNS handler now reads system nameservers from /etc/resolv.conf (Unix) before falling back to the hardcoded 127.0.0.1:53 default. This makes the DNS proxy work out-of-the-box without requiring explicit DNS server configuration. Fixes go-gost/gost#89
This commit is contained in:
@@ -108,6 +108,23 @@ func (h *dnsHandler) Init(md md.Metadata) (err error) {
|
||||
h.exchangers[node.Name] = ex
|
||||
}
|
||||
|
||||
if len(h.exchangers) == 0 {
|
||||
// Try system nameservers first (from /etc/resolv.conf on Unix).
|
||||
for i, addr := range systemNameservers() {
|
||||
ex, err := exchanger.NewExchanger(
|
||||
addr,
|
||||
exchanger.RouterOption(h.options.Router),
|
||||
exchanger.TimeoutOption(h.md.timeout),
|
||||
exchanger.LoggerOption(log),
|
||||
)
|
||||
if err != nil {
|
||||
log.Warnf("system nameserver %s: %v", addr, err)
|
||||
continue
|
||||
}
|
||||
h.exchangers[fmt.Sprintf("system-%d", i)] = ex
|
||||
}
|
||||
}
|
||||
|
||||
if len(h.exchangers) == 0 {
|
||||
ex, err := exchanger.NewExchanger(
|
||||
defaultNameserver,
|
||||
|
||||
Reference in New Issue
Block a user