Host name is used to identify the systems like hosts, clients, servers etc. Host name provides human readable easy names to remember. In a big environment host names will provides some easy of use. This tutorial is compatible with RHEL6, RHEL7, Fedora, CentOS 6 and CentOS 7 versions
How Host Names Works
In basic form computer networks like TCP/IP works with IP addresses to communicate. IP addresses are not practical for remember and usage. So we name hosts with host names where these host names are associated with related IP address. In the following example we associate host name
web1 with IP address
For more detailed host naming with fully qualified domain name read following tutorials.
Change Host Name In Network Config File
One way to change CentOS server host name is editing the network config file. CentOS network config file resides in
/etc/sysconfig/network . We will open this file with out favourite editor which is
vi in this example. Also we need root privileges in order to edit and save network config file.
$ vi /etc/sysconfig/network
and we will add following line or change if it exists. In this example we will set
HOSTNAME configuration to
In order to apply new host name we need to restart network services with the following command.
$ systemctl restart network
Change Host Name with hostname Command
We have all ready examined the
hostname command which is used to change and set hostname of fully qualified domain name. We can simply specify the new host name after
hostname command. In this example we will set host name as
poftut5 . This will require root privileges
$ hostname poftut5
Add Host Name and Associated IP Address To Hosts File
After changing CentOS host name we should also set new host name and IP address associated in the local system and other systems. We will add host name and IP address to the
/etc/hosts file like below. This will also require root privileges too.