You are currently viewing how to change hostname in centos  using command line

how to change hostname in centos using command line

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.

Jobair Alam Bipul

I'm Jobair Alam, a cPanel Certified WHM/cPanel server administrator and web hosting expert with over 10 years of experience in the industry.

Leave a Reply

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

HostArmada - Affordable Cloud SSD Web Hosting