Everyone has a name right? It’s how we identify each other.
As a kid, if a teacher yelled “John go to the principal’s office,” I knew I was in trouble.
This is strictly hypothetical of course. I was an angel. I never darkened the doorstep of the principal’s office and any documentation indicating differently was burne… er… never existed.
But the point remains. We are identified by names.
Well, names are used by computers to identify each other as well.
Humans have first names, last names, and possibly middle names, computers have hostnames. Where user-friendliness is paramount, computer name is sometimes used instead of hostname. However, hostname is more common.
The way computers use and identify hostnames in and between computers is the subject of some heavy, mind-warping computer networking. Which I’m not going to discuss.
But, I will discuss how hostnames affect you, and how to set them in Linux.
How Does The Hostname Affect Me?
It probably doesn’t. Especially if you’re just starting out using Linux.
Hostnames only become important when managing a network of several machines.
In this computer addicted world, it’s not uncommon for a single household to have 4 or more computers. And to have these computers networked together so they can share files, media, and more. Giving each computer a unique and descriptive name makes creating, managing, and utilizing this network simpler.
Many businesses have hundreds or thousands of computers networked together that all need management. Hostnames help organize that mess.
If your machine is operating in isolation, or in a very small network, hostnames don’t matter much apart from a few aesthetic niceties.
Setting Your Hostname
If the aesthetic niceties are important to you, or you have a network of computers, then you can easily set a hostname.
Hostnames are usually set during operating system installation.
If you’ve read our eBook, Just Tell Me Damnit!, you’ve seen this picture before:
“Your computer’s name“, that’s the hostname. Here’s another screenshot of Debian asking for the hostname.
When choosing a hostname, you may only use the letters ‘a’ through ‘z’, the digits ‘0’ through ‘9’, and the hyphen (‘-‘). Hostnames cannot begin or end with a hyphen. And they should not exceed 63 characters in length (but may still work if kept beneath 255 characters in length). Hostnames are case-insensitive.
More information on hostname restrictions can be found in the Internet standards for protocols documents, RFC-952 and RFC-1123 Section 2.1 if you’re interested.
Setting Hostname After Installation
The hostname can easily be changed after installation as well.
The hostname of a Linux computer is retrieved from a configuration file each time the system starts up. As explained in our article, The Essential Guide to the Linux Filesystem, configuration files are stored in the /etc/ directory. Most distributions use the /etc/hostname file.