ypwhich

networkingLinux/Unix
The ypwhich command is one of the most frequently used commands in Linux/Unix-like operating systems. ypwhich Return hostname of NIS server or map master

Quick Reference

Command Name:

ypwhich

Category:

networking

Platform:

Linux/Unix

Basic Usage:

ypwhich [options] [arguments]

Common Use Cases

    Syntax

    ypwhich [options] [host]
    ypwhich [-m [mapname]]

    Options

    Option Description
    -d domain Specify domain other than the default domain
    -m [mapname] Find the master NIS server for a map. If no map is specified, displays all available maps and their master servers
    -t Inhibit map nickname translation
    -V Display version number
    -x Display the map nickname translation table

    Common Map Names

    Map Name Description
    passwd User account information (nickname for passwd.byname)
    group Group information (nickname for group.byname)
    hosts Host name to IP address mappings (nickname for hosts.byname)
    passwd.byname User account information indexed by username
    passwd.byuid User account information indexed by UID
    group.byname Group information indexed by group name
    group.bygid Group information indexed by GID
    hosts.byname Host information indexed by hostname
    hosts.byaddr Host information indexed by IP address

    Examples

    How to Use These Examples

    The examples below show common ways to use the ypwhich command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    Basic Examples:

    Show which NIS server the local host is bound to
    ypwhich
    Show which NIS server another host is bound to
    ypwhich otherhost
    List all available maps
    ypwhich -x

    Advanced Examples:

    Show which server is the master for a specific map
    ypwhich -m passwd
    Show all map/server pairs
    ypwhich -m
    Show which server is the master for a map in a specific domain
    ypwhich -d mydomain -m passwd
    Check if a host is running as an NIS server
    rpcinfo -p hostname | grep ypserv
    Verify full NIS configuration
    ypwhich && ypcat -k passwd | head -1

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The `ypwhich` command is a Network Information Service (NIS) client utility used to identify which NIS server a client is currently bound to or to find the master server for a specific NIS map. It's a crucial diagnostic and information tool for administrators of NIS networks. **NIS Overview:** Network Information Service (NIS), formerly known as Yellow Pages (YP), is a client-server directory service protocol developed by Sun Microsystems. It allows multiple machines on a network to share common configuration files such as `/etc/passwd`, `/etc/group`, and `/etc/hosts` through a centralized database system. **Primary Functions of ypwhich:** 1. **Binding Identification**: When run without arguments, `ypwhich` displays the name of the NIS server to which the local machine is currently bound. 2. **Remote Host Binding**: When given a hostname argument, `ypwhich` reports which NIS server that remote host is bound to. 3. **Map Master Identification**: With the `-m` option, `ypwhich` identifies the master server for a specific map, or for all maps if no map is specified. 4. **Map Nickname Translation**: Using the `-x` option, `ypwhich` displays the map nickname translation table, showing the relationship between common map nicknames (like "passwd") and their actual map names (like "passwd.byname"). **NIS Architecture Understanding:** To fully appreciate the utility of `ypwhich`, it's important to understand some key aspects of NIS architecture: 1. **Client Binding**: NIS clients (via the `ypbind` daemon) establish connections to NIS servers, a process known as "binding." `ypwhich` reports these binding relationships. 2. **Master vs. Slave Servers**: An NIS domain typically has one master server (where updates occur) and potentially multiple slave servers (which replicate data from the master). The `-m` option of `ypwhich` is used to identify the master server for specific maps. 3. **Maps and Nicknames**: NIS organizes data into maps, which are essentially databases of key-value pairs. Many maps have common nicknames for ease of reference, and `ypwhich -x` shows these relationships. **Common Use Cases:** 1. **Troubleshooting NIS Connectivity**: System administrators use `ypwhich` to verify that clients are correctly binding to NIS servers. 2. **Verifying NIS Configuration**: The command helps confirm that the expected NIS server is being used by clients. 3. **Map Administration**: Before updating NIS maps, administrators use `ypwhich -m` to identify the master server where changes should be made. 4. **Domain Verification**: The output of `ypwhich` includes the NIS domain name, helping to verify domain configuration. 5. **Server Load Balancing**: In environments with multiple NIS servers, `ypwhich` can help monitor client distribution across servers. **Related NIS Components:** 1. **ypbind**: The client daemon responsible for finding and connecting to an NIS server. `ypwhich` essentially reports the results of `ypbind`'s server selection. 2. **ypserv**: The server daemon that provides NIS maps to clients. 3. **ypcat**: A command to display the contents of an NIS map. 4. **ypmatch**: A command to retrieve specific entries from an NIS map based on keys. 5. **yppoll**: A command to determine the version and master server of an NIS map. **Practical Examples and Scenarios:** 1. **Basic Connectivity Check**: Simply running `ypwhich` with no arguments tells you if your NIS client is successfully bound to a server, which is the first step in diagnosing NIS issues. 2. **Multi-Server Environment**: In environments with multiple NIS servers (master and slaves), `ypwhich` helps verify that clients are distributed appropriately across available servers. 3. **Map Update Workflow**: Before updating an NIS map, an administrator would use `ypwhich -m mapname` to identify where to make the change, then update the map on the master server, and finally run `yppush` to propagate the change to slave servers. 4. **Server Migration**: When migrating to a new NIS server, `ypwhich` is used to verify that clients are binding to the new server after the migration. **Security and Network Considerations:** 1. **Information Disclosure**: `ypwhich` reveals information about the NIS infrastructure, which could potentially be useful to attackers. Access should be appropriately restricted. 2. **Network Dependency**: Like all NIS operations, `ypwhich` depends on network connectivity to the NIS server. Network issues can affect its operation and results. 3. **Domain Security**: NIS domains have limited security mechanisms, and `ypwhich` results depend on the integrity of the NIS domain infrastructure. **Historical Context:** Like other NIS commands, `ypwhich` dates back to the early days of Unix networking when Sun Microsystems developed NIS (initially called Yellow Pages) to address the challenge of maintaining consistent configuration files across multiple systems. The "yp" prefix in the command name is a remnant of this original "Yellow Pages" name, which was changed due to trademark issues. While NIS is considered legacy technology today and has been largely superseded by more secure and feature-rich alternatives like LDAP, understanding tools like `ypwhich` remains important for administrators working in environments where NIS is still deployed. **Modern Alternatives:** 1. **LDAP Tools**: In environments using LDAP instead of NIS, commands like `ldapsearch` and various LDAP administrative tools serve similar purposes. 2. **DNS-based Service Discovery**: Modern networks often use DNS-based service discovery mechanisms rather than the broadcast/RPC mechanisms used by NIS. 3. **Configuration Management Systems**: Tools like Ansible, Puppet, or Chef often replace the configuration distribution functions of NIS in modern environments. In summary, `ypwhich` is a diagnostic and information tool for NIS networks, primarily used to identify NIS server bindings and map master servers. While its underlying technology (NIS) is largely considered legacy, the command remains useful in environments where NIS is still deployed for historical or compatibility reasons.

    Related Commands

    These commands are frequently used alongside ypwhich or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the ypwhich command works in different scenarios.

    $ ypwhich
    View All Commands
    Linux ypwhich Command - Identify NIS Server or Map Master