Murphy Mac - Screencasts and Tutorials » Page 'The Hosts File'

The Hosts File


One of the biggest headaches for network administrators, especially in a Windows environment, is name resolution. What’s name resolution? It’s pretty simple in concept, and quite complicated in some implementations.

The Hosts FileComputers on the Internet and on any IP network have IP addresses, like Those numbers are hard to remember, so we use names instead. Like The same is true in your house. You have an iMac in the kitchen, maybe its name is clara and its IP is You should be able to access it across the network from another machine using its name, clara. Mechanisms built into Windows and OS X turn the name clara into an IP address and you connect.

Name resolution is pretty complicated, and sometimes it plain just doesn’t work. You could try to troubleshoot it, but that can be very time consuming. The main tool for turning computer names into IP addresses is DNS (Domain Name System), which acts something like a phone book. When you type into Safari a DNS server is contacted and it returns the IP of to your computer. Then your computer connects to using the IP address. All that, and a lot more, happens every time you access a site. And you think it’s slow!

When you can’t access a computer or site by name, the logical next step is to use the IP address. That eliminates name resolution as the source of the problem. Instead of taking that big step you could implement a hosts file. Hosts is a simple listing of IP addresses and corresponding names. Because it’s so simple, it’s unlikely to malfunction.

In the early days of the Internet a hosts file was shared amongst the users. The rapid growth of computers (hosts) on the Internet made hosts inadequate as a name resolver. DNS distributed the load across many computers and still serves us today.

On your home network your computers rely on a system of announcing themselves periodically to let other computers know they’re there and what their names are. This is more complicated when you have a mix of Windows and Mac computers living together, and when computers are frequently powered on and off.

If you want to be proactive, you can configure a hosts file on each computer, listing the names and ip addresses of the other computers on your network. Once you’ve done this your name problems should be greatly reduced. You can access other computers by name instead of typing the awkward IP addresses.

It’s important to note that computers have multiple ways to resolve names. Their own cache of resolved names, the hosts file, DNS, and other databases. When troubleshooting it helps to know what order OS X tries to resolve names. Tiger uses hosts before consulting DNS. If the name is found in hosts there won’t be a DNS lookup. You can use the lookupd command to see how your computer resolves host names.

In Terminal type “lookupd -configuration” and press enter. Look for output like the following:

LookupOrder: Cache FF DNS NI DS
_config_name: Host Configuration

FF means flat file and is in fact the hosts file. Tiger looks at hosts first. Your version of OS X might not.

You might think the hosts file would be a good way to simplify your browsing – by adding the names (or nick names) of sites you access frequently and their IP addresses. Nick names? The name you enter in hosts doesn’t have to be the actual name of the computer or site you’re accessing. It’s the name you want to type.

Regardless, that could be a lot to manage and might lead to unexpected results. The screencast shows how to use a keyword in Firefox that lets you use an alias, called a keyword. Murphy suggests you try it out. If you want to get crafty with hosts, take a look at using it to block pop-up ad domains. Personally, ads don’t really bother Murphy. And they help to support some great sites!

The hosts file history is pretty interesting, for geeks. It was the way to resolve names on the Internet for about ten years, with users downloading a copy every night. You don’t know how good you have it!

Watch Now | Permalink

4 comments to “The Hosts File”

  1. how delete the link “router” ?
    i went back to sudo pico /etc/hosts
    i deleted it but i still end up on my router page ?

  2. I’m not sure what you mean. What is your “router page” ?

  3. I used your method in the video to block a website. How can you undo this change?

  4. My partner and I stumbled over here by a different page and thought I
    might as well check things out. I like what I see
    so now i’m following you. Look forward to looking at your web page
    for a second time.

Leave a comment