How to change hostname or FQDN in CentOS and Redhat
In this tutorial we will learn about,how to change Hostname or FQDN in CentOS and Red Hat.
The method is applicable to all Red Hat based operating system. I have described about difference between hostname and FQDN which you can read from this post (The post is written on how to change hostname in Ubuntu,read the theory).
Step 1: Edit the /etc/hosts file and give IP Address,FQDN name and Server name
#vi /etc/hosts ipaddress_of_system server1.sharadchhetri.com server1
Step 2: Edit /etc/sysconfig/network file ,give HOSTNAME as machine name i.e server1
# vi /etc/sysconfig/network NETWORKING=yes HOSTNAME=server1
Step 3: Restart the network service.
Now check the hostname and FQDN with command called
hostname -f respectively.
#hostname server1 #hostname -f server1.sharadchhetri.com
Note: There is another method through which you can change the hostname but generally it is not so much preferable.
The command is
sysctl kernel.hostname (It will show the current hostname) sysctle kernem.hostname Give_hostname (It will set the hostname)