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.
/etc/init.d/network restart
Now check the hostname and FQDN with command called hostname
and 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)
What software have you encountered which is sensitive to whether the hostname is set to the FQDN or short name?
Hi Chupacabras,
It has been long time.Trying to recall, I think it was SAP based application.
Regards
Sharad
I am confused if the IP address is the internal LAN address such as 192.168.1.x, or is it the external public WAN IP?
Also the host file currently contains the following which is slightly confusing:
127.0.0.1 localhost.localdomain localhost.localdomain localhost 4 localhost4.localdomain4 localhost::1 localhost.localdomain localhost.localdomain localhost6 localhost6.localdomain6 localhost
Thanks for the great info! Sometimes it is hard to find info on the simpler items.
192.168.x.x is C class Private IP.(Internal Network IP address)
thanks man, some time the easy thinks make big problems, ldap, zimbra problems for bad /etc/sysconfig/network config.
really apreciated.
Welcome Jorgemop
Keep reading the blog,I regularly write new technical posts