Managing NFS and NIS, 2nd Edition - Mike Eisler [192]
131.40.52.54 hannah
131.40.52.132 positive
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:
By default, only the value paired with the key in the map is displayed, and not the key itself. Some maps retain the key as part of the data value because it is needed by applications that retrieve the map entry. Library routines that locate a password file entry based on UID, for example, return the user's login name as part of the password file structure. Other maps such as aliases simply store the value associated with the key, when applications (such as mail) that reference the NIS map already have the key value. The following excerpt from ypcat aliases is of little value because there are no alias names associated with the alias expansions:% ypcat aliases
dan, lauri, paul, harry, bob
dave, michael
michael, jan, stewart, tom
Both ypcat and ypmatch use the -k option to print the data value with its associated key:% ypcat -k aliases
south-sales dan, lauri, paul, harry, bob
engin-managers dave, michael
north-engin michael, jan, stewart, tom
Some maps do not associate a data value with a key. The most common map of this variety is the ypservers map, which simply contains hostnames of NIS servers without any additional information. When using ypcat or ypmatch with value-less maps, blank lines are produced as output:% ypcat ypservers
unless the -k option is specified:% ypcat -k ypservers
>mahimahi
wahoo
thud
An NIS server implements separate procedures to get the "first" and each successive key in a map. ypcat uses the "get first key" and "get next key" procedures to locate the first key in the DBM file and to walk through all keys. The ordering of the keys is determined by a linear scan through the DBM index file, rather than the order in which the records appear in the plain text file. Because keys are encountered in the order in which they are hash chained together, ypcat produces a seemingly random ordering of the keys. In the hosts file example earlier, the original /etc/inet/hosts file was sorted by increasing host number in the IP addresses; but the process of hashing the keys into the DBM file produced the ordering seen with ypcat.
As a diagnostic tool, ypmatch can be used to identify NIS maps that are out of synchronization even after a map transfer has been requested or scheduled. It is often used to see if a change has taken place. After a new map is built, it is generally pushed to other servers using yppush. However, NIS map changes may not propagate as quickly as desired. A slave server may be down when a map transfer occurs, in which case it will not get an updated map until the next ypxfr transfer.
Displaying and analyzing client bindings
ypwhich provides information about a client's NIS domain binding, and the availability of master servers for various maps in the domain. With no arguments, it returns the name of the NIS server to which the client is currently bound by ypbind:
% ypwhich
mahimahi
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 gonzo
ypwhich: clnt_create error: RPC: Unknown host
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 131.40.52.34
wahoo
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