Elastic Cloud Server

Map hostname to IP address

2025-12-11 07:37:16

Restriction and Limitations

Only applicable to Linux Elastic Cloud Servers in the same VPC.

You can view the VPC of Elastic Cloud Server in the following ways:

a. Log in to the cloud server console.

b. Click Instance.

c. View the VPC.

Procedure

Assuming that there are two Elastic Cloud Servers in the same VPC: ecm-53a1 and ecm-9d59. By doing the following, the two Elastic Cloud Servers can communicate with each other through the hostnames.

1. Obtain the IP addresses of the two Elastic Cloud Servers.

a. Log in to the cloud server console.

b. View the IPv4 addresses of the cloud servers in the cloud server list.
Example: Suppose the IP addresses are as follows:
ecm-53a1:10.0.0.4
ecm-9d59:10.0.0.5

2. Obtain the hostnames of the two Elastic Cloud Servers separately.

a. Log in to the Elastic Cloud Server.
b. Execute the following command to query the hostname of the Elastic Cloud Server.

sudo hostname

Example: Suppose the hostnames are as follows:

ecm-53a1:ecm-53a1

ecm-9d59:ecm-9d59

3. Establish a mapping relationship between hostnames and IP addresses, and add information about other Elastic Cloud Servers in the same VPC.

a. Log in to the ECS ecm-53a1.
    b. Execute the following command to switch to root permissions.

  sudo su -

c. Execute the following command to edit the hosts file.

 vi /etc/hosts

d. Press i to enter the Edit mode.

e. Add statements in the following format to establish a mapping relationship.

IP address hostname

Example: The statement to be added:

10.0.0.4 ecm-53a1

10.0.0.5 ecm-9d59

f. Press Esc to exit the Edit mode and execute the following command to save and exit.

:wq

g. Log in to and repeat steps 3.b~3.f.

 

4. Test to verify whether communication is normal with the hostnames.

Log in to the configured Elastic Cloud Servers separately, execute the following command to check if the ping packet can be delivered normally. If the result shown in the following figure is present, it means that the hostname can be used to communicate normally.

ping hostname


h3jtXUVeXPC7