El contenido no se encuentra disponible en el idioma seleccionado. Estamos trabajando continuamente para agregar más idiomas. Gracias por su apoyo.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ Elastic Cloud Server/ User Guide (ME-Abu Dhabi Region)/ FAQs/ ECS Management/ How Can a Changed Static Hostname Take Effect Permanently?

How Can a Changed Static Hostname Take Effect Permanently?

Updated on 2023-09-07 GMT+08:00

Symptom

The static hostname of a Linux ECS is user defined and injected using Cloud-Init during the ECS creation. Although the hostname can be changed by running the hostname command, the changed hostname is restored after the ECS is restarted.

Changing the Hostname on the ECS

To make the changed hostname still take effect even after the ECS is stopped or restarted, save the changed hostname into configuration files.

The changed hostname is assumed to be new_hostname.

  1. Modify the /etc/hostname configuration file.
    1. Run the following command to edit the configuration file:

      sudo vim /etc/hostname

    2. Change the hostname to the new one.
    3. Run the following command to save and exit the configuration file:

      :wq

  2. Modify the /etc/sysconfig/network configuration file.
    1. Run the following command to edit the configuration file:

      sudo vim /etc/sysconfig/network

    2. Change the HOSTNAME value to the new hostname.

      HOSTNAME=Changed hostname

      NOTE:

      If there is no HOSTNAME in the configuration file, manually add this parameter and set it to the changed hostname.

      For example:

      HOSTNAME=new_hostname
    3. Run the following command to save and exit the configuration file:

      :wq

  3. Modify the /etc/cloud/cloud.cfg configuration file.
    1. Run the following command to edit the configuration file:

      sudo vim /etc/cloud/cloud.cfg

    2. Use either of the following methods to modify the configuration file:
      • Method 1: Change the preserve_hostname parameter value or add the preserve_hostname parameter to the configuration file.

        If preserve_hostname: false is already available in the /etc/cloud/cloud.cfg configuration file, change it to preserve_hostname: true. If preserve_hostname is unavailable in the /etc/cloud/cloud.cfg configuration file, add preserve_hostname: true before cloud_init_modules.

        If you use method 1, the changed hostname still takes effect after the ECS is stopped or restarted. However, if the ECS is used to create a private image and the image is used to create a new ECS, the hostname of the new ECS is the hostname (new_hostname) used by the private image, and user-defined hostnames cannot be injected using Cloud-Init.

      • Method 2 (recommended): Delete or comment out - update_hostname.

        If you use method 2, the changed hostname still takes effect after the ECS is stopped or restarted. If the ECS is used to create a private image and the image is used to create a new ECS, the changed hostname permanently takes effect, and user-defined hostnames (such as new_new_hostname) can be injected using Cloud-Init.

  1. Run the following command to restart the ECS:

    sudo reboot

  2. Run the following command to check whether the hostname has been changed:

    sudo hostname

    If the changed hostname is displayed in the command output, the hostname has been changed and the new name permanently takes effect.

Modifying the Mapping Between the ECS Hostname and IP Address (Modifying the hosts File)

If you want to use the changed hostname as the preferred localhost and localhost.localdomain, update the mapping between the hostname and IP address after the hostname is changed and then save the configuration to the corresponding Cloud-Init configuration file so that the new hostname takes effect permanently.

The changed hostname is assumed to be new_hostname.

  1. Modify the /etc/hostname configuration file.
    1. Run the following command to edit the configuration file:

      sudo vim /etc/hostname

    2. Change the hostname to the new one.
    3. Run the following command to save and exit the configuration file:

      :wq

  2. Modify the /etc/sysconfig/network configuration file.
    1. Run the following command to edit the configuration file:

      sudo vim /etc/sysconfig/network

    2. Change the HOSTNAME value to the new hostname.

      HOSTNAME=Changed hostname

      NOTE:

      If there is no HOSTNAME in the configuration file, manually add this parameter and set it to the changed hostname.

      For example:

      HOSTNAME=new_hostname
    3. Run the following command to save and exit the configuration file:

      :wq

  3. Modify the /etc/cloud/cloud.cfg configuration file.
    1. Run the following command to edit the configuration file:

      sudo vim /etc/cloud/cloud.cfg

    2. Use either of the following methods to modify the configuration file:
      • Method 1: Change the preserve_hostname parameter value or add the preserve_hostname parameter to the configuration file.

        If preserve_hostname: false is already available in the /etc/cloud/cloud.cfg configuration file, change it to preserve_hostname: true. If preserve_hostname is unavailable in the /etc/cloud/cloud.cfg configuration file, add preserve_hostname: true before cloud_init_modules.

        If you use method 1, the changed hostname still takes effect after the ECS is stopped or restarted. However, if the ECS is used to create a private image and the image is used to create a new ECS, the hostname of the new ECS is the hostname (new_hostname) used by the private image, and user-defined hostnames cannot be injected using Cloud-Init.

      • Method 2 (recommended): Delete or comment out - update_hostname.

        If you use method 2, the changed hostname still takes effect after the ECS is stopped or restarted. If the ECS is used to create a private image and the image is used to create a new ECS, the changed hostname permanently takes effect, and user-defined hostnames (such as new_new_hostname) can be injected using Cloud-Init.

  1. Update the mapping between the hostname and IP address in /etc/hosts to an entry starting with 127.0.0.1. Use new_hostname as your preferred localhost and localhost.localdomain.
    1. Run the following command to edit /etc/hosts:

      sudo vim /etc/hosts

    2. Modify the entry starting with 127.0.0.1 and replace localhost and localhost.localdomain with new_hostname.
      ::1     localhost       localhost.localdomain   localhost6      localhost6.localdomain6
      127.0.0.1       localhost       localhost.localdomain   localhost4      localhost4.localdomain4
      127.0.0.1       new_hostname    new_hostname
    3. Run the following command to save and exit the configuration file:

      :wq

  2. Modify the /etc/cloud/cloud.cfg configuration file.
    1. Run the following command to edit the configuration file:

      sudo vim /etc/cloud/cloud.cfg

    2. Set manage_etc_hosts to manage_etc_hosts: false.
      manage_etc_hosts: false
    3. Run the following command to save and exit the configuration file:

      :wq

  1. Run the following command to restart the ECS:

    sudo reboot

  2. Run the following commands to check whether the changes to hostname and hosts take effect permanently:

    sudo hostname

    sudo cat /etc/hosts

    If the changed hostname (new_hostname) and hosts are displayed in the command output, the changes take effect permanently.

Utilizamos cookies para mejorar nuestro sitio y tu experiencia. Al continuar navegando en nuestro sitio, tú aceptas nuestra política de cookies. Descubre más

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback