Shares 13

As a System Admin, one must be aware of changing the hostname. If you have entered the wrong hostname during installation or requirement to change it, you can change it as below. Changing hostname involve two steps.

  • Change HOSTNAME value in /etc/sysconfig/network
  • Change host name in /etc/hosts

1. Display Hostname

[[email protected] ~]# hostname
localhost.localdomain
[[email protected] ~]# hostname

2. Change Hostname

Edit /etc/sysconfig/network file as below, look for HOSTNAME= to update the desired hostname.

Ex: Before change:

[[email protected] sysconfig]# cat network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=localhost.localdomain

[[email protected] sysconfig]#   vi /etc/sysconfig/network
save the file

Ex: After change:

[[email protected] sysconfig]# cat network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=Chandan.Pro
[[email protected] sysconfig]#

Next step would be change hostname in a hosts file.

Edit/etc/hosts file as below, look for current hostname and update desired hostname

Ex: Before change:

[[email protected] etc]# cat hosts
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
[[email protected] etc]#

vi /etc/hosts
save the file

Ex: After change:

[[email protected] etc]# cat hosts
127.0.0.1 chandan.pro
::1 localhost6.localdomain6 localhost6
[[email protected] etc]#

3. Change hostname on terminal

[[email protected] etc]# hostname chandan.pro

Verification

[[email protected] etc]# hostname
chandan.pro
[[email protected] etc]#

Done! Your Linux hostname is changed!

Shares 13

Reader Interactions

Comments

Your email address will not be published. Required fields are marked *