Are you tired of typing ftp://172.22.1.222 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 172.22.1.37.
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):
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 172.22.1.2, 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:
With this file in place, you can perform all of the networking functions by replacing 172.22.1.2 with nightmare.
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 172.22.1.3 for employee records, one machine for payrolls at 172.22.1.4, one machine for customer files at 172.22.1.5, and one machine for billing at 172.22.1.6. It would make sense to have an /etc/hosts file that looks something like this:
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.
Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website jackwallen.com.