diff --git a/client/fingerprint/network_unix.go b/client/fingerprint/network_unix.go index 020c9951615..9a422ec01ba 100644 --- a/client/fingerprint/network_unix.go +++ b/client/fingerprint/network_unix.go @@ -34,11 +34,13 @@ func (f *NetworkFingerprint) Fingerprint(cfg *config.Config, node *structs.Node) // newNetwork is populated and addded to the Nodes resources newNetwork := &structs.NetworkResource{} defaultDevice := "" + ip := "" // 1. Use user-defined network device // 2. Use first interface found in the system for non-dev mode. (dev mode uses lo by default.) if cfg.NetworkInterface != "" { defaultDevice = cfg.NetworkInterface + ip = f.ipAddress(defaultDevice) } else { intfs, err := net.Interfaces() @@ -48,19 +50,19 @@ func (f *NetworkFingerprint) Fingerprint(cfg *config.Config, node *structs.Node) for _, i := range intfs { if (i.Flags&net.FlagUp != 0) && (i.Flags&(net.FlagLoopback|net.FlagPointToPoint) == 0) { - if ip := f.ipAddress(i.Name); ip != "" { + if ip = f.ipAddress(i.Name); ip != "" { defaultDevice = i.Name - node.Attributes["network.ip-address"] = ip - newNetwork.IP = ip - newNetwork.CIDR = newNetwork.IP + "/32" break } } } } - if defaultDevice != "" { + if (defaultDevice != "") && (ip != "") { newNetwork.Device = defaultDevice + node.Attributes["network.ip-address"] = ip + newNetwork.IP = ip + newNetwork.CIDR = newNetwork.IP + "/32" } else { return false, fmt.Errorf("Unable to find any network interface which has IP address") }