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

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

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

4. Restart the network.

sudo service network restart

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

 

 

I am a Senior System Administrator that work daily with Virtualization,Xenserver, Linux, IT automation, Ansible,Windows, Active Directory, Exchange and a lot more. Here you will find tips and trix from early junior, middle junior and senior to unique information of the topics I mentioned earlier. If you need help with something do not hesitate to contact me I will gladly help.

Tagged with: , , , , ,