jcifs_1.3.3.docs.resolver.html Maven / Gradle / Ivy
Go to download
JCIFS is an Open Source client library that implements the CIFS/SMB networking protocol in 100% Java
Setting Name Resolution Properties
Server names can be resolved using NetBIOS broadcast queries, WINS queries, lmhosts files, or DNS. The individual methods as well as the order in which they will be used can be set using the jcifs.resolveOrder
property. Several other properties are important to how server names are resolved and are discussed below.
Name Resolution Properties
jcifs.netbios.wins
The IP address of the WINS server(or more formally NBNS). This is only required when accessing hosts on different subnets although it is recomended if a WINS server is being used.
jcifs.netbios.baddr
The local network's broadcast address. It may be necessary to set this for certain network configurations because the default of 255.255.255.255 may otherwise throw a "Network is unreachable" IOException
. For example if the local host's IP address is 192.168.1.15, the broadcast address would likely be 192.168.1.255.
jcifs.resolveOrder
A comma separated list of name resolution method identifiers that specify which methods will be used and in what order to resolve hostnames. The possible identifiers are LMHOSTS
, WINS
, BCAST
, and DNS
.
jcifs.netbios.lmhosts
The path to an lmhosts file containing a map of IP addresses to hostnames. The format of this file is identical to that of the Windows lmhosts file format with a few exceptions noted below.
jcifs.netbios.scope
This is rare but NetBIOS provides for a "scope id" to be used in a attempt to conceal groups of machines on the same network. Ask your network administrator if scope id is used. If so, it must be set using this property or name queries will fail.
The resolveOrder Property
The resolveOrder
property specifies a comma separated list of name resolution methods to use as well as the order in which they should be used. The method names are LMHOSTS
, WINS
, BCAST
, and DNS
. The default order is:
resolveOrder=LMHOSTS,WINS,DNS,BCAST
or if the jcifs.netbios.wins
property is not defined the default will be just
resolveOrder=LMHOSTS,DNS,BCAST
Note: The above defaults were changed in 1.3.3 from LMHOSTS,WINS,BCAST,DNS
and LMHOSTS,BCAST,DNS
respectively. Meaning BCAST
was moved to after DNS
.
Both the UniAddress and NbtAddress classes honor the jcifs.resolveOrder property but the UniAddress class is used almost exclusively by jCIFS internally whereas the NbtAddress class will ignore the "DNS" token.
The DNS
method uses java.net.InetAddress.getByName()
. So the operating systems default name resolution mechanism is responsible for resolving DNS names(i.e. if you wish to specify a DNS server you must modify the DNS configuration of the system on which jCIFS will be running). To resolve a server name, each method is queried in order. If at any point the name is successfully resolved no further methods are queried.
As an example:
resolveOrder=DNS,BCAST
This would result in DNS being queried first. If the DNS query fails, a NetBIOS name query will be broadcast on 255.255.255.255 or the address specified by the jcifs.netbios.baddr property. Should this broadcast query fail, an UnknownHostException
will result. The lmhosts file and WINS methods will not be attempted regardless of whether or not the jcifs.netbios.lmhosts
or jcifs.netbios.wins
properties are set.
It is noteworthy that failed BCAST
queries take 6 seconds to timeout (by default retryTimeout
is 3000 and retryCount
is 2). Therefore it is advantageous to specify a resolveOrder
of:
resolveOrder=LMHOSTS,WINS,DNS
without the BCAST
method if it is expected that all hosts should be resolved by WINS or DNS. This is much faster if queries are anticipated to occasionally fail (e.g. an SMB crawler program will run much faster without BCAST
).
The lmhosts Property
The optional lmhosts
property specifies the path to an lmhosts file. This file should contain IP address to server name mappings. When the LMHOSTS
name resolution method is queried, these entries will be consulted. Generally lmhosts files are used to allow access to hosts on different networks if a WINS server is not provided. It is analogous to the /etc/hosts
file on a UNIX system.
The format of this file is identical to that of the Microsoft Windows lmhosts file. A simple lmhosts file might look like:
# This is a comment
192.168.1.15 nano
192.168.1.16 angus
Where each entry is just an IP address followed by the server name for that host. A more sophisticated example might look like:
# This is a comment
150.34.26.16 freto #PRE
#INCLUDE \\FRETO\TEMP\nlmhosts
192.168.1.15 nano
The #PRE
tag is ignored by jCIFS because they are not necessary. It indicates that a name should be pre-loaded into the server lookup table. However because jCIFS provides for specifying a resolveOrder
where an lmhosts file might be queried after a different method it is not desirable to explicitly populate the lookup table. Entries are loaded as they are encountered in the file however so names are effectively always pre-loaded.
The #INCLUDE
tag is not ignored by jCIFS. Where encountered, jCIFS will retrieve the file associated with this UNC name and parse it's contents as if the file were included at that location.
#DOM
tags are ignored but the #BEGIN_ALTERNATE
/ #END_ALTERNATE
blocks are fully supported. The only incompatability with the Windows lmhosts file format is that quoted strings and \0xnn
non-printable escape characters are not supported.
The format for this file was chosen to be compatible with the Windows lmhosts file because it is conceivable that an existing system or network lmhosts file might be used. To use a systems existing lmhosts file one might set the jcifs.netbios.lmhosts
property to point to the system lmhosts file for Windows NT with:
lmhosts=C:\WINNT\system32\drivers\etc\lmhosts
or on other Windows systems with perhaps:
lmhosts=C:\WINDOWS\lmhosts
To read a network lmhosts file, set the jcifs.netbios.lmhosts
property like:
lmhosts=conf/mylmhosts
and create that file with contents such as:
# Address of server hosting network lmhosts file
192.168.1.16 freto
#INCLUDE \\freto\netcfg\nlmhosts
Ask your network administrator if lmhosts files are used and if you should use one in the context of your application.
Note: It so happens that DNS names may be specified in a jCIFS lmhosts file. But DNS names are not valid if the lmhosts file is to be read by Windows systems.
Last updated Jan 23, 2009
jcifs-1.3.3
Copyright © 2004 The JCIFS Project
validate this page
© 2015 - 2025 Weber Informatics LLC | Privacy Policy