Posts Set Or Change Hostname In CentOS7

Set Or Change Hostname In CentOS7

In CentOS6, we modify /etc/sysconfig/network to set the servers’s hostname but in CentOS7, it was changed to use command line to change or set the hostname. I did not know this when I first start using CentOS7 until I google about it. The commands are as below

Check hostname status

The following command will show you the current hostname status of your server. Static hostname is the filed we are going to set to a desired name.

hostnamectl status


Changing or setting hostname

Use the command below to change or set the hostname of the server. After that, use the status command again to confirm the change.

hostnamectl set-hostname TheHostnameYouWant


Be aware that you have to re-login in order to make the hostname in your connection to take effect, like the image below.

And there you go, that’s how we change the hostname in CentOS7.

This post is licensed under CC BY 4.0 by the author.