diff --git a/naming/src/main/java/com/alibaba/nacos/naming/misc/NetUtils.java b/naming/src/main/java/com/alibaba/nacos/naming/misc/NetUtils.java index de81b899c..7358e5f67 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/misc/NetUtils.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/misc/NetUtils.java @@ -28,17 +28,16 @@ import static com.alibaba.nacos.common.util.SystemUtils.PREFER_HOSTNAME_OVER_IP; */ public class NetUtils { - private static String localIpAddress = null; + private static String serverAddress = null; - public static String localIP() { public static String localServer() { try { - if (StringUtils.isBlank(localIpAddress)) { - localIpAddress = InetAddress.getLocalHost().getHostAddress(); + if (StringUtils.isNotBlank(serverAddress)) { + return serverAddress + UtilsAndCommons.CLUSTER_CONF_IP_SPLITER + RunningConfig.getServerPort(); } - return localIpAddress + ":" + RunningConfig.getServerPort(); + InetAddress inetAddress = InetAddress.getLocalHost(); - String serverAddress = inetAddress.getHostAddress(); + serverAddress = inetAddress.getHostAddress(); if (PREFER_HOSTNAME_OVER_IP) { if (inetAddress.getHostName().equals(inetAddress.getCanonicalHostName())) { serverAddress = inetAddress.getHostName(); diff --git a/naming/src/main/java/com/alibaba/nacos/naming/web/ApiCommands.java b/naming/src/main/java/com/alibaba/nacos/naming/web/ApiCommands.java index aee085e92..d42a398aa 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/web/ApiCommands.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/web/ApiCommands.java @@ -973,7 +973,7 @@ public class ApiCommands { if (RaftCore.isLeader()) { try { domainsManager.getDom2LockMap().get(dom).lock(); - proxyParams.put("clientIP", NetUtils.localIP()); + proxyParams.put("clientIP", NetUtils.localServer()); proxyParams.put("notify", "true"); proxyParams.put("term", String.valueOf(RaftCore.getPeerSet().local().term));