This is how you change the hostname of you CentOS or Red Hat Enterprise host.
- First check what the current fully qualified domain name is with the command hostname -f
hostname -f
Result of the command:
$ hostname -f hostname: Unknown host
In my example I will change the hostname to geekcorner at my domain sitedevelopments.net
- edit /ectc/hosts and change it from localhost to your desired hostname
sudo vi /etc/hosts
My original /etc/hosts looks like this:
#This is the original hosts file located in /etc/hosts 127.0.0.1 localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6
Change the file /etc/hosts to what you like your hostname to be.
#We change it to this "If you have static IP then you can specify the IP adress to the host aswell" 127.0.0.1 geekcorner.sitedevelopments.net geekcorner localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6
- Next we change /etc/sysconfig/network
sudo vi /etc/sysconfig/network
#This is the original /etc/sysconfig/network file NETWORKING=yes NETWORKING_IPV6=no HOSTNAME=localhost NTPSERVERARGS=iburst ~ ~ ~ "/etc/sysconfig/network" 4L, 97C
#Change the file /etc/sysconfig/network to this NETWORKING=yes NETWORKING_IPV6=no HOSTNAME=geekcorner #Change to your desired hostname NTPSERVERARGS=iburst ~ ~ ~ "/etc/sysconfig/network" 4L, 97C
- Restart the network.
sudo service network restart
- Check that the hostname change went well
hostname -f
#You should get a reply like this: $ hostname -f $ geekcorner.sitedevelopments.net #this will show your Fully qualified domain name (FQDN)
Sometimes you have to restart to get the changes
sudo shutdown -r now