Assign unique hostnames to ECS instances for identification, logging, and internal DNS resolution within a VPC.
Use cases
-
Distinguish instances: Identify individual ECS instances by meaningful names.
-
Simplify configuration: Use readable hostnames instead of IP addresses for network services, applications, and system settings.
-
Improve logging and monitoring: Hostnames in logs and monitoring tools identify event sources for faster troubleshooting.
-
Assist with DNS resolution: Map hostnames to IP addresses through internal DNS resolution so instances can communicate by hostname. See Use hostnames for internal communication between Linux instances.
Hostname types
Set an ECS instance hostname by configuring its Hostname Type. ECS supports the following hostname types:
-
Custom hostname: A hostname based on a custom string you provide.
-
Hostname format:
-
For Windows instances, the hostname must be 2 to 15 characters long. It can contain letters (uppercase or lowercase), digits, and hyphens (-), but cannot start or end with a hyphen, contain consecutive hyphens, or consist only of digits.
ImportantDue to length constraints, Windows instances support only custom hostnames.
-
For other operating systems such as Linux, the hostname must be 2 to 64 characters long. Periods (.) separate segments. Each segment can contain letters (uppercase or lowercase), digits, and hyphens (-). The hostname cannot contain consecutive periods or hyphens, or start or end with a period or hyphen.
Use a hostname that clearly indicates the server's purpose. A mature operations and maintenance (O&M) system typically includes a complete set of naming rules, such as `business ID-product line-region`. For example:
app001-live-huanan1can indicate ECS server 001 in the `huanan1` region, which hosts the company's live streaming application.jack001-dev-huabei2can indicate development server 001 in the `huabei2` region, used by an employee named Jack.
-
-
Custom sequential hostnames: When creating multiple ECS instances, use sequential hostnames to differentiate and manage them. See Batch configure sequential instance names or hostnames.
-
-
IP address-based hostname: A non-editable hostname auto-generated from the primary private IPv4 address of the instance's primary elastic network interface (ENI). Suitable for environments that identify instances by IP address.
ImportantIf you change the primary private IPv4 address of an instance, the hostname updates automatically.
-
Hostname format:
ip-[Private-IPv4-address-string].[regionID].ecs.internal-
Private-IPv4-address-string: The primary private IPv4 address with periods (.) replaced by hyphens (-).
-
regionID: The region ID of the ECS instance. See Regions and zones.
-
ecs.internal: The internal domain suffix for ECS.
-
-
-
Instance ID-based hostname: A non-editable hostname auto-generated from the instance ID. This hostname persists even if the instance's IP address changes, making it ideal for stable identification.
-
Hostname format:
[Instance-ID].[regionID].ecs.internal
-
Configure an instance hostname
If you do not specify a hostname during instance creation, a default custom hostname is assigned.
Define a hostname during creation or modify it afterward.
Define during creation
Go to ECS console - custom launch.
-
Configure settings such as the billing method, region, instance type, and image.
For a detailed explanation of each parameter, see Parameters.
-
Click Advanced Settings (Optional) to define a hostname. To create multiple instances, batch configure sequential instance names or hostnames to differentiate them.
ImportantDue to length constraints, Windows instances support only custom hostnames.

Modify after creation
-
You can also call the ModifyInstanceAttribute API operation to modify the hostname.
-
After modifying a hostname, restart the instance from the ECS console (see Restart an instance) or by calling the RebootInstance API operation for the change to take effect. Restarting from within the operating system does not guarantee that the change takes effect.
-
Do not modify the hostname from within the operating system (such as running
hostnamectlor editing/etc/hostname). Such changes are not synced with instance properties and will not appear in the ECS console or API.
Go to ECS console - Instances.
-
Click the instance ID to open its details page. In the upper-right corner, click All Operations > Modify Instance Properties. Modify the hostname and click OK.
ImportantDue to length constraints, Windows instances support only custom hostnames.

-
Restart the instance for the hostname change to take effect.
View an instance hostname
View the hostname in the ECS console or by running the hostname command on the instance.
View in the console
View the hostname on the instance details page.
Go to ECS console - Instances.
-
Click the instance ID to open the details page. In the .

API references
Call the DescribeInstances operation and check the HostName parameter in the response.
Connect to view
Connect to an ECS instance to view its system hostname.
-
Connect to the instance.
-
View the system hostname:
hostname
Use hostnames for internal communication between Linux instances
Enable internal communication between two ECS instances in the same VPC and security group by using hostnames.
Basic information
-
Target instance: The instance with hostname and private DNS resolution configured.
-
Operating system: Alibaba Cloud Linux 3.2
-
Primary private IPv4 address: 172.16.0.101
-
-
Test instance: The instance that runs
ping <target_instance_hostname>to access the target instance.-
Operating system: Alibaba Cloud Linux 3.2
-
Primary private IPv4 address: 172.16.100.170
-
Procedure
-
Configure the hostname of the target instance to be IP-based (or instance ID-based). See Configure an instance hostname.

-
Restart the target instance for the new hostname to take effect.
-
Verify the hostname of the target instance.
-
Connect to the target instance.
-
Check the current hostname of the target instance:
hostnameThe following output indicates the hostname is updated:

-
-
Configure private DNS resolution for the target instance. See Enable communication between ECS instances by using private domain names.
-
In the VPC console, enable the DNS hostname feature for the VPC.

-
In the ECS console, configure private DNS resolution for the target instance. Select Enable DNS resolution for the IP-based hostname to the primary private IPv4 address of the instance (A record):

-
-
Log on to the test instance and run
ping <target_instance_hostname>to test connectivity.-
Connect to the test instance with Workbench. See Log on to a Linux instance using Workbench.
-
Verify internal network connectivity to the target instance by hostname:
ping ip-172-16-0-101.ap-southeast-3.ecs.internalThe following output shows the instance is accessible over the internal network by hostname:

-