Hello,
Sometime we need to change server hostname , It can be possible to change host name by using SSH command line ;
1st we can check the current hostname by command :
hostname
outputs example : server1.bipul.me
Now , we change the hostname by editing network and hosts files . we can edit file by using nano or vi command ;
nano /etc/sysconfig/network
look in outputs and find HOSTNAME value & change with new hostname ;
for example : HOSTNAME=”server2.bipul.me”
Save and close the file.
Now we need to edit hosts file with host name with your IP :
nano /etc/hosts
127.0.0.1 localhost
72.29.87.105 server2.bipul.me
Save and close the file.
Set hostname manually without rebooting the box
Type the following command:
# hostname server2.bipul.me
Restart the CentOS networking and other services:
service network restart
OR
/etc/init.d/network restart
Verify new hostnames
Simply type the following commands:
# hostname
thats all.