This procedure differs from using grep on the ASCII source file that produced the map in two ways:% ypmatch help-request aliases john.goodman % ypmatch onaga hosts 131.40.52.27 onaga
NIS maps are stored as DBM databases, indexed files with fast access provided through a hash table. Standard utilities such as grep do not produce meaningful results when used on DBM data files. To peek into the contents of an NIS map, you must use ypmatch or ypcat. Output from NIS tools is colored by the underlying DBM index file organization, and presents several avenues of confusion:% ypcat hosts 131.40.52.121 vineyard 131.40.52.54 hannah 131.40.52.132 positive
Both ypcat and ypmatch use the -k option to print the data value with its associated key:% ypcat aliases dan, lauri, paul, harry, bob dave, michael michael, jan, stewart, tom
% ypcat -k aliases south-sales dan, lauri, paul, harry, bob engin-managers dave, michael north-engin michael, jan, stewart, tom
unless the -k option is specified:% ypcat ypservers
% ypcat -k ypservers >mahimahi wahoo thud
If a hostname is passed as a parameter, then ypwhich queries the named host for its current binding. If ypwhich cannot resolve the hostname into an IP address, it reports an error:% ypwhich mahimahi
An IP address may be used in place of a hostname if you are debugging NIS problems, since NIS itself is used to map the hostname into an IP address. If NIS operation is not reliable, then explicit IP addresses should be used with all of the NIS-oriented debugging tools. For example:% ypwhich gonzo ypwhich: clnt_create error: RPC: Unknown host
Querying client bindings individually is useful for debugging client problems, but it doesn't provide much useful information about the use of NIS on the network. ypwhich is better suited for answering questions about NIS servers: Are there enough servers? Are the clients evenly distributed among the NIS servers? There is no client binding information kept by an NIS server -- the binding is something created by the client and known only to the client. The server simply answers requests that are sent to it. To determine the distribution of NIS clients to servers, you must poll the clients. ypwhich, embedded in a shell script, collects NIS client demographics to perform a "census" of server usage:% ypwhich 131.40.52.34 wahoo
The for expression dumps the hosts NIS file, and awk extracts the second field -- the hostname -- from each entry. The loop then queries each host for its NIS server, and then the output from the loop is sorted. The entire loop is executed in a subshell so that its output is treated as a single stream by the next stage of the command pipeline. The grep command filters out errors from ypwhich, produced when an NIS client has not found a server for its domain. At the end of the pipe, uniq -c counts the occurrences of each line, producing the census of NIS servers. Sample output from the script is:#! /bin/sh # ypcensus - poll for ypservers ( for h in `ypcat hosts | awk '{print $2}'` do ypwhich $h done ) | grep -v 'not running' | sort | uniq -c
You may find that the total number of bindings recorded is less than the number of clients -- some clients may not have formed a server binding when the script was run. Executing ypwhich causes the client to bind to a server, so if you "miss" some hosts on the first attempt, execute the script again after all clients have been forced to find servers. What does the output indicate? With multiple NIS servers, it is possible for the client distribution to load one server more heavily than the others. In the previous example, the large number of clients bound to server onaga could be caused by several things:% ypcensus 26 onaga 7 mahimahi 8 thud
ypbind sends its RPC broadcast to the portmapper on the sunrpc port (port 111), and the portmapper calls the ypserv process indirectly. If you see a large number of broadcast calls being made to the portmapper, then your NIS clients are rebinding frequently and you should add more NIS servers or choose servers that have a lighter load.# snoop broadcast port sunrpc aqua -> 131.40.52.255 NIS C DOMAIN_NONACK mydomain.com semaphore -> 131.40.52.255 NIS C DOMAIN_NONACK mydomain.com
While map nicknames provide a shorter command-line option for tools that take a map name as a parameter, they can also create name conflicts with non-standard maps that share commonly used map names. For example, a daemon that maps popular internal resource server names to IP ports might create an NIS map called services advertising its default mappings. This map name will not conflict with the NIS map created from /etc/inet/services because the latter is converted into the map services.byname. Users of ypcat and ypmatch may be surprised by output that appears to confuse the map names. The following example doesn't work at first because the ypmatch utility turns the map name services into services.byname, using the standard nickname translation. NIS completely ignores the map you want. If you use ypmatch -t, nickname translation is suppressed and you locate the desired map:% ypwhich -x Use "passwd" for map "passwd.byname" Use "group" for map "group.byname" Use "networks" for map "networks.byaddr" Use "hosts" for map "hosts.byname" Use "protocols" for map "protocols.bynumber" Use "services" for map "services.byname" Use "aliases" for map "mail.aliases" Use "ethers" for map "ethers.byname" Use "ipnodes" for map "ipnodes.byname" Use "project" for map "project.byname"
If you create your own maps, it's best to pick names that do not conflict with the standard map nicknames. Finally, ypwhich finds the master server for a map, or prints the list of all known maps if passed the -m option:% ypmatch cullinet services Can't match key cullinet in map services.byname. Reason: no such key in map. % ypmatch -t cullinet services cullinet 6667
ypwhich -m examines the NIS master server name embedded in the NIS map DBM file. You can also explode an NIS map using makedbm -u, which "undoes" a DBM file. You see the data records as well as the two additional records added by DBM containing the NIS master name and the map's timestamp. If you have concerns about data disappearing from NIS maps, dump the entire map (including keys) using makedbm -u:% ypwhich -m passwd mahimahi % ypwhich -m excerpt follows protocols.byname mahimahi passwd.byuid mahimahi passwd.byname mahimahi hosts.byname mahimahi rpc.bynumber mahimahi group.bygid mahimahi netmasks.byaddr mahimahi hosts.byaddr mahimahi netgroup mahimahi group.byname mahimahi mail.aliases mahimahi services.byname mahimahi netgroup.byhost mahimahi protocols.bynumber mahimahi ethers.byname mahimahi bootparams mahimahi ypservers mahimahi
The map master information is useful if you have changed NIS master servers and need to verify that client maps are built correctly and synchronized with the new master server.[wahoo]% cd /var/yp/nesales [wahoo]% /usr/etc/yp/makedbm -u ypservers YP_LAST_MODIFIED 0649548751 YP_MASTER_NAME wahoo wahoo wahoo redsox redsox thud thud
Make sure to include the necessary hostname to IP address mappings in /etc/inet/ipnodes or /etc/inet/hosts before running the ypinit command, otherwise ypinit will fail. The resulting ypservers file:# ypinit -c In order for NIS to operate sucessfully, we have to construct a list of the NIS servers. Please continue to add the names for YP servers in order of preference, one per line. When you are done with the list, type a <control D> or a return on a line by itself. next host to add: onaga next host to add: mahimahi next host to add: 131.40.52.126 next host to add: ^D The current list of yp servers looks like this: onaga mahimahi 131.40.52.126 Is this correct? [y/n: y] y
Note that it is not necessary to preconfigure an initial list of NIS servers, since ypbind will broadcast a request on the network to find the available servers if the initial list does not exist. ypbind is started by /usr/lib/netsvc/yp/ypstart which in turn is invoked by the /etc/init.d/rpc startup script:% cat ypservers onaga mahimahi 131.40.52.126
The next section will explain in more detail when and why you may want to bind to specific NIS servers, and how you can modify the binding once ypbind has been started.Excerpt from /usr/lib/netsvc/yp/ypstart: if [ -d /var/yp/binding/$domain -a -f /var/yp/binding/$domain/ypservers ]; then /usr/lib/netsvc/yp/ypbind > /dev/null 2>&1 echo " ypbind\c" elif [ -d /var/yp/binding/$domain ]; then /usr/lib/netsvc/yp/ypbind -broadcast > /dev/null 2>&1 echo " ypbind\c" fi
Alternatively, you can verify that the /etc/inet/ipnodes or /etc/inet/hosts file lists the IP address for the new NIS server, and that /etc/nsswitch.conf is configured to use files before it uses NIS. In some NIS implementations (Solaris and others), ypbind no longer allows ypset to change its binding unless this functionality is explicitly enabled. If the -ypset option is used when ypbind is started, then ypbind accepts requests from any remote machine to rebind to a specified server:# ypset 131.40.52.28 # ypwhich mahimahi
The use of -ypset is a security risk as it allows a third party to change the binding to a potentially hostile server. Without the -ypset parameter, attempts to change the server binding will fail:ypbind -ypset
A more restrictive form is:wahoo# ypset thud ypset: Sorry, ypbind on host localhost has rejected your request.
which only allows root on the local machine to invoke ypset to alter the binding. To discourage manually changing the binding, the startup script does not specify either of these options when it invokes ypbind.ypbind -ypsetme
13.3. Remote procedure call tools | 13.5. Network analyzers |
Copyright © 2002 O'Reilly & Associates. All rights reserved.