{"record":{"id":"d5ada0b5996c9489","repo":"alibaba/nacos","slug":"cannot-get-localhost-inetaddress-please-check-you","errorCode":null,"errorMessage":"Cannot get LocalHost InetAddress, please check your network!","messagePattern":"Cannot get LocalHost InetAddress, please check your network!","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"critical","filePath":"core/src/main/java/com/alibaba/nacos/core/distributed/id/SnowFlowerIdGenerator.java","lineNumber":88,"sourceCode":"    private long workerId;\n    \n    private long sequence;\n    \n    private long lastTime;\n    \n    private long currentId;\n    \n    {\n        long workerId = EnvUtil.getProperty(\"nacos.core.snowflake.worker-id\", Integer.class, -1);\n        \n        if (workerId != -1) {\n            this.workerId = workerId;\n        } else {\n            InetAddress address;\n            try {\n                address = InetAddress.getByName(InetUtils.getSelfIP());\n            } catch (final UnknownHostException e) {\n                throw new IllegalStateException(\n                    \"Cannot get LocalHost InetAddress, please check your network!\", e);\n            }\n            byte[] ipAddressByteArray = address.getAddress();\n            this.workerId =\n                (((ipAddressByteArray[ipAddressByteArray.length - 2] & 0B11) << Byte.SIZE)\n                    + (ipAddressByteArray[ipAddressByteArray.length - 1] & 0xFF));\n        }\n    }\n    \n    @Override\n    public void init() {\n        initialize(workerId);\n    }\n    \n    @Override\n    public long currentId() {\n        return currentId;\n    }","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/core/src/main/java/com/alibaba/nacos/core/distributed/id/SnowFlowerIdGenerator.java#L70-L106","documentation":"Thrown in the SnowFlowerIdGenerator instance initializer when InetAddress.getByName(InetUtils.getSelfIP()) fails with UnknownHostException. This means the server could not resolve its own advertised/local IP to an InetAddress, so a worker id cannot be derived from the IP bytes. It is an IllegalStateException that aborts bean construction (server fails to start).","triggerScenarios":"nacos.core.snowflake.worker-id is unset (default -1) AND InetUtils.getSelfIP() returns a hostname/IP that cannot be resolved by the JVM. The worker id is then computed from the last two bytes of the resolved IP address.","commonSituations":"Misconfigured nacos.inetUtils.ip / host that is not resolvable in /etc/hosts or DNS; containerized deployment where the self IP is not bound; network interface auto-detection picking an unreachable address; DNS temporarily unavailable at startup.","solutions":["Set nacos.core.snowflake.worker-id explicitly to a fixed value 0..1023 to bypass IP-based derivation.","Fix nacos.inetUtils.ip (or preferred network interface) so InetUtils.getSelfIP() returns a resolvable address.","Ensure /etc/hosts or DNS resolves the server hostname, and the network interface is up before Nacos starts."],"exampleFix":"// before\n# nacos.inetUtils.ip points to an unresolvable address -> startup fails\n\n// after (option A: fixed worker id)\n-Dnacos.core.snowflake.worker-id=1\n// after (option B: correct the self IP)\n-Dnacos.inetUtils.ip=10.0.0.5","handlingStrategy":"validation","validationCode":"String selfIp = InetUtils.getSelfIP();\ntry {\n    InetAddress.getByName(selfIp);\n} catch (UnknownHostException e) {\n    // fix config or set -Dnacos.core.snowflake.worker-id before starting\n}","typeGuard":null,"tryCatchPattern":"try {\n    new SnowFlowerIdGenerator();\n} catch (IllegalStateException e) {\n    // set a fixed worker-id or fix inetUtils config\n}","preventionTips":["Set nacos.core.snowflake.worker-id explicitly in multi-node/clustered setups.","Ensure InetUtils.getSelfIP() returns a resolvable address before startup."],"tags":["id-generator","snowflake","network","startup","inet","configuration"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}