Help Center/ Elastic Cloud Server/ User Guide (Kuala Lumpur Region)/ Instances/ Managing ECSs/ (Optional) Configuring Mapping Between Hostnames and IP Addresses
Updated on 2024-07-24 GMT+08:00

(Optional) Configuring Mapping Between Hostnames and IP Addresses

ECSs in the same VPC can communicate with each other using hostnames. In such a case, you are required to configure the mapping between hostnames and IP addresses. The communication using hostnames is more convenient than that using IP addresses.

Constraints

This method applies only to Linux ECSs.

Procedure

For example, there are two ECSs in a VPC, ecs-01 and ecs-02. Perform the following operations to enable communication using hostnames between ecs-01 and ecs-02:

  1. Log in to ecs-01 and ecs-02 and obtain their private IP addresses.

    1. Log in to the management console.
    2. Under Computing, click Elastic Cloud Server.
    3. On the Elastic Cloud Server page, obtain the private IP address in the IP Address column.

      For example, the obtained private IP addresses are as follows:

      ecs-01: 192.168.0.1

      ecs-02: 192.168.0.2

  2. Obtain the hostnames for the two ECSs.

    1. Log in to an ECS.
    2. Run the following command to view the ECS hostname:

      sudo hostname

      For example, the obtained hostnames are as follows:

      ecs-01: hostname01

      ecs-02: hostname02

  3. Create a mapping between the hostnames and IP addresses and add information about other ECSs in the same VPC.

    1. Log in to ecs-01.
    2. Run the following command to switch to user root:

      sudo su -

    3. Run the following command to edit the hosts configuration file:

      vi /etc/hosts

    4. Press i to enter editing mode.
    5. Add the statement in the following format to set up the mapping:

      Private IP address hostname

      For example, add the following statement:

      192.168.0.1 hostname01

      192.168.0.2 hostname02

    6. Press Esc to exit editing mode.
    7. Run the following command to save the configuration and exit:

      :wq

    8. Log in to ecs-02.
    9. Repeat 3.b to 3.g.

  4. Check whether the ECSs can communicate with each other using hostnames.

    Log in to an ECS in the same VPC, run the following command to ping the added host, and check whether the operation is successful:

    ping Hostname