Changing hostname in CentOS ,Redhat Linux OS

Hello ,

Today lets see an article about changing hostname in CentOS and Redhat.

We have to change hostname in 3 locations to apply changes globally in all locations. 
Configuration filenames :

    

1. /etc/sysconfig/network
2. /etc/hosts
3. hostname command 

1. Open /etc/sysconfig/network with any editor.
           
                                     
# vim /etc/sysconfig/network


And write/modify line as

                                   
HOSTNAME=


Ex: HOSTNAME=centos.virt02.com

close and save file.

2. Open /etc/hosts file  and add as
   

                               
                                # vim /etc/hosts

and add as
                           
192.168.56.101 centos.virt02.com centos


close and save file.

3. Now type command hostname to see current hostname . To assign new hostname

                                 
# hostname=centos.virt02.com



after doing all those steps , restart network with
service network restart


Hope it will help you.

Summary :

[root@localhost Tools]# cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=centos.virt02.com
[root@localhost Tools]# cat /etc/hosts
127.0.0.1               localhost.localdomain localhost
::1             localhost6.localdomain6 localhost6
192.168.56.101 centos.virt02.com centos
[root@localhost Tools]# hostname
centos.virt02.com
[root@localhost Tools]#


0 comments:

Post a Comment