summaryrefslogtreecommitdiffhomepage
path: root/net/dnscache/dnscache.go
diff options
context:
space:
mode:
Diffstat (limited to 'net/dnscache/dnscache.go')
-rw-r--r--net/dnscache/dnscache.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/net/dnscache/dnscache.go b/net/dnscache/dnscache.go
index 2cbea6c0f..3cbb5ccd8 100644
--- a/net/dnscache/dnscache.go
+++ b/net/dnscache/dnscache.go
@@ -202,6 +202,20 @@ func (r *Resolver) LookupIP(ctx context.Context, host string) (ip, v6 netip.Addr
r.dlogf("returning %d static results", len(allIPs))
return
}
+
+ // Hard-code this to avoid extra work, DNS fallbacks, etc.
+ if host == "localhost" {
+ r.dlogf("host is localhost")
+
+ // TODO: @raggi mentioned that some distributions don't use
+ // 127.0.0.1 as the localhost IP; should we check the interface
+ // address to determine this?
+ ip = netip.AddrFrom4([4]byte{127, 0, 0, 1})
+ v6 = netip.IPv6Loopback()
+ allIPs = []netip.Addr{ip, v6}
+ err = nil
+ return
+ }
if ip, err := netip.ParseAddr(host); err == nil {
ip = ip.Unmap()
r.dlogf("%q is an IP", host)