Changing hostname in Linux

Change hostname linux

If your change is only temporary, or you want to make it without rebooting, you just need to use the hostname command, which can be found at /bin/hostname. Running it without arguments just outputs the current hostname. To change it, su to root and run hostname newhostname.

You need to look at the value for hostname in /etc/sysconfig/network

The contents will look something like this:

Change the HOSTNAME= parameter value to the proper hostname

…and save the file

Make sure that /etc/hosts has the new hostname properly referenced in it

Then restart the network service (this will not take the box down)
service network restart

If that doesn’t do it, you can modify /proc/sys/kernel/hostname to modify it on the fly.

If that doesn’t do it, reboot the machine after making those changes and it should come back up with the new hostname.

Leave a Reply

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