How to change hostname without rebooting

Here in the following example, I have used 192.168.0.1 as computer IP and server1.example.com as hostname.

Step-1  First you need to edit  /etc/sysconfig/network file.

[ root @ leolinux ~ ]#    vim   /etc/sysconfig/network

NETWORKING=yes

HOSTNAME=server1.example.com

ESC

:wq!

 

Step-2 Now run the following command to make it usable for current session only.

[ root @ leolinux ~ ]#   hostname  server1.example.com

 

Step-3  Make entery  in  /etc/hosts file to make hostname accessible by local service.

[ root @ leolinux ~ ]#   vim   /etc/hosts

127.0.0.1   localhost localhost.localdomain

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.0.1    server1.example.com   server1

ESC

:wq!

 

Step-4  Now restart the network service.

[ root @ leolinux ~ ]#   service    network    restart

 

cheer !!