Configuring Mapping Between Hostnames and IP Addresses in the Same VPC
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:
- Log in to ecs-01 and ecs-02 and obtain their private IP addresses.
- Log in to the management console.
- Click . Under Compute, click Elastic Cloud Server.
- 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
- Obtain the hostnames for the two ECSs.
- Log in to an ECS.
- 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
- Create a mapping between the hostnames and IP addresses and add information about other ECSs in the same VPC.
- Log in to ecs-01.
- Run the following command to switch to user root:
sudo su -
- Run the following command to edit the hosts configuration file:
- Press i to enter editing mode.
- Add the statement in the following format to set up the mapping:
For example, add the following statement:
192.168.0.1 hostname01
192.168.0.2 hostname02
- Press Esc to exit editing mode.
- Run the following command to save the configuration and exit:
- Log in to ecs-02.
- Repeat 3.b to 3.g.
- 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
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot