How to change Hostname in Linux

A hostname is the unique name by which a network-attached device (which could consist of a computer, file server, network storage device, fax machine, copier, cable modem, etc.) is known on a network. The hostname is used to identify a particular host in various forms of electronic communication such as the World Wide Web, e-mail or Usenet.
On the Internet, a hostname is a domain name assigned to a host computer.
To find out your hostname, use the following command:


$ uname -n
or
$ hostname


There are 2 ways to change the host name, a temporary and a permanent way.




  • To immediately (but not permanently) change the hostname:

    • $ hostname newhostname
  •  The "permanent" way is a bit different depending the distro you run:
If you want the hostname to stick even after a reboot in Linux there are 2 files to change: the /etc/sysconfig/network and the /etc/hosts:

In the /etc/sysconfig/network I added the line:

CODE
HOSTNAME= newhostname

Next in the /etc/hosts file I changed the "127.0.0.1 localhost.localdomain localhost" to:

CODE
127.0.0.1       newhostname localhost

Finally reboot and you will see that the hostname is set.

0 comments:

Post a Comment