alibaba/nacos · critical · IllegalStateException

Cannot get LocalHost InetAddress, please check your network!

Error message

Cannot get LocalHost InetAddress, please check your network!

What it means

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).

Source

Thrown at core/src/main/java/com/alibaba/nacos/core/distributed/id/SnowFlowerIdGenerator.java:88

    private long workerId;
    
    private long sequence;
    
    private long lastTime;
    
    private long currentId;
    
    {
        long workerId = EnvUtil.getProperty("nacos.core.snowflake.worker-id", Integer.class, -1);
        
        if (workerId != -1) {
            this.workerId = workerId;
        } else {
            InetAddress address;
            try {
                address = InetAddress.getByName(InetUtils.getSelfIP());
            } catch (final UnknownHostException e) {
                throw new IllegalStateException(
                    "Cannot get LocalHost InetAddress, please check your network!", e);
            }
            byte[] ipAddressByteArray = address.getAddress();
            this.workerId =
                (((ipAddressByteArray[ipAddressByteArray.length - 2] & 0B11) << Byte.SIZE)
                    + (ipAddressByteArray[ipAddressByteArray.length - 1] & 0xFF));
        }
    }
    
    @Override
    public void init() {
        initialize(workerId);
    }
    
    @Override
    public long currentId() {
        return currentId;
    }

View on GitHub (pinned to 9b989acdf1)

Solutions

  1. Set nacos.core.snowflake.worker-id explicitly to a fixed value 0..1023 to bypass IP-based derivation.
  2. Fix nacos.inetUtils.ip (or preferred network interface) so InetUtils.getSelfIP() returns a resolvable address.
  3. Ensure /etc/hosts or DNS resolves the server hostname, and the network interface is up before Nacos starts.

Example fix

// before
# nacos.inetUtils.ip points to an unresolvable address -> startup fails

// after (option A: fixed worker id)
-Dnacos.core.snowflake.worker-id=1
// after (option B: correct the self IP)
-Dnacos.inetUtils.ip=10.0.0.5
Defensive patterns

Strategy: validation

Validate before calling

String selfIp = InetUtils.getSelfIP();
try {
    InetAddress.getByName(selfIp);
} catch (UnknownHostException e) {
    // fix config or set -Dnacos.core.snowflake.worker-id before starting
}

Try / catch

try {
    new SnowFlowerIdGenerator();
} catch (IllegalStateException e) {
    // set a fixed worker-id or fix inetUtils config
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14). Data as JSON: /api/errors/d5ada0b5996c9489. Report an issue: GitHub.