how to change hostname in linux

Very often you might want to change the hostname in your linux server. The hostnames are usually written like…

vps.domain.com
server.domain.com
box.domain.com
web.domain.com

and it is a very good idea to follow this hostname format.

To change hostname all you have to do is modify 2 files

1. Open /etc/hosts and change the name of the host

127.0.0.1 vps.domain.com vps localhost localhost.localdomain

2. Open /etc/sysconfig/network and do the change

HOSTNAME="vps.domain.com"

Once this is done, check whether the hostname has been changed using hostname command after restart.

Thats all!