Ease Linux Networking With /etc/hosts - gHacks Tech News

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 -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 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:               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.          files

Now instead of typing ssh -l -v jlwallen -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.

We need your help

Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.

We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats or subscription fees.

If you like our content, and would like to help, please consider making a contribution:


  1. hybrid-kernel said on January 16, 2009 at 4:50 am

    For my one and only server I set up a passwordless (I know) login with the command “sshs” (ssh server). I just use the server for playing around, so security isnt a biggie.

    btw sshs=”ssh -i /path/to/rsync.key [email protected]

  2. Anonymous said on January 16, 2009 at 7:53 am

    Hey Jack, Great tip that editor http://www.nano-editor.org/. I do not have a Linux network with hundreds of machines, i have only one machine, but good to rememeber for hopeful, the not to far future. Thanks again for yet one outher christal clear artikel.

  3. Charles said on January 16, 2009 at 1:19 pm

    This is not a linux feature as you seem to claim, you can do this from every operating system I know of, yes, even windows. The file lives in C:\Windows\system32\drivers\etc.

  4. Syahid A. said on January 25, 2009 at 3:04 pm

    Cool trick one can learn to easily connect between multiple PC’s, in Linux and Windows too. Both files are called “hosts” files.

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

Please note that your comment may not appear immediately after you post it.