LMHOSTS File Information and Predefined Keywords

Last reviewed: November 5, 1997
Article ID: Q102725
The information in this article applies to:
  • Microsoft Windows NT operating system version 3.1
  • Microsoft Windows NT Advanced Server version 3.1
  • Microsoft Windows NT Workstation versions 3.5, 3.51, and 4.0
  • Microsoft Windows NT Server versions 3.5, 3.51, and 4.0

The LMHOSTS file is a local text file that maps IP addresses to NetBIOS names of remote servers with which you want to communicate over the TCP/IP protocol. Windows NT recognizes names instead of IP addresses for network requests and a name discovery process is used to correctly route network requests with TCP/IP. Because the name discovery process is generally not routed by an IP router, the LMHOSTS file allows Windows NT machines to communicate using TCP/IP across a subnet.

This article is divided into the following sections:

  • Comprehensive Information
  • LMHOSTS Entry Cache
  • Predefined Keywords
  • More Information on Block Inclusion

Comprehensive Information

  • LMHOSTS contains IP address to "NetBIOS over TCP/IP" name translations.
  • LMHOSTS is only used by the NBT (NetBIOS over TCP/IP) interface.
  • LMHOSTS file contains some valuable additions to the LAN Manager and Windows for Workgroups LMHOSTS file, such as the ability to support routed domain logon validation.
  • LMHOSTS contains static information about TCP/IP addresses, but using logon scripts and/or the replicator service, the "master" file can be distributed transparently across all stations.
  • By default, the LMHOSTS file should be located in the directory %SYSTEMROOT%\SYSTEM32\DRIVERS\ETC (usually C:\WINNT\SYSTEM32\DRIVERS\ETC).

LMHOSTS Entry Cache

By default, entries specified with the #PRE keyword are cached at initialization up to a maximum of 100 entries. More initially cached entries can be obtained modifying the following Registry value:

   \HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services
   \NetBT\Parameters\MaxPreload

The sequence used to determine NetBIOS to IP address resolution is the following: the cache is verified, a broadcast to the subnet is performed, and then additional entries from LMHOSTS are checked. If a connection is not established within 15 seconds, the TDI times-out and an error message is displayed.

Predefined Keywords

All predefined keywords that are valid for Windows NT and Windows NT Advanced Server computers are not valid for LMHOSTS files on Microsoft LAN Manager or Microsoft Windows for Workgroups computers. These computers can't be validated by routed domain controllers the same way Windows NT computers can. To be able to validate them, use the LAN Manager TCP/IP Extensions Service available on all OS/2 LAN Manager (version 2.1a or later) servers.

   # <remark line>
      Used to remark IP address to NetBIOS names.
   #PRE
      Defines which entries should be initially preloaded into the
      name cache.
   #DOM:<domain_name>
      Distinguishes Windows NT Advanced Server servers from Windows NT
      workstations, a LAN Manager server, or a Windows for Workgroups
      computer. This keyword is needed for all servers that validate logon
      requests.
   #NOFNR
      Avoid Directed Name Queries (DNS). Some earlier versions of LAN
      Manager cannot handle NetBIOS DNS requests and return error 53.
      Specifying this flag on the same line will avoid using NetBIOS
      directed name queries.
   #BEGIN_ALTERNATE
      #INCLUDE <\\server_name01\sharename\LMHOSTS>
      #INCLUDE <\\server_name02\sharename\LMHOSTS>
      ...
   #END_ALTERNATE
      Defines a redundant list of alternate locations for LMHOSTS files.
      The recommended way to #INCLUDE remote files is using a UNC path,
      to ensure access to the file. Of course, the UNC names must exist
      in the LMHOSTS file with a proper IP address to NetBIOS name
      translation.
   #MH
      Associates a single, unique NetBios computer name to an IP address.
      You can create multiple entries for the same NetBios computer name
      for each NIC in the multihomed device, up to a maximum of 25
different
      IP addresses for the same name.

   #SG
      Used to define a special group, such as printers or computers that
      belong to groups on the intranet for easy reference, browsing or
      broadcasting. Special groups are limited to a total of 25 members.

The first 3 keywords can be used together to specify 1 NetBIOS over TCP/IP name to IP address translation. For example:

102.54.94.97   rhinodc   #DOM:rhino   #The rhino domain PDC   #PRE
102.54.94.99   zoobdc    #DOM:rhino   #BDC for rhino domain   #PRE

NOTE: PDC is primary domain controller and BDC is backup domain controller.

To start with the IP Address followed by the NetBIOS name, the predefined entries can be defined in diverse order. It is recommended to insert important entries first, because the the file is accessed in sequential order.

More Information on Block Inclusion Keywords

Windows NT provides new block commands that permit centralized location and management of the LMHOSTS file. In addition, provisions are included to permit redundant backup copies on multiple servers. The following Windows NT LMHOSTS file block commands are discussed in detail below:

  • #INCLUDE
  • #BEGIN_INCLUDE
  • #END_INCLUDE
  • #BEGIN_ALTERNATE
  • #END_ALTERNATE

Block Inclusion Keywords (#BEGIN_INCLUDE, #END_INCLUDE):

   130.20.26.169  Trustedserver  #PRE   #DOM:Testing  # Test group domain

   #BEGIN_INCLUDE
   #INCLUDE \\localsrv\public\lmhosts       # Local domain
   #INCLUDE \\Trustedserver\public\lmhosts  # Server in Testing domain
   #END_INCLUDE

In the above block inclusion, the specified LMHOSTS file is scanned under the following conditions:
  • During TCP/IP initialization, the local LMHOSTS file is scanned for #PRE commands. It places all these entries in its name cache. In addition, all LMHOSTS files specified by the #INCLUDE command are scanned.
  • When resolving a computer name (NetBIOS name) to an IP address, the #INCLUDE file is also searched if the name cannot be found in the preloaded entries of the cache.
  • The LMHOSTS files are scanned to resolve the address of a domain controller of a domain that is not found in the preloaded cache name list.

The benefit of this command is that it allows system administrators to easily maintain a centrally-located master LMHOSTS file that can be accessed over the network by each node. This method also works across subnets because of the use of UNC (universal naming convention) names and LMHOSTS mappings for these entries.

If the domain spans multiple subnets or if the domain controller for a domain is across a router, it is necessary to have an entry in the LMHOSTS file for locating the domain controller for that server, with a #DOM prefix added (for our example, trustedserver is the domain controller for domain TESTING). See the IP line above the block inclusion. This line must appear before the #INCLUDE.

In the above case, the TESTING domain has a trust relationship with the local domain. This is important for servers included in the block that are not in the local domain.

NOTE: The LMHOSTS files located on servers that are in a trusted domain should have read privileges for the Everyone group, which includes all of the local users and the trusted domain users.

Alternate Block Inclusion (#BEGIN_ALTERNATE, #END_ALTERNATE):

   #BEGIN_ALTERNATE
   #INCLUDE \\localsrv\public\lmhosts      # Local domain
   #INCLUDE \\Trustedserver\public\lmhosts # Server in Testing Domain
   #END_ALTERNATE

In this case, the "Alternate Include" condition is satisfied if one of the #INCLUDE's is successful. This means that only one LMHOSTS file will be scanned. The first successful #INCLUDE is the only LMHOSTS file that will be read.

This is helpful in keeping multiple copies of the same file on different servers. If one of the servers is down, it will attempt to read the LMHOSTS file from the alternate server identified in the block inclusion.

Additional information, including a full description of all these features, is available in the "Windows NT Resource Kit."


Additional query words: wfw wfwg prodnt
Keywords : NTSrvWkst nttcp kbnetwork
Version : 3.1 3.5 3.51 4.0
Platform : winnt


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 5, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.