Home How to change hostname “FQDN” on CentOS and RHEL
Post
Cancel

How to change hostname “FQDN” on CentOS and RHEL

This is how you change the hostname of you CentOS or Red Hat Enterprise host.

  1. 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

  1. 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
  1. 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
  1. Restart the network.
sudo service network restart
  1. 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

 

 

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