How To Change Hostname On CentOS 6

Change Hostname On CentOS 6

CentOS 6 modify the hostname (hostname) need to modify two places: one is /etc/sysconfig/network, the other is /etc/hosts, only modifying any one will cause the system to start abnormally. First switch to the root user.

vi /etc/sysconfig/network

Open the file, there is a line HOSTNAME=localhost.localdomain (if it is the default), modify localhost.localdomain to your hostname.

vi /etc/hosts

Open the file, there will be a line localhost.localdomain localhost. Among them, is the local loop address, and localhost.localdomain is the hostname, which is what you want to modify. localhost is the alias of the host name, which will appear at the Konsole prompt. Change the second item to your hostname, the third item is optional.

After the above two files are modified, they will not take effect immediately. If you want to take effect immediately, you can use 

hostname your-hostname

For temporary modification, it only temporarily modifies the host name, and it will be restored after the system restarts. But modifying the above two files is permanent, and restarting the system will get the new host name.

Finally, check the host name after restarting:

uname -n
Leave a Comment


No comments yet. Why don’t you start the discussion?

Leave a Reply