Back docs > tech help > hosts and lmhosts files
     
   
   

From the Microsoft Windows 98 Resource Kit


Setting Up HOSTS Files  

Setting Up LMHOSTS Files  




Setting Up HOSTS Files     
Top

Microsoft TCP/IP can be configured to search the local host table file, HOSTS, for mappings of remote host names to IP addresses. The HOSTS file format is the same as the format for host tables in the version 4.3 Berkeley Software Distribution (BSD) UNIX /etc/hosts file. For example, the entry for a computer with an address of 192.102.73.6 and a host name of trey.research.com looks similar to this:

192.102.73.6        trey.research.com

Edit the sample HOSTS file that is created when you install TCP/IP to include remote host names and their IP addresses for each computer with which you will communicate. This sample file also explains the syntax of the HOSTS file.

Host names are used in virtually all TCP/IP environments. A host name always corresponds to an IP address that is stored in a HOSTS file or on a DNS server and is assigned by an administrator to identify a TCP/IP host or default gateway. A host name can be used in place of an IP address when using ping or other TCP/IP utilities.

Host names are not used in the Windows 98 network user interface, such as Network Neighborhood or Net.exe. The only time a host name is used to access a Windows-based computer is when ping or ftp or another TCP/IP utility is used. In this case, the host name and corresponding IP address must be stored in a HOSTS file.

The HOSTS file is a static file used to map host names to IP addresses. This file provides compatibility with the UNIX HOSTS file. The following describes HOSTS file entries:

  • A single entry consists of an IP address corresponding to one or more host names.
  • Entries are case-sensitive. Therefore, it is a good idea to assign multiple host names with different cases.

For example, to connect to the UNIX host archive.research.com at the IP address 144.3.56.200, make two entries in the HOSTS file:

144.3.56.200     ARCHIVE.RESEARCH.COM

144.3.56.200     archive.research.com

This way, a user can connect to ARCHIVE using a utility, whether or not the CAPS LOCK is enabled.

A HOSTS file must reside on each system. By default, the host name localhost is an entry in the HOSTS file with the loopback address 127.0.0.1.

The HOSTS file is parsed whenever a host name is referenced. Names are read in a linear fashion. The most commonly used names should be near the beginning of the file. HOSTS file entries do not replace or interact with Windows-based NetBIOS computer names in any way.

The following shows the default HOSTS file provided with Windows 98.

# Copyright (c) 1994 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows 98
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the computer name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host
127.0.0.1     localhost

 

 

Setting Up LMHOSTS Files      Top

When you use Microsoft TCP/IP on a local network with any combination of computers running Windows 98, Windows NT, LAN Manager, or Windows for Workgroups, server names are automatically mapped to their corresponding IP addresses. However, to map 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 98 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, with the exception that LMHOSTS does not allow a scoped name to be indicated. 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. This LMHOSTS file will be checked by default as the machine starts.

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:

  • Each entry should be placed on a separate line.
  • The IP address should begin in the first column, followed by the corresponding computer name.
  • The address and the computer name should be separated by at least one space or tab.
  • The # character is usually used to mark the start of a comment. However, it can also designate special keywords, as described in this section.

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. #PRE entries in LMHOSTS are looked up and cached prior to WINS lookup. #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 map 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 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: 
  • The servers named localsrv and trey are preloaded so they can be used later in an #INCLUDE statement in a centrally maintained LMHOSTS file.
  • The server named "appname \0x14" contains a special character after the 15 characters in its name (including blanks), so its name is enclosed in quotation marks.
  • The server named popular is preloaded, based on the #PRE keyword.  
  • Additional Comments
    LMHOSTS example:

    IP Address PDCName #PRE #DOM:domainname
    IP Address "domainname,,,,,\0x1b" #PRE

    Where IP Address is the address of your PDC.
    PDCName is the name of your PDC
    domainname is the name of your Domain
    and
    domainname,,,,, is also the name of your Domain. However, the commas represent spaces, and in this line, your domainname must be 15 characters. If it isn't, pad it with the appropriate number of spaces to reach 15 characters.
    And...use the quotes

    Your PDC acts as the Domain Master Browser, and as such, should have the browse lists of all Segment Master Browsers (if you have a multi-segment network), thus a list of all network devices.

    The above LMHosts file tells your PC the name of the logon domain controller (your PDC), and the second line says use the PDC as your browse master.

    If you can ping your PDC and net use a share to the PDC, then the above should work.


Guidelines for LMHOSTS

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

  • Update the LMHOSTS file whenever a computer is changed or removed from the network.
  • Use #PRE statements to preload popular entries into the local computer’s name cache and to preload servers that are included with #INCLUDE statements.
  • Because LMHOSTS files are searched one line at a time from the beginning, you can increase the speed of searches for the entries used most often by placing frequently used servers near the top of the file. Follow these with less frequently used servers, and then remote #INCLUDE statements. The #PRE entries should be at the end of the file, because these are preloaded into the cache at system startup time and are not accessed later. Comment lines add to the parsing time, because each line is processed individually.

 

Top