Keeping your sanity with /etc/hosts

The /etc/hosts file is a great tool that will cut down on the time that you spend typing when you're using various network protocols. It also will help you remember aliases. Jack Wallen explains how.

Are you tired of typing every time you need to grab a file from within your corporate ftp server? It's a hassle, and it wastes time. But how can you get around it? Simple. The /etc/hosts file is a great tool that will help cut down on your typing when you’re using various network protocols.

The biggest benefit of using the /etc/hosts file is its ability to assign various aliases to an IP address. This ability will save your fingers from constantly typing IP addresses. An alias can be almost any alphanumeric combination, but you ought to keep them short, easy to remember, and simple to type. For example, the alias bob is much easier to remember than

From your favorite editor (and as root if you plan on editing), you should open /etc/hosts. You will see the following line (and perhaps more): localhost.localdomain localhost

Normally, this line is the first entry in the hosts file, and it should remain so. There’s an IP address (in this case, the loopback address), a hostname.domain name, and an alias. The hostname is the name of the computer that you’re using, the domain is the domain of your network, and the alias is a user-defined name for the computer. Let's enter a new alias for the machine that you’re using. Let's say that the IP address of your machine is, the name of the machine is insanity, the domain is junction, and the alias that you’ve chosen is nightmare. This entry would appear like so: insanity.junction nightmare

With this file in place, you can perform all of the networking functions by replacing with nightmare.

Entire network
Of course, it’s also possible to enter an entire private (or even public) network’s worth of aliases into this file. Since this file may become a long list of machine names that you’ll have to memorize, you can make it easier on yourself by using aliases that reflect what the machines in question do. Let's say that you have one machine with an IP address of for employee records, one machine for payrolls at, one machine for customer files at, and one machine for billing at It would make sense to have an /etc/hosts file that looks something like this: localhost.localdomain localhost insanity.junction nightmare records.junction records payroll.junction payroll customer.junction customer billing.junction billing

Now, you have a very simple way of remembering what goes where.

Jack Wallen, Jr. is very pleased to have joined the TechRepublic staff as editor in chief of Linux content. Jack was thrown out of the "Window" back in 1995, when he grew tired of the "Blue Screen of Death" and realized that "computing does not equal rebooting." Prior to Jack's headfirst dive into the computer industry, he was a professional actor with film, TV, and Broadway credits. Now, Jack is content with his new position of Linux evangelist. Ladies and gentlemen—the poster boy for the Linux Generation!

The authors and editors have taken care in preparation of the content contained herein, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for any damages. Always have a verified backup before making any changes.

About Jack Wallen

Jack Wallen is an award-winning writer for TechRepublic and He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website

Editor's Picks

Free Newsletters, In your Inbox