micro/go-micro · error
could not determine host IP addresses for %s
Error message
could not determine host IP addresses for %s
What it means
When no IPs are supplied, NewMDNSService attempts net.LookupIP on the hostname (or hostname+domain as a fallback) to discover A/AAAA records. If that lookup fails, this error reports that no IP addresses could be determined for the host, so A records cannot be published.
Source
Thrown at internal/util/mdns/zone.go:108
}
hostName = fmt.Sprintf("%s.", hostName)
}
if err := validateFQDN(hostName); err != nil {
return nil, fmt.Errorf("hostName %q is not a fully-qualified domain name: %v", hostName, err)
}
if len(ips) == 0 {
var err error
ips, err = net.LookupIP(trimDot(hostName))
if err != nil {
// Try appending the host domain suffix and lookup again
// (required for Linux-based hosts)
tmpHostName := fmt.Sprintf("%s%s", hostName, domain)
ips, err = net.LookupIP(trimDot(tmpHostName))
if err != nil {
return nil, fmt.Errorf("could not determine host IP addresses for %s", hostName)
}
}
}
for _, ip := range ips {
if ip.To4() == nil && ip.To16() == nil {
return nil, fmt.Errorf("invalid IP address in IPs list: %v", ip)
}
}
return &MDNSService{
Instance: instance,
Service: service,
Domain: domain,
HostName: hostName,
Port: port,
IPs: ips,
TXT: txt,
TTL: defaultTTL,View on GitHub (pinned to 24529f1404)
Solutions
- Pass an explicit ips slice (e.g. discovered interface addresses) so no lookup is performed: net.InterfaceAddrs() filtered to IPNet addresses
- Ensure the machine's hostname resolves: add it to /etc/hosts or configure DNS
- Check network/DNS configuration on the host; the wrapped lookup must succeed for auto-discovery
Example fix
// before
svc, err := NewMDNSService("myapp", "_http._tcp", "local.", "", 8080, nil, nil) // lookup fails offline
// after
var ips []net.IP
if addrs, err := net.InterfaceAddrs(); err == nil {
for _, a := range addrs {
if ipnet, ok := a.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
ips = append(ips, ipnet.IP)
}
}
}
svc, err2 := NewMDNSService("myapp", "_http._tcp", "local.", "", 8080, ips, nil) Defensive patterns
Strategy: fallback
Validate before calling
func localIPs() []net.IP {
var ips []net.IP
if addrs, err := net.InterfaceAddrs(); err == nil {
for _, a := range addrs {
if ipnet, ok := a.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
ips = append(ips, ipnet.IP)
}
}
}
return ips // pass explicitly to skip DNS lookup
} Type guard
func hasUsableIPs(ips []net.IP) bool {
return len(ips) > 0
} Try / catch
svc, err := NewMDNSService(instance, service, domain, hostName, port, ips, txt)
if err != nil {
if strings.Contains(err.Error(), "could not determine host IP addresses") {
// offline host: fall back to explicit interface addresses or skip registration
return fmt.Errorf("pass explicit IPs or fix DNS/hosts resolution: %w", err)
}
return err
} Prevention
- Discover interface addresses locally (net.InterfaceAddrs) and pass them instead of relying on DNS lookup
- Ensure the machine's own hostname resolves (add it to /etc/hosts) in containers and offline hosts
- Defer registration until the network is up, or retry registration on failure
When it happens
Trigger: Calling NewMDNSService(instance, service, domain, hostName, port, nil/[], txt) on a machine where DNS/mDNS resolution of its own hostname fails — no resolver configured, hostname not in /etc/hosts, or the host has no network interfaces.
Common situations: Offline or air-gapped machines; containers whose hostname isn't resolvable; freshly provisioned VMs before /etc/hosts is populated; VPN-only environments where the lookup path is broken.
Related errors
- invalid IP address in IPs list: %v
- ErrIPNotFound
- failed to bind to any unicast udp port
- failed to bind to any multicast udp port
- failed to join multicast group on all interfaces
AI-assisted analysis of micro/go-micro@24529f1404 (2026-09-01).
Data as JSON: /api/errors/f959a484815c662c.
Report an issue: GitHub.