When we are using virtual machines, sometimes it will take the IPaddress or Hostname.When we reboot the virtual machine, the IPaddress may change.It will badly affect the cluster.So to avoid this, we are using the hostname only.That is why we are changing the hostname of the Linux machine without rebooting

step 1: Change the hostname

We can change the hostname of Linux system.First we must change the config file that control this.

  • In Redhat/Centos/Fedora systems,

We can edit the hostname in /etc/sysconfig/network

nano /etc/sysconfig/network

HOSTNAME=<hostname of the system >

  • IN Ubuntu/Debain systems,

we can edit the hostname in /etc/hostname

nano /etc/hostname

delete old name and add the new name

step 2: Update /etc/hosts

Now, you need to edit /etc/hosts file

nano /etc/hosts

In ‘etc/hosts’ file, we can enter both IPaddress and hostname.So either hostname or IPaddress will be taken.

Leave a Reply

Your email address will not be published. Required fields are marked *