Using the Solaris getent command
As a system administrator, you can query name service information sources with tools, such as the ypcat
, nslookup
, niscat
, and ldaplist
commands.
You can use the ypcat command to query the NIS namespace. You can use the nslookup command to query the DNS namespace. However, when trying to isolate a problem, using one of these tools can return different results than standard system search operations, because the nsswitch.conf file is not referenced by these commands.
The getent command has these advantages:
- The primary advantage is that the command searches the information sources in the order in which they are configured in the name service switch file.
- A secondary advantage is that by using the name service switch file, the defined status message codes and actions are tested as they are currently configured. Therefore, if a return action is improperly placed in the name service switch file, the getent command will find the problem, whereas the specific commands used to test the name service information sources (such as ypcat or nslookup) will not find the problem because they directly use the name service database without referencing the nsswitch.conf file.
Using the getent
command
The getent
command retrieves a list of entries from the administrative database specified by database. The sources for the database are specified in the /etc/nsswitch.conf file. The syntax is:
getent database [key]...
where:
- database — The name of the database to be examined. This name can be passwd, group, hosts, ip nodes, services, protocols, ethers, networks, or netmasks.
- key — A value that corresponds to an entry in a database. The key must be in a format appropriate for searching on the respective database. For example, it can be a username or numeric user ID (UID) for passwd, or a host name or IP address for hosts.
Search files
before nis
In the following examples, the /etc/nsswitch.conf
file is configured to search files
and then to search nis
:
# getent passwd user1 user1:x:1002:10:Dummy User 1:/export/home/user1:/usr/bin/ksh # getent group 10 staff::10: # getent hosts church1e 10.1.1.22 church1e loghost
Search nis
before local files
# grep "^hosts:" /etc/nsswitch.conf hosts: nisplus [NOTFOUND=return] files
Since the /etc/nsswitch.conf
file is configured to search NIS and then to search files, the output of the final search would be:
# getent hosts church1e 10.1.1.22 church1e
You will notice that the entry loghost
is missing in this output. The loghost
is an alias entry in the /etc/inet/hosts
file for church1e
but not in the NIS map. Therefore, when the /etc/nsswitch.conf
file search order is altered, the getent
command looks up the entry in the NIS map before consulting the /etc/inet/hosts
file.