Menu

IT Infrastructure Blog               

Provide an Articles and Tutorials                                                            

Free Course: Do you like reading White Papers, Magazine, eBooks, Video Tutorials? Just enter your email below to receive...


How to Change hostname in Linux

Linux

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

 

Display Hostname

[root@localhost ~]# hostname
localhost.localdomain
[root@localhost ~]# hostname

 

Change Hostname

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

Before change:

[root@localhost sysconfig]# cat network

NETWORKING=yes

NETWORKING_IPV6=no

HOSTNAME=localhost.localdomain

[root@localhost sysconfig]#

 

vi /etc/sysconfig/network

save the file

After change:

[root@localhost sysconfig]# cat network

NETWORKING=yes

NETWORKING_IPV6=no

HOSTNAME=Chandan.Pro

[root@localhost sysconfig]#

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

Before change:

[root@localhost etc]# cat hosts

127.0.0.1 localhost.localdomain localhost

::1 localhost6.localdomain6 localhost6

[root@localhost etc]#

 

vi /etc/hosts

save the file

After change:

[root@localhost etc]# cat hosts

127.0.0.1 chandan.pro

::1 localhost6.localdomain6 localhost6

[root@localhost etc]#

 

Change hostname on terminal

 

[root@localhost etc]# hostname chandan.pro
[root@localhost etc]# hostname
chandan.pro
[root@localhost etc]#

 

Done! Your Linux hostname is changed!

back to top