Home >Operation and Maintenance >CentOS >What should I do if I cannot successfully modify the hostname under centos7?
The reason why hostname cannot be successfully modified under centos7 is:
The system was not restarted after modifying the file.
(Recommended tutorial: centos tutorial)
The modification steps are as follows:
Two places need to be modified: one is /etc/sysconfig/network, The other place is /etc/hosts. Modifying just any one place will cause the system to start abnormally.
First switch to the root user.
/etc/sysconfig/network
Open the file with an editor, there is a line HOSTNAME=localhost.localdomain (if it is the default), change localhost.localdomain to your host name.
/etc/hosts
Open the file, there will be a line 127.0.0.1 localhost.localdomain localhost. Among them, 127.0.0.1 is the local loop address, and localhost.localdomain is the hostname (hostname), which is what you want to modify. localhost is an alias for the hostname that appears at the Konsole prompt. Change the second item to your hostname, and the third item is optional.
After modifying the above two files, it will not take effect immediately. If you want it to take effect immediately, you can use the following command to make temporary changes. It only temporarily changes the host name, and it will be restored after the system is restarted. However, modifying the above two files is permanent, and restarting the system will result in a new host name.
hostname your-hostname
Finally, just check the host name after restarting.
Command:
uname -n
Related video tutorial recommendations: linux video tutorial
The above is the detailed content of What should I do if I cannot successfully modify the hostname under centos7?. For more information, please follow other related articles on the PHP Chinese website!