How to Change Hostname in Linux

In This post we will learn how to change or add hostname in linux.Hostname is unique identification of your computer on network, Host names can only contain letters (a through z), digits (0 through 9), and the hyphen character ( – ), and the period character ( . ). A hostname must begin and end with a letter or number — not a hyphen or period. You can change HOSTNAME any time using command in Linux, here I am providing steps by step process to change hostname in linux. You could not use the same hostname on two different computers on a network .
Each computer has IP address we just match this IP to readable form of string that’s Hostname, like here is host name of this IP.

You can also check other recommended Linux tutorials,

You can check what’s host name of your Linux machines:

$ hostname

How To Change the Hostname in Linux

  • Open terminal window
  • Open host file using ($ sudo vim /etc/hostname)

Now you can see an entry against to local host. You can add below entry in your host file, if this entry already exist then you need to change your-hostname if you want modify existing hostname.
$ your-ip your-hostname

Now you can reboot your system and find modified hostname :).


We have checked hostname in linux.We have also change hostname inLinux.You have seen its very easy to set hostname in linux using single command.