Ease Linux Networking With /etc/hosts
How many times have you gone to your Linux box to administer your network and found yourself developing carpal tunnel from typing ssh -v -l jlwallen 192.168.1.10 -X? Or how taxing to your memory is it when you have to remember an IP address assigned to that Linux file server that never needs babysitting save for when you do an upgrade - how do you remember that one IP address when you have a network that consists of hundreds of machines?
Thankfully the Linux operating system contains its own system for mapping IP addresses to names. So instead of having to type (or remember) an IP address for that file server at 192.168.1.10 you can map it to a name like "files".
The hosts file is actually a smaller part to a larger system that includes a deny and an allow file. But this article will focus on the /etc/hosts file. This file most be edited by the root user and can be edited in a standard text editor like Nano.
Once you have the file open you will instantly understand the format. The default entry for /etc/hosts looks like this:
127.0.0.1Â Â Â Â Â Â Â Â Â Â Â Â Â Â localhost
This is the loopback entry and must be left alone. This is a special entry responsible for software local addressing. Do not delete or change this entry. But this entry illustrates how this file works. The "official" structure of an /etc/hosts entry looks like this:
IP AddressÂ Â Â Â Â Â Â Â Â FQDNÂ Â Â Â NAME
From our loopback entry you can see that the FDQN is not required. If the machine does have a fully qualified domain name use it, if not - don't. Let's use the example we started early on. We'll create an entry for the file server.
192.168.1.10Â Â Â Â Â Â Â Â Â files
Now instead of typing ssh -l -v jlwallen 192.168.1.10 -X you can enter ssh -v -l jlwallen files -X and you're on your way. See how simple mapping addresses can be in Linux? And don't hesitate to fill this file up. If you have a network with hundreds of servers, add an entry for each machine to make your network much easier to navigate.Advertisement