Библиотека сайта rus-linux.net
Chapter 7. Name Resolution and Browsing
While name resolution and browsing are not difficult to configure, some complexity is introduced by the variety of available name-resolution systems. Historically, Unix and other TCP/IP users have moved from a flat hosts file to the Domain Name System, with the Network Information System being another popular choice. Meanwhile, Microsoft has moved from a broadcasting system to a simple, LAN-only name server called WINS and ultimately to DNS.
Name Resolution
The main problem with performing name resolution using broadcast packets is poor performance of the network as a whole, including CPU time consumed by each host on the network, which has to accept every broadcast packet and decide whether to respond to it. Also, broadcast packets usually aren't forwarded by routers, limiting name resolution to the local subnet. Microsoft's solution was to add WINS (Windows Internet Name Service) support to Windows NT so that the computers on the network can perform a direct query of the WINS server instead of using broadcast packets.
Modern Windows clients use a variety of methods for translating hostnames into IP addresses. The exact method varies depending on the version of Windows the client is running, how the client is configured (i.e., whether DNS server and/or WINS server IP addresses are provided), and whether the application software is accessing the network through Microsoft's Winsock or TCP/IP API. In general, Windows uses some combination of the following methods:
When a Windows system is configured with the IP address of at least one DNS server, it can use DNS to resolve fully qualified domain names, such as those for sites on the Internet. The DNS servers can be either Windows NT/2000 or Unix systems. You can learn more about DNS and DNS server configuration in the O'Reilly book DNS and BIND.
WINS Clients and Server Interaction
There are two types of interaction between a WINS client and a server: the client keeps its own NetBIOS name[1] registered with the server and queries the server to get the IP address corresponding to the NetBIOS name of another system.
When a WINS client joins the network, it registers its NetBIOS name with the WINS server, which stores it along with the client's IP address in the WINS database. This entry is marked active. The client is then expected to renew the registration of its name periodically (typically, every four days) to inform the server that it is still using the name. This period is called the time to live, or TTL. When the client leaves the network by being shut down gracefully, it informs the server, and the server marks the client's entry in its database as released.
When a client leaves the network without telling the WINS server to release its name, the server waits until after it fails to receive the expected registration renewal from the client and then marks the entry as released.
In either case, the released name is available for use by other clients joining the network. It might persist in the released state in the WINS database, and if it is not reregistered, the entry will eventually be deleted.
More information on WINS can be found in the Microsoft white paper Windows Internet Naming Service (WINS) Architecture and Capacity Planning. It can be downloaded from the Microsoft web site at http://www.microsoft.com.
The lmhosts File
In Chapter 3 we showed you how to configure Windows systems to use the LMHOSTS file as an alternative to the WINS server for name resolution. Samba also can use an LMHOSTS file, which by default is /usr/local/samba/lib/lmhosts. Samba's lmhosts is the same format as the Windows version. A simple lmhosts file might look like this:
172.16.1.1 toltec 172.16.1.6 maya
172.16.1.1 toltec#20 172.16.1.1 metran#1b 172.16.1.6 maya#20
#nmbd -H /etc/samba/lmhosts -D
Configuring Name Resolution for the Samba Suite
Various daemons and tools in the Samba suite need to perform
name resolution. You can define the
order in which the programs try each name-resolution method through
the name
resolve
order
parameter, like
this:
[global] name resolve order = wins lmhosts hosts bcast
The string used to define the parameter can take up to four values:
Setting Up Samba as a WINS Server
You can set up Samba as a WINS server by setting the
wins
support
parameter in the configuration file, like this:
[global] wins support = yes
WARNING
Configuring a DNS proxy
A Samba WINS server can check with the system's DNS server if a requested host cannot be found in its WINS database. With a typical Linux system, for example, you can find the IP address of the DNS server by searching the /etc/resolv.conf file. In it, you might see an entry such as the following:
nameserver 127.0.0.1 nameserver 172.16.1.192
Now it is a simple matter of using the
dns
proxy
option to tell
Samba to use the DNS server:
[global] dns proxy = yes
TIP
Setting Up Samba to Use Another WINS Server
You can configure Samba to use a WINS server somewhere else on the
network by simply providing it with the IP address of the WINS
server. This is done with the global
wins
server
configuration option, as shown here:
[global] wins server = 172.16.1.1
Configuring a WINS proxy
If you have a Samba server on a
subnet that doesn't have a WINS server, and the
Samba server has been configured with a WINS server on another
subnet, you can tell the Samba server to forward any name-resolution
requests with the wins
proxy
option:
[global] wins server = 172.16.200.12 wins proxy = yes
Name-Resolution Configuration Options
Samba's name-resolution options are shown in Table 7-1.
Table 7-1. Name-resolution options
Option |
Parameters |
Function |
Default |
Scope |
---|---|---|---|---|
|
boolean |
If set to |
|
Global |
|
string (IP address or DNS name) |
Identifies a WINS server for Samba to use for name registration and resolution |
None |
Global |
|
boolean |
Allows Samba to act as a proxy to a WINS server on another subnet |
|
Global |
|
string |
Command to run when the WINS database changes |
None |
Global |
|
boolean |
If set to |
|
Global |
|
string |
The order of methods used to resolve NetBIOS names |
|
Global |
|
numeric |
Maximum TTL in seconds for a requested NetBIOS name |
|
Global |
|
numeric |
Maximum TTL in seconds for NetBIOS names given out by Samba as a WINS server |
|
Global |
|
numeric |
Minimum TTL in seconds for NetBIOS names given out by Samba as a WINS server |
|
Global |
name resolve order
The global name
resolve
order
option specifies
the order of services that Samba will use in performing name
resolution. The default order is to use the
lmhosts file, followed by standard Unix
name-resolution methods (some combination of
/etc/hosts, DNS, and NIS), then to query a WINS
server, and finally to use broadcasting to determine the address of a
NetBIOS name. You can override this option by specifying something
like the following:
[global] name resolve order = lmhosts wins hosts bcast
This causes resolution to use the lmhosts file first, followed by a query to a WINS server, the /etc/hosts file, and finally broadcasting. You need not use all four options. This option is covered in more detail in Section 7.1.4, earlier in this chapter.
Browsing
Browsing in a Windows Network
The basic way browsing works is that one computer in the network takes on the role of the master browser (also called local master browser, browse master, or browse server) and keeps a list of all the computers on the local subnet that are acting as SMB servers. The list of computers is called the browse list and includes all Samba servers, Windows NT/2000/XP systems, and any Windows 95/98/Me systems that have the "File and printer sharing for Microsoft Networks" networking component installed. The browse list also contains the names of all workgroups and domains. At this level, browsing is limited to the local subnet because the browsing protocol depends on broadcast packets, which are typically not forwarded to other subnets by routers.
A user at any Windows system can view the browse list by opening up the Network Neighborhood (or My Network Places), as we showed you in Chapter 1. Or, the net view command can be used from a Windows command prompt:
C:\>net view
Server Name Remark ------------------------------------------------------------------------------- \\MAYA Windows 98 \\MIXTEC Samba 2.2.5 \\OLMEC Windows XP Pro on Pentium/ASUS \\TOLTEC Samba 2.2.5 \\YAQUI Windows 95 on mixtec/VMware \\ZAPOTEC The command completed successfully.
C:\>net view \\maya
Shared resources at \\maya Windows 98 Share name Type Used as Comment ------------------------------------------------------------------------------- D Disk E Disk HP Print The command completed successfully.
There can be more than one backup browser. A workgroup will have a backup browser if two or more computers are running Windows 95/98/Me or Windows NT Workstation (or another nonserver version of Windows NT/2000/XP) on the subnet. For every 32 additional computers, another backup browser is added.
In a Windows NT domain, the primary domain controller is always the local master browser, and if it fails, another Windows NT/2000 server (if one exists) will take over the role of local master browser. Other versions of Windows can function as backup browsers, but will never become a master browser if a Windows NT/2000 server is available.
In addition to acting as the local master browser, the primary domain
controller also acts as the domain master
browser, which ties subnets together and allows
browse lists to be shared between master and backup browsers on
separate subnets. This is how browsing is extended to function beyond
the local subnet. Each subnet functions as a separate browsing
entity, and the domain master browser synchronizes the master
browsers of each subnet. In a Windows-only network, browsing cannot
function across subnets unless a Windows NT/2000 PDC exists on the
network. Samba can act as a domain master browser and can perform
that task even in a workgroup network, which means that the Windows
PDC is not required for this task. (It is also possible to use the
remote
browse
sync
parameter to configure a Samba server to
synchronize its browse list with a Samba server on another subnet. In
this case, each server must be acting as the local master browser of
its subnet.)
Browser Elections
A potential browser's qualifications include the following:
If the potential browser has lost an election recently, it immediately disqualifies itself. The version of the election protocol it is running is checked, but so far, all Windows systems (and Samba) use the same election protocol, so the check is not very meaningful. The election criteria are usually what determine which computer becomes the local master browser. There are two parts to the election criteria, shown in Tables Table 7-2 and Table 7-3.
Table 7-2. Operating-system values in an election
Operating system |
Value |
---|---|
Windows NT/2000 Server, running as PDC |
32 |
Windows NT/2000/XP, if not the PDC |
16 |
Windows 95/98/Me |
1 |
Windows for Workgroups |
1 |
Table 7-3. Computer-role settings in an election
Role |
Value |
---|---|
Domain master browser |
128 |
WINS client |
32 |
Preferred master |
8 |
Running master |
4 |
Recent backup browser |
2 |
Backup browser |
1 |
When an operating-system type comparison results in a tie, the role of the computer is compared. A computer can have more than one of the values in Table 7-3, in which case the values are added.
A domain master browser has a role value of 128 to weight the election so heavily in its favor that it will also become the local master browser on its own subnet. Although the primary domain controller (which is always the domain master browser) will win the election based solely on its operating system value, sometimes there is no primary domain controller on the network, and the domain master browser would not otherwise be distinguished from other potential browsers.
Systems that are using a WINS server for name resolution are weighted heavily over ones that use broadcast name resolution with a role value of 32.
A preferred master is a computer that has been selected and configured manually by a system administrator to be favored as the choice master browser. When a preferred master starts up, it forces a browser election, even if an existing master browser is still active. A preferred master has a role value of 8, and the existing master browser gets a value of 4.
A backup browser that has recently been a master browser and still has an up-to-date browse list is given a role value of 2, and a potential browser that has been running as a backup browser gets a value of 1.
If comparing the operating-system type and role results in a tie, the computer that has been running the longest wins. In the unlikely event that the two have been up for the same amount of time, the computer that wins is the one with the NetBIOS name that sorts first alphabetically.
You can tell if a machine is a local master browser by using the Windows nbtstat command. Place the NetBIOS name of the machine you wish to check after the -a option:
C:\>nbtstat -a toltec
Local Area Connection: Node IpAddress: [172.16.1.4] Scope Id: [] NetBIOS Remote Machine Name Table Name Type Status --------------------------------------------- TOLTEC <00> UNIQUE Registered TOLTEC <03> UNIQUE Registered TOLTEC <20> UNIQUE Registered ..__MSBROWSE__.<01> GROUP Registered METRAN <00> GROUP Registered METRAN <1B> UNIQUE Registered METRAN <1C> GROUP Registered METRAN <1D> UNIQUE Registered METRAN <1E> GROUP Registered MAC Address = 00-00-00-00-00-00
The resource entry that you're looking for is
.._ _MSBROWSE_ _.<01>
. This indicates
that the server is currently acting as the local master browser for
the current subnet. If the machine is a Samba server, you can check
the Samba nmbd log file for an entry such as:
nmbd/nmbd_become_lmb.c:become_local_master_stage2(406) ***** Samba name server TOLTEC is now a local master browser for workgroup METRAN on subnet 172.16.1.0
Or, you can use the nmblookup command with the -M option and the workgroup or domain name on any Samba server to find the IP address of the local master:
$nmblookup -M metran
querying metran on 172.16.1.255 172.16.1.1 metran<1d>
Server Announcements
For more detailed information on Microsoft's browsing protocols, consult the Microsoft documents Browsing and Windows 95 Networking and CIFS/E Browser Protocol. You can find these by searching for the titles on the Microsoft web site at http://www.microsoft.com.
More information on configuring Samba for browsing can be found in BROWSING.txt and BROWSING-Config.txt in the Samba distribution's docs/textdocs directory.
Configuring Samba for Browsing
Samba has full support for browsing and can participate as a master browser, a backup browser, a domain master browser, a potential browser, or just a server that doesn't participate in browsing elections. If you want to make sure your Samba server never becomes a master or backup browser, simply set:
[global] local master = no
Usually, you will want Samba to be available as a local master or at
least a backup browser. In the simplest case, you
don't need to do anything because
Samba's default is to participate in browsing
elections with its operating system value set to 20, which will beat
any Windows system less than a Windows NT/2000 primary domain
controller (see Table 7-2). The operating-system
value Samba reports for itself in browser elections can be set using
the os
level
parameter:
[global] os level = 33
[global] os level = 8
[global] local master = yes os level = 255 preferred master = yes
The addition of the
preferred
master
parameter causes Samba to start a browser
election as soon as it starts up, and the os
level
of 255 allows it to beat any other system on
the network. This includes other Samba servers, assuming they are
configured properly! If another server is using a similar
configuration file (with os
level
=
255
and preferred
master
=
yes
), the two will fight each
other for the master browser role, winning elections based on minor
criteria, such as uptime or their current role. To avoid this, other
Samba servers should be set with a lower os
level
and not configured to be the preferred
master.
Samba as the Domain Master Browser
[global] domain master = yes preferred master = yes local master = yes os level = 255
The final three parameters ensure that the server is also the local master browser, which is vital for it to work properly as the domain master browser. You can verify that a Samba machine is in fact the domain master browser by checking the nmbd log file:
nmbd/nmbd_become_dmb.c:become_domain_master_stage2(118) ***** Samba name server TOLTEC is now a domain master browser for workgroup METRAN on subnet 172.16.1.0
Or you can use the nmblookup command that comes with the Samba distribution to query for a unique <1B> resource type in the workgroup:
#nmblookup METRAN#1B
Sending queries to 172.16.1.255 172.16.1.1 METRAN<1b>