Set your hostname in Linux

Linux

If you are an administrator then you know what a hostname is. If you are not an administrator then you should know that the hostname of a computer is the name which a network attached device is known. Unless you have manually changed your hostname, or set it up during installation, your hostname will most likely be ìlocalhost.localdomainî.

Find your hostname

The most common means to find your host name is to open up a terminal window and enter the command:

hostname
If you have not set your hostname, more than likely you will see returned:

localhost.localdomain
Temporarily changing your hostname

You can temporarily change your hostname by issuing a single command as root user

hostname bharat
Now issue the command hostname which should report back:

bharat
This change will last until you reboot your machine.

Permanently changing your hostname

How you permanently change your hostname will depending upon which distribution you use.

On Ubuntu:

Edit the file /etc/hostname to remove old hostname and add new one.To make this chang take effect issue the command:

/etc/init.d/hostname.sh start
This hostname will remain intact upon reboot.

On Fedora/RHEL:

Edit the file /etc/sysconfig/network . The default contents of this file will look like below . Edit the hostname

NETWORKING=yes
HOSTNAME=localhost.localdomain
Once you have made this change issue the following command (as the root user):

/etc/rc.d/rc.sysinit
For the change to take effect.