Setting Up LMHOSTS Files

When you use Microsoft TCP/IP on a local network with any combination of computers running Windows 95, Windows NT, LAN Manager, or Windows for Workgroups, server names are automatically matched to their corresponding IP addresses. However, to match server names across remote networks connected by routers (or gateways), you can use the LMHOSTS file if WINS servers are not available on the network. The LMHOSTS file is commonly used to locate remote computers for Microsoft networking file, printer, and remote access services, and for domain services such as logon, browsing, replication, and so on.

The LMHOSTS file used by Windows 95 contains mappings of IP addresses to Microsoft networking computer names (which are NetBIOS names). Microsoft LAN Manager 2.x TCP/IP LMHOSTS files are compatible with Microsoft TCP/IP.

Microsoft TCP/IP loads the LMHOSTS file into memory when the computer is started. The LMHOSTS file is a text file in the Windows directory that lists the IP addresses and computer names of remote Windows networking servers that you want to communicate with. The LMHOSTS file should list all the names and IP addresses of the servers you regularly access.

For example, the LMHOSTS table file entry for a computer with an address of 192.45.36.5 and a NetBIOS computer name of Finance1 looks like this:


192.45.36.5      finance1

The format for the LMHOSTS file is the same as the format for host tables in 4.2 MSD UNIX systems. The computer name is optionally enclosed in quotation marks (this is necessary for computer names that contain spaces).

To create an LMHOSTS file

  1. Use a text editor to create a file named LMHOSTS, or edit the default file named LMHOSTS.SAM in the Windows directory and then save this file as LMHOSTS.
  2. In the LMHOSTS file, type the IP address and the host name of each computer that you want to communicate with. Separate the items with at least one space.

Entries in the LMHOSTS file are not case-sensitive.

You will want to use LMHOSTS for smaller networks or to find hosts on remote networks that are not part of the WINS database (because name query requests are not broadcast beyond the local subnetwork). If WINS servers are in place on an internetwork, users do not have to rely on broadcast queries for name resolution, because WINS is the preferred method for name resolution. Therefore, with WINS servers in place, LMHOSTS may not be necessary.

However, the LMHOSTS file is read when WINS or broadcast name resolution fails, and resolved entries are stored in a system cache for later access. When the computer uses the replicator service and does not use WINS, LMHOSTS entries are required on import and export servers for any computers on different subnetworks participating in the replication.

You can use Notepad or any other text editor to edit the sample LMHOSTS.SAM file that is automatically installed in the Windows directory. The following rules apply for entries in LMHOSTS:

The keywords listed in the following table can be used in LMHOSTS using Microsoft TCP/IP. Notice, however, that LAN Manager 2.x treats these keywords as comments.

Keyword

Meaning

#PRE

Added after an entry to cause that entry to be preloaded into the name cache. By default, entries are not preloaded into the name cache but are parsed only after WINS and name query broadcasts fail to resolve a name. #PRE must be appended for entries that also appear in #INCLUDE statements; otherwise, the entry in #INCLUDE is ignored.

#DOM:domain

Added after an entry to associate that entry with the domain specified by domain. This keyword affects how the Browser and Logon services behave in routed TCP/IP environments. To preload a #DOM entry, you must also add the #PRE keyword to the line.

#INCLUDE filename

Forces the system to seek the specified filename and parse it as if it were local. Specifying a Universal Naming Convention (UNC) filename allows you to use a centralized LMHOSTS file on a server. You must add a mapping for the server before its entry in the #INCLUDE section and also append #PRE to ensure that it is preloaded (otherwise, the #INCLUDE will be ignored).

#BEGIN_ALTERNATE

Used to group multiple #INCLUDE statements. Any single successful #INCLUDE statement causes the group to succeed.

#END_ALTERNATE

Used to mark the end of an #INCLUDE grouping.

\0xnn

Support for nonprinting characters in NetBIOS names. Enclose the NetBIOS name in double quotation marks and use \0xnn hexadecimal notation to specify a hexadecimal value for the character. This allows custom applications that use special names to function properly in routed topologies. However, LAN Manager TCP/IP does not recognize the hexadecimal format, so you surrender backward compatibility if you use this feature.

Notice that the hexadecimal notation applies only to one character in the name. The name should be padded with blanks so the special character is last in the string (character 16).


The following example shows how all of these keywords are used:


102.54.94.98      localsrv   #PRE
102.54.94.97      trey      #PRE   #DOM:networking   #net group's PDC
102.54.94.102   "appname        \0x14"      #special app server
102.54.94.123   popular      #PRE      #source server
#BEGIN_ALTERNATE
#INCLUDE \\localsrv\public\lmhosts      #adds LMHOSTS from this server
#INCLUDE \\trey\public\lmhosts      #adds LMHOSTS from this server
#END_ALTERNATE

In the preceding example:

Guidelines for LMHOSTS

When you use a host table file, be sure to keep it up to date and organized. Follow these guidelines: