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
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          devserver

users can reference the machine at 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:WINNTsystem32driversetc
(for Win2k), or c:WINDOWSsystem32driversetc (for WinXP).

An example hosts file for several local hosts and a remote server might look like:         localhost localhost.localdomain       ix       caladan  #department nfs server       giedi       salusa   sandcrawler

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

  • 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

  • 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.

Latest Articles

Follow Us On Social Media

Explore More