Troubleshoot UnknownHostException during application startup

更新时间:
复制 MD 格式

An Enterprise Distributed Application Service (EDAS) application fails to start and throws UnknownHostException. This topic explains the cause and provides steps to resolve the issue.

Symptom

The application fails to start in the EDAS console with the following error:

UnknownHostException

Cause

The hostname of the machine was changed, but /etc/hosts was not updated to reflect the new name.

During startup, the Java runtime calls InetAddress.getLocalHost() to resolve the local hostname. If the current hostname has no matching entry in /etc/hosts, the lookup fails and throws UnknownHostException.

Solution

Add the current hostname to /etc/hosts so that the Java runtime can resolve it.

Step 1: Check the current hostname

Run the following command to display the current hostname:

hostname

Example output:

my-edas-node

Step 2: Check /etc/hosts for a matching entry

cat /etc/hosts

If the output does not contain a line that maps the hostname (my-edas-node in this example) to an IP address, the entry is missing.

Step 3: Add the hostname to /etc/hosts

Open /etc/hosts and add a line that maps 127.0.0.1 to the current hostname:

echo "127.0.0.1 $(hostname)" | sudo tee -a /etc/hosts

After the edit, /etc/hosts should contain a line similar to:

127.0.0.1 my-edas-node

Step 4: Verify the fix

  1. Confirm that the hostname resolves:

    ping -c 1 $(hostname)

    A successful response confirms that the hostname now resolves to an IP address.

  2. Restart the application in the EDAS console and verify that it starts without the UnknownHostException error.

Prevent recurrence

When you change the hostname on a machine that runs EDAS applications, always update /etc/hosts at the same time to keep the two in sync.

If the issue persists

If the application still fails to start after you update /etc/hosts, check the application logs in the EDAS console for other errors.