How to effectively modify the etc/hosts configuration of Linux C
Last Updated At: 2025-11-26 11:31:02
Overview
Converge Cloud are pre-installed with the purely open-source Cloud-Init tool, which enables the initialization operations of all instances and increases the transparency of the internal processes of the instances.
Cloud-Init generates a new /etc/hosts file based on the template located at /etc/cloud/templates/hosts.${os_type}.tmplevery time the instance is started, which overwrites the original /etc/hosts file. This means that if you manually modify the /etc/hosts configuration inside the instance and restart the instance, the /etc/hosts configuration will revert to its default state.
Directions
Option I
Log in to the Linux server.
Execute the following command to modify the
/etc/cloud/cloud.cfgconfiguration file by changing- update_etc_hoststo- ['update-etc-hosts', 'once-per-instance'].sed -i "/update_etc_hosts/c \ - ['update_etc_hosts', 'once-per-instance']" /etc/cloud/cloud.cfgExecute the following command to create the
config_update_etc_hostsfile under the path/var/lib/cloud/instance/sem/.touch /var/lib/cloud/instance/sem/config_update_etc_hosts
Option II
This solution takes the CentOS7.2 operating system as an example.
Retrieve the hosts template file path
Log in to the Linux server.
Execute the following command to view the system's hosts template file.
cat /etc/hostsThe hosts template file path will be displayed:

Modifying Hosts Template File
Take adding 127.0.0.1 test test as an example. You can modify the hosts template file and /etc/hosts file as needed.
Execute the following command to modify the hosts template file.
vim /etc/cloud/templates/hosts.redhat.tmplPress "i ” to switch to edit mode.
Add the following content at the end of the file.
127.0.0.1 test testAfter entering, press "Esc " , input :wq to save the file and exit.
Modifying /etc/hosts File
Execute the following command to modify
/etc/hostsfile.vim /etc/hostsPress "i ” to switch to edit mode.
Add the following content at the end of the file.
127.0.0.1 test testAfter entering, press "Esc " , input :wq to save the file and exit.