CentOS7 Set Hostname

Are you looking to set or change the hostname on CentOS7? The guide below will go through the easy steps on setting the hostname.

Check your existing hostname by issuing the below command:

hostnamectl

This command should return some information about your machine as well as show the current static hostname assigned to it:

Results you should see when issuing the hostnamectl command in CentOS7

You can now issue the command below to set a hostname in CentOS7:

hostnamectl set-hostname machine-name

Now you should you edit the /etc/hosts/ file via vim or nano and add in your new hostname for the 127.0.0.1 entry as well as the ::1 entry if you're making use of IPV6.

You can now restart the system or restart the networking services if needed, however, the hostname should change without you doing this.

Congrats, you've successfully changed the hostname on your CentOS7 machine.