All Products
Search
Document Center

Elastic Compute Service:Hostnames

Last Updated:Dec 02, 2024

A hostname is a unique name for a computer or device in a LAN. The hostname of a host distinguishes the host from other hosts on a network, which allows you and network services to accurately identify the host. To prevent hostname conflicts, make sure that the hostname of each host is unique across a subset or internal network.

Functions of hostnames

  • Identify and distinguish Elastic Compute Service (ECS) instances. A hostname is a unique identifier of an ECS instance that allows you to distinguish the ECS instance from other ECS instances when you manage multiple instances.

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

  • Identify logs and monitoring data. Hostnames can 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. In most cases, ECS instances use IP addresses to communicate. However, in specific configurations, ECS instances can have their hostnames 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.

Configure a hostname for an ECS instance

If you do not specify a hostname when you create an ECS instance, the system automatically assigns a custom hostname to the instance.

You can specify a hostname when you create an ECS instance. After the instance is created, you can modify the instance attributes to change the hostname of the instance.

Specify a hostname when you create an instance

Procedure
  1. Go to the ECS instance buy page.

  2. Click the Custom Launch tab.

  3. 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.

  4. 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 the specified hostname. This way, each created 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 the attributes of an instance

Procedure
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. The new hostname may not take effect if you restart the instance from within the operating system of the instance.

  • If you change the hostname of an ECS instance by running the hostnamectl command or modifying the /etc/hostname file in the operating system of the instance, 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. Therefore, we recommend that you do not change the hostname of an ECS instance from within the operating system of the instance.

  1. Log on to the ECS console.

  2. In the left-side navigation pane, choose Instances & Images > Instances.

  3. Find the ECS instance whose attributes you want to modify and choose 图标 > Instance Attributes > Modify Instance Attribute in the Actions column. In the Modify Instance Attributes dialog box, change the hostname of the ECS instance.

    Important

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

    image

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

View an instance hostname

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

View an instance hostname in the ECS console

Log on to the ECS console and go to the Instance Details page of an ECS instance to view the instance hostname.

  1. Log on to the ECS console.

  2. In the left-side navigation pane, choose Instances & Images > Instances.

  3. Find the ECS instance and click the instance ID.

  4. On the Instance Details tab, scroll down to the Other Information section and view the Hostname parameter, which specifies the hostname of the instance.

    image

OpenAPI

You can also call the DescribeInstances operation and view the hostname of the instance in the HostName response parameter.

Connect to an instance to view the instance hostname

Connect to an ECS instance to view the instance hostname.

  1. Connect to an ECS instance.

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

    hostname

    image