in impl/src/main/java/org/apache/rocketmq/remoting/internal/NetworkUtils.java [52:80]
public static String getLocalHostIp() {
try {
for (Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces(); ifaces.hasMoreElements(); ) {
NetworkInterface iface = ifaces.nextElement();
// Workaround for docker0 bridge
if ("docker0".equals(iface.getName()) || !iface.isUp()) {
continue;
}
InetAddress ia;
for (Enumeration<InetAddress> ips = iface.getInetAddresses(); ips.hasMoreElements(); ) {
ia = ips.nextElement();
if (ia instanceof Inet4Address) {
// Check if the address is any local or loop back(127.0.0.1 or ::1)
if (!ia.isLoopbackAddress() && ia.getHostAddress().indexOf(':') == -1) {
if (ia.isSiteLocalAddress()) {
return ia.getHostAddress();
} else if (!ia.isLinkLocalAddress() && !ia.isAnyLocalAddress()
&& !ia.isMulticastAddress()) {
return ia.getHostAddress();
}
}
}
}
}
} catch (SocketException e) {
throw new RuntimeException("Could not get local host ip", e);
}
return DEFAULT_LOCAL_ADDRESS;
}