Keeping your sanity with /etc/hosts
Takeaway: 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 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.
Aliases
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):
| 127.0.0.1 | 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 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:
| 172.22.1.2 | insanity.junction | nightmare |
With this file in place, you can perform all of the networking functions by replacing 172.22.1.2 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 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:
| 127.0.0.1 | localhost.localdomain | localhost |
| 172.22.1.2 | insanity.junction | nightmare |
| 172.22.1.3 | records.junction | records |
| 172.22.1.4 | payroll.junction | payroll |
| 172.22.1.5 | customer.junction | customer |
| 172.22.1.6 | 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.SponsoredWhite Papers, Webcasts, and Downloads
- Oracle Web 2.0 Resource Library Oracle
- Cut energy costs with the powerful IBM BladeCenter JS22 Express blade IBM
- Explore the benefits of the IBM BladeCenter S from the inside out IBM
- IBM Power Systems offer a smart alternative to Windows servers IBM
- Upgrading Your Network for CRM? Six Things to Consider Cisco Systems
Article Categories
- Security
- Security Solutions, IT Locksmith
- Networking and Communications
- E-mail Administration NetNote, Cisco Routers and Switches
- CIO and IT Management
- Project Management, CIO Issues, Strategies that Scale
- Desktops, Laptops & OS
- Windows 2000 Professional, Microsoft Word, Microsoft Excel, Microsoft Access, Windows XP,
- Data Management
- Oracle, SQL Server
- Servers
- Windows NT, Linux NetNote, Windows Server 2003
- Career Development
- Geek Trivia
- Software/Web Development
- Web Development Zone, Visual Basic, .NET
What it takes to stay on the edge of innovation
Going green and managing costs during tough economic times
Taking chances with the core brand
Transforming the company and developing new delivery platforms
