What should I do if I cannot successfully modify the hostname under centos7?

王林
Release: 2020-03-31 09:25:15
Original
3265 people have browsed it

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
Copy after login

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
Copy after login

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
Copy after login

Finally, just check the host name after restarting.

Command:

uname -n
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template