how to set the host name on a Linux system

From Sharkysoft Wiki
Jump to: navigation, search

I recommend you read through this entire article before beginning.

The host name is set as part of your system's boot-up process, using the hostname command. The hostname is read from a plain text file located at:


So, if you'd like a different host name, simply edit this file in your favorite text editor. You will need root permissions. The change will be permanent, but it will not take effect until you reboot your system.

If you desire instant gratification -- or simply don't want to reboot your machine -- then you can also just run the hostname command yourself. The following command should do the trick:

sudo hostname the_name

This all seems easy enough, but there is one gotcha. After your host name changes, you may lose your ability to run sudo. This is because sudo consults another plain text file,


as part of its security process, and your hostname is stored in there, too! To ensure you don't get locked out, also update the host name in that file as well. It may be best to edit both text files in the same sudo command. For example:

sudo nano /etc/hostname /etc/hosts

Good luck, and be careful!

Personal tools