Using Centralized LMHOSTS Files

With Microsoft TCP/IP, you can include other LMHOSTS files from local and remote computers. The primary LMHOSTS file is always located in the \systemroot\SYSTEM32\DRIVERS\ETC directory on the local computers. Most networks will also have an LMHOSTS file maintained by the network administrator, so administrators should maintain one or more global LMHOSTS files that users can rely on. This is done using #INCLUDE statements rather than copying the global file locally. Then use the replicator service to distribute multiple copies of the global file(s) to multiple servers for reliable access.

Note If network clients access a computer's LMHOSTS file, that computer's Registry parameter NullSessionShares must include the share where the LMHOSTS file is located. The NullSessionShares parameter is in the Registry key HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\LanManServer\Parameters. For detailed information on Registry parameters, see Chapter 14, "Registry Value Entries," in the Windows NT Resource Guide.

To provide a redundant list of servers maintaining copies of the same LMHOSTS file, use the #BEGIN_ALTERNATE and #END_ALTERNATE keywords. This is known as a block inclusion, which allows multiple servers to be searched for a valid copy of a specific file. The following example shows the use of the #INCLUDE and #_ALTERNATE keywords to include a local LMHOSTS file (in the C:\PRIVATE directory):



102.54.94.97 treydc #PRE #DOM:treycorp #primary DC 102.54.94.99 treybdc #PRE #DOM:treycorp #backup DC in domain 102.54.94.98 localsvr #PRE #DOM:treycorp #INCLUDE c:\private\lmhosts #include a local lmhosts #BEGIN_ALTERNATE #INCLUDE \\treydc\public\lmhosts #source for global file #INCLUDE \\treybdc\public\lmhosts #backup source #INCLUDE \\localsvr\public\lmhosts #backup source #END_ALTERNATE

Important This feature should never be used to include a remote file from a redirected drive, because the LMHOSTS file is shared between local users who have different profiles and different logon scripts, and even on single-user systems, redirected drive mappings can change between logon sessions.

In the above example, the servers treydc and treybdc are located on remote subnets from the computer that owns the file. The local user has decided to include a list of preferred servers in a local LMHOSTS file located in the C:\PRIVATE directory. During name resolution, the Windows NT system first includes this private file, then gets the global LMHOSTS file from one of three locations: treydc, treybdc, or localsvr. All names of servers in the #INCLUDE statements must have their addresses preloaded using the #PRE keyword; otherwise, the #INCLUDE statement is ignored.

The block inclusion is satisfied if one of the three sources for the global LMHOSTS is available and none of the other servers are used. If no server is available, or for some reason the LMHOSTS file or path is incorrect, an event is added to the event log to indicate that the block inclusion failed.