After an ECS instance is restarted for the first time, the hostname (hostname) of some CentOS 7 instances is changed from uppercase letters to lowercase letters. This topic lists the impacted image types and the solution.

Examples of hostname changes

The following table shows examples of changes before and after the initial restart of a CentOS instance with an uppercase hostname.

Instance hostname example Hostname change after the initial restart Do the lowercase letters remain in subsequent restarts?
iZm5e1qe09gy5sxx1ps5zX izm5e1qe09gy5sxx1ps5z6x Yes
ZZHost zzhost Yes
NetworkNode networknode Yes

Impact scope

Impacted images

The following CentOS public images and the custom images created by using these public images are impacted.

  • centos_7_2_64_40G_base_20170222.vhd
  • centos_7_3_64_40G_base_20170322.vhd
  • centos_7_03_64_40G_alibase_20170503.vhd
  • centos_7_03_64_40G_alibase_20170523.vhd
  • centos_7_03_64_40G_alibase_20170625.vhd
  • centos_7_03_64_40G_alibase_20170710.vhd
  • centos_7_02_64_20G_alibase_20170818.vhd
  • centos_7_03_64_20G_alibase_20170818.vhd
  • centos_7_04_64_20G_alibase_201701015.vhd

Impacted hostname types

If the applications deployed in your instance are case-sensitive to the hostname, and you restart the target instance, your services will be impacted. To resolve this issue, you can use an appropriate method described in this topic to fix this error according to the required hostname type or types:

Hostname convention Is the name changed? When does the change occur? Do I proceed with this topic?
The hostname has some uppercase letters in the instance that you create in the ECS console or by using the API. Yes Initial restart Yes
The hostname has only lowercase letters in the instance that you create in the ECS console or by using the API. No N/A No
The hostname had some uppercase letters, but were changed to lowercase letters after you log on to the instance. No N/A Yes

Solution

To retain a hostname with uppercase letters after you restart the instance, follow these steps:

  1. Connect to the instance.
  2. Run the following command to view the current hostname:
    [root@izbp193nf1pk3i161uynzzx ~]# hostname
    izbp193nf1pk3i161uynzzx
  3. Run the following command to set the hostname:
    hostnamectl set-hostname --static iZbp193nf1pk3i161uynzzX
  4. Run the following command to view the updated hostname:
    [root@izbp193nf1pk3i161uynzzx ~]# hostname
    iZbp193nf1pk3i161uynzzX

What to do next

If you are using a custom image, update the cloud-init tool to the latest version, and then create the custom image again. Otherwise, the same error occurs when you use the original custom image to create a new instance. For more information, see Install cloud-init for Linux images and Create a custom image by using an instance.