Linux is usually installed at the time, the user needs to set the hostname, but in daily use, convenient grouping or memory, etc., may need to modify the host name, modify the hostname has 2 kinds, temporary modification or permanent modification, the following are described separately.
First, temporarily modify the host name
Temporary modification is only valid at this time, and will return to the original hostname after the next reboot.
In terminal input: hostname xxxxx, where xxxxx is the hostname that needs to be changed
- After the return, the hostname has changed, but the interface is the original hostname, at this time you can exit login exit, to refresh the host name.
- After the reboot, the hostname will be restored to the original host name.
Second, permanently modify the host name
1, log in as root, or log on to the root user, and then enter the hostname command at the prompt, you can see the current system host name is Localhost.localdomain.
2. Change the network file under/etc/sysconfig, enter vi/etc/sysconfig/network at the prompt, and change the value after hostname to the host name you want to set.
3. Change the Hosts file under/etc, enter vi/etc/hosts at the prompt and change the localhost.localdomain to the host name you want to set.
4. Restart the server by entering the reboot command at the prompt.
5, restart after the completion of the hostname command query system hostname, you can see the system hostname has been changed to MyComputer.
How Linux modifies host names