All Products
Search
Document Center

Elastic Compute Service:Hostnames

Last Updated:May 15, 2025

A hostname is a unique name for a computer or device in a LAN. Hostnames distinguish hosts on a network, allowing you and network services to accurately identify target hosts. To prevent hostname conflicts, make sure that the hostname of each host is unique across a subset or an internal network.

Functions of hostnames

  • Identify and distinguish Elastic Compute Service (ECS) instances. A hostname is a unique identifier that helps you distinguish ECS instances when you manage multiple instances.

  • Facilitate configuration and management. Hostnames can serve as convenient and semantic references to replace complex IP addresses when you configure network services, applications, or system settings.

  • Identify logs and monitoring data. Hostnames also serve as identifiers of event sources in system logs, application logs, or various monitoring tools to help trace and analyze system behaviors and improve troubleshooting efficiency.

  • Assist in DNS resolution. ECS instances typically use IP addresses for communication. However, in specific configurations, their hostnames can be resolved by an internal DNS server to IP addresses and communicate by using the hostnames. For more information, see Configure Linux instances to use hostnames for communication over the internal network.

Hostname types

Specify a hostname type to configure a hostname for an ECS instance. ECS instances support the following hostname types:

  • Custom hostname: Specify a custom string based on the basic format requirements as the hostname.

    • Hostname format:

      • For Windows ECS instances, the hostname must be 2 to 15 characters in length and can contain letters, digits, and hyphens (-). It cannot start or end with a hyphen (-), contain consecutive hyphens (-), or contain only digits.

        Important

        Windows ECS instances support only custom hostnames due to length restrictions.

      • For ECS instances that run 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 a time, specify custom sequential hostnames for easy distinction, classification, and management. For more information, see Batch configure sequential names or hostnames for multiple instances.

  • IP address-based hostname: A hostname is automatically generated in a fixed format for an ECS instance based on the primary private IPv4 address of the primary elastic network interface (ENI), which is also considered as the instance's primary private IPv4 address. You cannot modify this hostname. IP address-based hostnames are suitable for ECS instances identified by IP addresses.

    Important

    After you change the primary private IPv4 address of an ECS instance, its IP address-based hostname is automatically updated.

    • Hostname format: 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]: Periods (.) in the primary private IPv4 address are replaced with hyphens (-).

      • regionID: the region ID of the ECS instance. To view the region ID, see Regions and zones.

      • ecs.internal: the internal domain name of the ECS instance.

  • Instance ID-based hostname: A hostname is automatically generated in a fixed format for an ECS instance based on the instance ID. You cannot modify this hostname. Instance ID-based hostnames are suitable for ECS instances identified by unique IDs because this type of hostname remains unchanged even when the instances' IP addresses change.

    • Hostname format: [Instance ID].[regionID].ecs.internal

Configure a hostname for an ECS instance

If you do not specify a hostname during instance creation, the system automatically assigns a custom hostname to the instance.

You can specify a hostname during instance creation. After the instance is created, you can modify the instance attributes to change the hostname.

Specify a hostname during instance creation

  1. Go to ECS console - Custom Launch.

  2. Configure parameters, such as Billing Method, Region, Instance Type, and Image.

    For information about each parameter on the Custom Launch tab, see Parameters.

  3. Expand the Advanced Settings(Optional) section and enter a hostname in the Hostname field. When you create multiple ECS instances, you can select Add Sequential Suffix to Instance Name and Hostname to add incremental suffixes to your specified hostname. This way, each instance has a unique final hostname.

    Important

    Windows ECS instances support only custom hostnames due to length restrictions.

    image

Change the instance hostname when you modify instance attributes

Important
  • You can also call the ModifyInstanceAttribute operation to change the hostname of an ECS instance.

  • After you change the hostname of an ECS instance, you must restart the instance in the ECS console or by calling the RebootInstance operation for the new hostname to take effect. For information about how to restart an ECS instance in the ECS console, see Restart an instance. If you restart the instance from within its operating system, the new hostname may not take effect.

  • If you change the hostname of an ECS instance by running the hostnamectl command or modifying the /etc/hostname file in its operating system, the new hostname is not synchronized to the instance attributes. In this case, you cannot query the new hostname in the ECS console or by calling an API operation. We recommend that you do not change the hostname of an ECS instance from within its operating system.

  1. Go to ECS console - Instance.

  2. Find the ECS instance whose attributes you want to modify and click its ID. On the Instance Details tab, click All Actions in the upper-right corner. In the panel that appears, search for and click Modify Instance Attribute. In the Modify Instance Attributes dialog box, change the instance hostname and click Confirm.

    Important

    Windows ECS instances support only custom hostnames due to length restrictions.

    image

  3. Restart the ECS instance for the new hostname to take effect.

View the instance hostname

You can directly view the hostname of an ECS instance in the ECS console or by calling an API operation. You can also view the hostname by running the hostname command after you connect to the instance.

View the instance hostname in the ECS console

View the hostname of an ECS instance on the instance details page in the ECS console.

  1. Go to ECS console - Instance.

  2. Find the ECS instance whose hostname you want to view and click its ID. On the Instance Details tab, scroll down to the Other Information section and view the Hostname parameter.

    image

Call an API operation

Call the DescribeInstances operation and view the hostname of an ECS instance in the HostName response parameter.

Connect to an instance to view its hostname

Connect to an ECS instance to view its hostname.

  1. Connect to an ECS instance by using one of the following methods:

  2. Run the following command to view the instance hostname:

    hostname

    image

Use the IP address-based or instance ID-based hostname of a Linux instance to access another Linux instance over the internal network

Prepare two ECS instances in the same virtual private cloud (VPC) and security groups. Then, configure them to communicate with each other over the internal network by using their hostnames.

Basic information

  • Target instance: Specify a hostname and configure private DNS resolution for the target instance.

    • Operating system: Alibaba Cloud Linux 3.2

    • Primary private IPv4 address: 172.16.0.101

  • Test instance: Run the ping <Hostname of the target instance> command on the test instance to access the target instance.

    • Operating system: Alibaba Cloud Linux 3.2

    • Primary private IPv4 address: 172.16.100.170

Procedure

  1. Configure an IP address- or instance ID-based hostname for the target instance. For more information, see Configure a hostname for an ECS instance.

    image

  2. Restart the target instance for the new hostname to take effect.

  3. View the hostname of the target instance.

    1. Connect to the target instance.

      For more information, see Use Workbench to connect to a Linux instance over SSH.

    2. Run the following command to view the hostname of the target instance:

      hostname

      The following command output shows that an IP address- or instance ID-based hostname is generated and takes effect for the instance.

      image

  4. Configure private DNS resolution for the target instance. For more information, see Private DNS resolution for ECS instances.

    1. Enable the DNS hostname feature for the VPC in which the target instance resides in the VPC console.启用主机名.png

    2. Select private DNS resolution options for the target instance in the ECS console. In this example, Enable DNS Resolution from the IP Address-based Hostname to the Instance Primary Private IPv4 Address (A Record) is selected.

      image

  5. Log on to the test instance and run the ping <Hostname of the target instance> command to test network connectivity.

    1. Use Workbench to connect to the test instance. For more information, see Use Workbench to connect to a Linux instance over SSH.

    2. Run the following command to check the internal network connectivity to the target instance:

      ping ip-172-16-0-101.ap-southeast-3.ecs.internal

      The following command output shows that the target instance can be accessed by using its hostname over the internal network.

      image