Change hostname on Linux

What is hostname ?

*From wikipedia
“In computer networking, a hostname (archaically nodename) is a label that is assigned to a device connected to a computer network and that is used to identify the device in various forms of electronic communication such as the World Wide Web, e-mail or Usenet. Hostnames may be simple names consisting of a single word or phrase, or they may be structured.”

To change your hostname open your terminal and type this following command on your terminal :

$ sudo sysctl -w kernel.hostname=”yourhostname”

Press enter.

Close and open again your terminal to see changes.

But this change is not permanent, that means if you restart your computer this settings will be revert back to your old hostname.

To make it permanent you must edit hostname configuration file.

$ sudo vim /etc/hostname

change it to your hostname, and save it.

If you get an error cannot resolve your hostname, then you should edit one more file.

$ sudo vim /etc/hosts

then change hostname next on the local IP (this situation maybe different) , then save.

Restart your computer to see changes.

Leave a Reply

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