WTF Is a Hostname?

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.

Pictured: Hostname in terminal prompt.  A.K.A. Aesthetic Nicety

Pictured: Hostname in terminal prompt. A.K.A. Aesthetic Nicety

 

 

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

 

Your computer’s name“, that’s the hostname.  Here’s another screenshot of Debian asking for the hostname.

 

Your 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.

 

/etc/hostname

 

Simply change the text in that file to your new hostname, save the file, and restart the machine.  The same restrictions on hostnames applies.

 

If you don’t have a /etc/hostname file, or changing its value doesn’t work, then your distribution may use a different configuration file.  This isn’t very common anymore.  But if you find a distribution that operates differently, simply search Google for “<distribution name and version> change hostname” replacing <distribution name and version> with your distribution name and version.

Then, help out others by leaving a comment with your distribution and filename below.

 

Written By

John is a sailing instructor and mechanical engineering student who happens to be a computer geek. To find more information about John, visit his website or find him on social media by clicking on the icons below.

Facebook Twitter Google+ Website

Tags: ,

Join the Conversation!