private static InetAddress doGetLocalHost() throws UnknownHostException, SocketException {
    InetAddress localHost = InetAddress.getLocalHost();
    if (localHost.isLoopbackAddress()) {
      LOG.debug("Hostname {} resolves to a loopback address, trying to resolve an external IP address.",
          localHost.getHostName());
      List<NetworkInterface> networkInterfaces;
      if (System.getProperty("os.name").startsWith("Windows")) {
        networkInterfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
      } else {
        networkInterfaces = Lists.reverse(Collections.list(NetworkInterface.getNetworkInterfaces()));
      }
      for (NetworkInterface networkInterface : networkInterfaces) {
        List<InetAddress> addresses = Collections.list(networkInterface.getInetAddresses())
            .stream()
            .filter(address -> !(address.isLinkLocalAddress() || address.isLoopbackAddress()))
            .collect(Collectors.toList());
        if (!addresses.isEmpty()) {
          InetAddress address = addresses.stream()
              .filter(addr -> addr instanceof Inet4Address)
              .findFirst()
              .orElseGet(() -> addresses.get(0));
          LOG.debug("Found an external IP address {} which represents the localhost.", address.getHostAddress());
          return InetAddress.getByAddress(address.getAddress());
        }
      }
    }
    return localHost;
  }
Returns the the first host address which is not the loopback address, or {@link InetAddress#getLocalHost} as a
fallback.

@return the {@link InetAddress} which represents the localhost
samza-core/src/main/java/org/apache/samza/util/Util.java