Net Tip: /etc/hosts for Windows

For small networks dependent on an ISP for DNS services, heterogeneous networks where you can't count on every machine having a NetBIOS name, or when slow DNS propagation is an issue for remote workers, the traditional names file has always been useful for UNIX hosts by providing a static mapping of names to IP addresses that takes precedence over DNS servers for hostname lookups. Just a few levels down in the file system, Windows has the same functionality, too.

By Enterprise Networking Planet Staff | Dec 13, 2002
Print ArticleEmail Article
  • Share on Facebook
  • Share on Twitter
  • Share on LinkedIn

For small networks dependent on an ISP for DNS services, heterogeneous networks where you can't count on every machine having a NetBIOS name, or when slow DNS propagation is an issue for remote workers, the traditional Berkeley-style names file has always been useful for UNIX hosts. By creating a line in the hosts file like

192.168.1.8          devserver
users can reference the machine at 192.168.1.8 as 'devserver' instead of using its IP address.

The same functionality exists in Windows operating systems as well, though it's buried a few levels deep in the file system. Where UNIX hosts typically place the file in /etc/hosts, Windows 2000 and XP place it in c:\WINNT\system32\drivers\etc (for Win2k), or c:\WINDOWS\system32\drivers\etc (for WinXP).

An example hosts file for several local hosts and a remote server might look like:

127.0.0.1         localhost localhost.localdomain
192.168.1.2       ix
192.168.1.3       caladan  #department nfs server
192.168.1.4       giedi
192.168.1.5       salusa
128.242.232.186   sandcrawler production.duneco.com

Nothing other than a simple text editor (like Notepad) is needed to modify the file, which is plain text.

Note that you can give a host more than one name in the hosts file: just place the official name of the machine first, then put a space between each of its other names (called 'aliases'). Once you edit and save the file, the changes are instantaneous (no reboot required) and your assorted clients and tools will use the addresses mapped in the hosts file in preference to normal DNS lookups. You can also include comments by using the traditional '#', making it easier to annotate the hosts file for others. See the third entry in our sample above.

Some scenarios where modifying the hosts file might come in handy include:

  • dealing with troublesome routing issues if a local host doesn't have an internally referrable name. In some cases, the latency routing out of a LAN induces can be substantial: this solution allows for direct access across the LAN.
  • conveniently referencing a host that recently had its DNS records updated without having to use its numeric IP until the changes propagate
  • allowing a small, heterogeneous network to operate without benefit of a DNS server.
  • providing a table of hosts for a net-booting workstation

As with any shortcut, there are some caveats to using the hosts file:

  • If you have a lot of machines and need to relate frequent changes in network addresses to them, it's best to consider investing the time and energy in deploying a modest internal DNS server.
  • Since the hosts file takes precedence over DNS lookups, if a host's address changes, the hosts file will need to be changed or clients will continue to reference the old address.

Comment and Contribute
(Maximum characters: 1200). You have
characters left.
Get the Latest Scoop with Enterprise Networking Planet Newsletter
Helpful Links
  • Yankee Group Mobile WAN Optimization Report

    Mobile work continues to evolve. Your organization must keep up with the demands of its mobile workforce. This report introduces the concept of mobile WAN optimization and provides three case studies including RCM, PRTM and Einstein that highlight how this emerging technology can help IT departments achieve what previously appeared to be conflicting goals. Read >

  • Network Security Resources

    More threats than ever before pose a danger to today's enterprise network. Get the latest tips and intel on the newest risks in our guide to network security resources. Read >

  • Extreme Savings: Cutting Costs with WAN Optimization

    Did you know it's possible to cut IT costs without impacting day-to-day IT operations? In fact, when you download this whitepaper from Riverbed on cost-savings through WAN optimization, you'll discover how businesses of all different sizes have realized a return on investment in just a few months through significant hard cost savings in areas such as bandwidth reduction and IT consolidation. It's called Extreme Savings and its only from Riverbed. Read >