diff --git a/upstream/upstream.go b/upstream/upstream.go index 3a5113d39..51543f4ed 100644 --- a/upstream/upstream.go +++ b/upstream/upstream.go @@ -218,15 +218,14 @@ func validateUpstreamURL(u *url.URL) (err error) { host = h } - _, err = netip.ParseAddr(host) - if err == nil { - return nil - } - // If it's an IPv6 address enclosed in square brackets with no port. // // See https://github.com/AdguardTeam/dnsproxy/issues/379. - _, err = netip.ParseAddr(u.Hostname()) + if strings.HasPrefix(host, "[") && strings.HasSuffix(host, "]") { + _, err = netip.ParseAddr(host[1 : len(host)-1]) + } else { + _, err = netip.ParseAddr(host) + } if err == nil { return nil }