CentOS modify the host name tutorial

Time:2021-4-7

We need to modify two parts: one is / etc / sysconfig / network, the other is / etc / hosts. Only modifying any part will cause system startup exception. First switch to root.

Copy code

The code is as follows:

/etc/sysconfig/network

Use any of your favorite editors to open the file with a line of host name= localhost.localdomain (if it is the default), modify localhost.localdomain For your host name.

Copy code

The code is as follows:

/etc/hosts

Open the file and there will be a line 127.0.0.1 localhost.localdomain localhost 。 Where 127.0.0.1 is the local loop address, localhost.localdomain Is the host name, which is what you want to modify. Localhost is the alias of the host name, which will appear at the prompt of konsol. Change the second item to your host name, and the third item is optional.

After the above two documents are modified, they will not take effect immediately. If you want it to take effect immediately, you can use the host name your host name to make temporary changes. It only changes the host name temporarily, and the system will return to its original state after restart. But modifying the above two files is permanent, and restarting the system will get a new host name.

Finally, after restarting, check the host name uname – n.