In most cases, an Elastic Compute Service (ECS) instance uses a private IP address instead of a hostname to access resources in the internal network. In a virtual private cloud (VPC), you can specify IP address-based or instance ID-based hostnames for Linux instances, and use the ECS private Domain Name System (DNS) resolution feature to resolve the hostnames to IP addresses. This way, Linux instances in the same VPC can use their hostnames instead of private IP addresses to communicate over the internal network.
Prerequisites
A VPC is created.
ECS instances that run a Linux operating system are created and reside in the VPC.
Hostname types
The feature of changing the hostname type is in invitational preview.
You can configure the hostname of an ECS instance by specifying the hostname type. ECS instances support the following types of hostnames:
Custom hostname: Specify a custom string that meets basic format rules. Then, the system generates an eligible hostname based on your custom string.
Hostname format:
For Windows, the hostname must be 2 to 15 characters in length and can contain letters, digits, and hyphens (-). The hostname cannot start or end with a hyphen (-), contain consecutive hyphens (-), or contain only digits.
ImportantWindows ECS instances support only custom hostnames due to length restrictions.
For other operating systems such as Linux, the hostname must be 2 to 64 characters in length. You can use periods (.) to separate the hostname into multiple segments. Each segment can contain letters, digits, and hyphens (-) but cannot contain consecutive periods (.) or hyphens (-). The hostname cannot start or end with a period (.) or a hyphen (-).
We recommend that you specify a hostname that can help you identify the purpose of the instance. In most cases, a mature maintenance system includes a set of complete numbering rules. Example: service ID-product line-region. Examples:
app001-live-huanan1
indicates that an ECS instance named 001 that hosts the live streaming app of an enterprise resides in the China (Shenzhen) region.jack001-dev-huabei2
indicates that an ECS instance named 001 that is used for development by an enterprise employee named Jack resides in the China (Beijing) region.
Custom sequential hostnames: When you create multiple ECS instances at the same time, specify custom sequential hostnames to distinguish, classify, and manage your ECS instances for efficient management. For more information, see Batch configure sequential names or hostnames for multiple instances.
IP address-based hostname: A hostname string is automatically generated in a fixed format based on the primary private IPv4 address of the primary elastic network interface (ENI) of an instance. You cannot change the IP address-based hostname.
ImportantAfter you change the primary private IPv4 address of an instance, the hostname of the instance is automatically updated. For information about how to change the primary private IP address of an instance, see Modify the private IP address of an instance.
Format of a hostname in a domain name: ip-[String generated based on the primary private IPv4 address of the primary ENI].[regionID].ecs.internal
[String generated based on the primary private IPv4 address of the primary ENI]: Dots (.) in the primary private IPv4 address are replaced with hyphens (-).
[regionID]: the region ID of the ECS instance. For information about region IDs, see the Supported regions and zones section of the "Regions and zones" topic.
ecs.internal: the internal domain name of the ECS instance.
Scenarios: IP address-based hostnames are temporarily used in the following scenarios or environments:
Temporary configuration or test environments: When you temporarily establish a test network, debug devices, or preliminarily configure devices, you can use IP address-based hostnames to easily identify and configure multiple devices.
Specific automated scripts or configurations: IP address-based hostnames may be used as temporary markers or placeholders in specific automated deployment scripts or software configurations, especially when a script or program is used to dynamically assign and manage device identifiers.
Instance ID-based hostname: A hostname string is automatically generated based on the instance ID. You cannot change the instance ID-based hostname.
Format of a hostname in a domain name: [Instance ID-based hostname].[regionID].ecs.internal
Scenarios:
Automated management and configuration: You can use instance ID-based hostnames to facilitate automated system identification and management in cloud computing environments, container orchestration scenarios such as Kubernetes, or scenarios involving configuration management tools such as Ansible, Chef, and Puppet. This simplifies script compilation and templated configuration because resource IDs are often unique and easy to process.
Resource tracking and auditing: You can specify instance ID-based hostnames to help you track the lifecycle of cloud service instances or other types of resources. This helps you quickly identify specific resources during log analysis, performance monitoring, and troubleshooting, especially in large distributed systems.
Resource association and dependency management: In system deployments with complex dependencies, you can use resource ID-based hostnames to identify the relationships between resources. This helps you understand service topology, isolate faults, and optimize resource allocation.
Specify a hostname type for an ECS instance
If you do not specify a hostname type when you create an ECS instance, the system automatically assigns a custom hostname to the instance.
You can specify a hostname type when you create an ECS instance. After the instance is created, you can change the hostname type of the instance by using the Modify Instance Attributes feature.
Specify a hostname type when you create an instance
Procedure
Go to the ECS instance buy page.
Click the Custom Launch tab.
Configure parameters, such as Billing Method, Region, Instance Type, and Image, based on your business requirements.
For information about each parameter on the Custom Launch tab, see the Parameters section of this topic.
Expand the Advanced Settings(Optional) section and specify a hostname type. For information about hostname types, see the Hostname types section of the "Hostnames" topic.
Change the hostname type by using the Modify Instance Attributes feature
Log on to the ECS console.
In the left-side navigation pane, choose .
Find the ECS instance whose hostname type you want to change and choose > Instance Attributes > Modify Instance Attribute in the Actions column. The Modify Instance Attributes dialog box appears.
Select a hostname type in the Hostname Type section. If you select Custom Hostname, enter a custom hostname. If you select IP Address-based Hostname or Instance ID-based Hostname, the system automatically generates a hostname for the instance. For more information about hostname types, see the Hostname types section of the "Hostnames" topic.
ImportantWindows ECS instances support only custom hostnames due to length restrictions.
Restart the ECS instance for the new hostname to take effect.
Communication between Linux instances over the internal network based on IP address-based and instance ID-based hostnames
Scenario: Two ECS instances that belong to the same VPC and security group are created.
Basic information
Destination instance: Specify a hostname and configure the private DNS resolution feature for the destination instance.
Operating system: Alibaba Cloud Linux 3.2
Instance ID: i-8ps625l5075b18r0v1cp
Primary private IPv4 address: 172.16.0.101
Security group: sg-bp1g41cssbfqzwjwrqtl
Test instance: Run the
ping <Hostname of the destination instance>
command on the test instance to access the destination instance.Operating system: Alibaba Cloud Linux 3.2
Instance ID: i-8ps8nsvbw63sr7n2bw7j
Primary private IPv4 address: 172.16.100.170
Security group: sg-bp1g41cssbfqzwjwrqtl
Procedure
Specify the IP address-based hostname for the destination instance. You can also specify the instance ID-based hostname. For more information, see the Configure a hostname for an ECS instance section of the "Hostnames" topic.
Restart the destination instance for the new hostname to take effect.
Confirm the hostname of the destination instance.
Connect to the destination instance.
For more information, see Connect to a Linux instance by using a password or key.
Run the following command to view the hostname of the instance:
hostname
The following command output indicates that the hostname is changed.
Configure the private DNS resolution feature for the destination instance. For more information, see the Configure ECS private DNS resolution section of the "ECS Private DNS Resolution" topic.
NoteThe record type of the private domain name must match the hostname type configured in Step 1. Otherwise, you may be unable to access the destination instance by using the hostname. For information about how to access an instance by using a private domain name, see the Communication between ECS instances by using private domain names section of the "ECS Private DNS Resolution" topic.
If you select Instance ID-based Hostname, select Enable DNS Resolution from the Instance ID-based Hostname to the Instance Primary Private IPv4 Address (A Record).
If you select IP Address-based Hostname, select Enable DNS Resolution from the IP Address-based Hostname to the Instance Primary Private IPv4 Address (A Record).
In this example, Enable DNS Resolution from the Instance ID-based Hostname to the Instance Primary Private IPv4 Address (A Record) is selected.
Log on to the test instance and run the
ping <Hostname of the destination instance>
command to test the connectivity.Connect to the test instance by using Workbench. For more information, see Connect to a Linux instance by using a password or key.
Run the following command to check the internal network connectivity of the instance:
ping ip-172-16-0-101.ap-southeast-3.ecs.internal
In this example, the following result is returned. You can use the hostname to access the instance over the internal network.
FAQ
What do I do if I cannot access an application on an instance by using the IP address-based hostname?
Cause: The primary private IP address of the instance was changed, but not updated in another application for which you also specified the IP address-based hostname. As a result, the original hostname becomes invalid.
Solution: Update the hostname settings for another application.
References
Windows instances do not support IP address-based or instance ID-based hostnames and cannot use the preceding hostnames to communicate with each other. To allow the instances to communicate with each other, you can configure private domain names for the Windows instances. For more information, see the Communication between ECS instances by using private domain names section of the "ECS Private DNS Resolution" topic.