CentOS7 is finally here! In this guide, I will take a quick look at how you can change the hostname in CentOS
Step 1: Check Your Current Hostname
Enter this into the shell:
You will get back something like host.domain.com, where domain is your assigned root domain that is usually used to set up your initial nameservers (if you are using WHM or Plesk, you are probably used to that)
Step 2: Backup Hosts and Network Files
If you are new to CentOS and have never edited the hostname before, it is a good idea to backup the following files first. Copy and paste this command
cp /etc/hosts /etc/hosts.bak
cp /etc/sysconfig/network cp /etc/sysconfig/network.bak
Step 3: Modifying Hosts File
My favorite editor is pico, so I will use that for this example:
Next, modify the line that looks similar to host.domain.com and replace only that
Step 4: Modifying Network File
Step 5: Execution
Finally, we are going to change the hostname and restart the network service by executing two lines:
service network restart
This is what you should get:
Step 6: Confirmation
You can now confirm that you hostname has been changed by executing the command hostname again.
Voilà, you have successfully rendered your hostname to a different alias.
If you’re still having problems with your hostname, make sure to clear all caches within your control panel.
Still not changing? Post a comment.