Softpanorama
May the source be with you, but remember the KISS principle ;-)

Contents Bulletin Scripting in shell and Perl Network troubleshooting History Humor

/etc/nsswitch.conf -- Name Service Switch File

The name service switch file determines which name services a system uses to search for information, and in which order the name services are searched. All Solaris  systems use the /etc/nsswitch.conf file as the name service switch file. The nsswitch.conf file is loaded with the contents of a template file during the installation of the Solaris, depending on the name service that is selected.

The /etc/nsswitch.conf file includes a list of databases that are sources of information about IP addresses, users, and groups. Data for these can come from a variety of sources. For example, host names and host addresses, are located in the /etc/hosts file, NIS, NIS+, LDAP, or DNS. Each database has zero or more sources; the sources and their lookup order are specified in the /etc/nsswitch.conf file.

Note: The default name service during installation of the Solaris 9  is the /etc/nsswitch.nisplus template that configures the name service for NIS+.

The following example is the /etc/nsswitch.conf file configured to support the NIS name service using the /etc/nsswitch.nis template.

# /etc/nsswitch.nis:
#
# An example file that could be copied over to /etc/nsswitch.conf; it
# uses NIS (YP) in conjunction with files.
#
# "hosts:" and "services:" in this file are used only if the
# /etc/netconfig file has a "-" for nametoaddr_libs of "inet" transports.
# the following two lines obviate the "+" entry in /etc/passwd and /etc/group.
passwd: files nis
group: files nis
# consult /etc "files" only if nis is down.
hosts: nis [NOTFOUND=return] files
ipnodes: files

... ... ...

There are five templates that are used during Solaris installation, or when you need to change name service:

  1. Local files   /etc/nsswitch.files
  2. DNS           /etc/nsswitch.dns
  3. NIS           /etc/nsswitch.nis
  4. NIS+          /etc/nsswitch.nisplus
  5. LDAP          /etc/nsswitch.ldap

Database Sources

There is an entry in the /etc/nsswitch.conf file for each database. Some typical examples of these entries are:

ipnodes: files
passwd: files nis
hosts: nis [NOTFOUND=return] files

There might be a single information source listed, in which case the search terminates if the information is not found. If two or more sources are listed, the first listed source is searched before moving on to the next listed source.

When multiple information sources are specified, it is sometimes necessary to define precisely the circumstances under which each source is searched. When a name service is referenced, the attempt to search this source can return one of the following status codes:

Actions

For each status code, two actions are possible. When the action is not explicitly specified, the default action is to continue the search using the next specified information source, as follows:

Examples:

  1. Example 1

    ipnodes: files

    In this example, the /etc/inet/ipnodes file is searched for the first entry that matches the requested host name. If no matches are found, an appropriate error is returned, and no further information sources are searched.

  2. Example 2: passwd: files nis

    In this example, the appropriate files in the /etc directory are searched for the corresponding password entry. If the entry is not found, the NIS maps are searched for the entry. If no entry is found in the NIS maps, an appropriate error is returned, and no further information sources are searched.

  3. Example 3:

    hosts: nis [NOTFOUND=return] files

    In this example, the NIS maps are searched for the entry. If the source (NIS) is not running, the system returns the status UNAVAIL, and continues to search the /etc/inet/hosts file. If the entry returns the status NOTFOUND, an appropriate error is returned, and the search is terminated without searching the /etc/inet/hosts file.

nsswitch.conf - System Databases and Name Service Switch configuration file

Various functions in the C Library need to be configured to work correctly in the local environment. Traditionally, this was done by using files (e.g., `/etc/passwd'), but other nameservices (like the Network Information Service (NIS) and the Domain Name Service (DNS)) became popular, and were hacked into the C library, usually with a fixed search order.

The Linux libc5 with NYS support and the GNU C Library 2.x (libc.so.6) contain a cleaner solution of this problem. It is designed after a method used by Sun Microsystems in the C library of Solaris 2. We follow their name and call this scheme "Name Service Switch" (NSS). The sources for the "databases" and their lookup order are specified in the /etc/nsswitch.conf file.

The following databases are available in the NSS:

aliases
Mail aliases, used by sendmail(8). Presently ignored.
ethers
Ethernet numbers.
group
Groups of users, used by getgrent(3) functions.
hosts
Host names and numbers, used by gethostbyname(3) and similar functions.
netgroup
Network wide list of hosts and users, used for access rules. C libraries before glibc 2.1 only support netgroups over NIS.
network
Network names and numbers, used by getnetent(3) functions.
passwd
User passwords, used by getpwent(3) functions.
protocols
Network protocols, used by getprotoent(3) functions.
publickey
Public and secret keys for Secure_RPC used by NFS and NIS+.
rpc
Remote procedure call names and numbers, used by getrpcbyname(3) and similar functions.
services
Network services, used by getservent(3) functions.
shadow
Shadow user passwords, used by getspnam(3).

An example /etc/nsswitch.conf (namely, the default used when /etc/nsswitch.conf is missing):

passwd:
compat
group:
compat
shadow:
compat
hosts:
dns [!UNAVAIL=return] files
networks:
nis [NOTFOUND=return] files
ethers:
nis [NOTFOUND=return] files
protocols:
nis [NOTFOUND=return] files
rpc:
nis [NOTFOUND=return] files
services:
nis [NOTFOUND=return] files

The first column is the database. The rest of the line specifies how the lookup process works. You can specify the way it works for each database individually.

The configuration specification for each database can contain two different items:

* The service specification like `files', `db', or `nis'.
* The reaction on lookup result like `[NOTFOUND=return]'.

For libc5 with NYS, the allowed service specifications are `files', `nis', and `nisplus'. For hosts, you could specify `dns' as extra service, for passwd and group `compat', but not for shadow.

For glibc, you must have a file called /lib/libnss_SERVICE.so.X for every SERVICE you are using. On a standard installation, you could use `files', `db', `nis', and `nisplus'. For hosts, you could specify `dns' as extra service, for passwd, group, and shadow `compat'. These services will not be used by libc5 with NYS. The version number X is 1 for glibc 2.0 and 2 for glibc 2.1.

The second item in the specification gives the user much finer control on the lookup process. Action items are placed between two service names and are written within brackets. The general form is

`[' ( `!'? STATUS `=' ACTION )+ `]'

where

STATUS => success | notfound | unavail | tryagain
ACTION => return | continue

The case of the keywords is insignificant. The STATUS values are the results of a call to a lookup function of a specific service. They mean:

success
No error occurred and the wanted entry is returned. The default action for this is `return'.
notfound
The lookup process works ok but the needed value was not found. The default action is `continue'.
unavail
The service is permanently unavailable. This can either mean the needed file is not available, or, for DNS, the server is not available or does not allow queries. The default action is `continue'.
tryagain
The service is temporarily unavailable. This could mean a file is locked or a server currently cannot accept more connections. The default action is `continue'.

Interaction with +/- syntax (compat mode)

Linux libc5 without NYS does not have the name service switch but does allow the user some policy control. In /etc/passwd you could have entries of the form +user or +@netgroup (include the specified user from the NIS passwd map), -user or -@netgroup (exclude the specified user), and + (include every user, except the excluded ones, from the NIS passwd map). Since most people only put a + at the end of /etc/passwd to include everything from NIS, the switch provides a faster alternative for this case (`passwd: files nis') which doesn't require the single + entry in /etc/passwd, /etc/group, and /etc/shadow. If this is not sufficient, the NSS `compat' service provides full +/- semantics. By default, the source is `nis', but this may be overriden by specifying `nisplus' as source for the pseudo-databases passwd_compat, group_compat and shadow_compat. This pseudo-databases are only available in GNU C Library.  

A service named SERVICE is implemented by a shared object library named libnss_SERVICE.so.X that resides in /lib.

/etc/nsswitch.conf configuration file
/lib/libnss_compat.so.X
implements `compat' source for glibc2
/lib/libnss_db.so.X
implements `db' source for glibc2
/lib/libnss_dns.so.X
implements `dns' source for glibc2
/lib/libnss_files.so.X
implements `files' source for glibc2
/lib/libnss_hesiod.so.X
implements `hesiod' source for glibc2
/lib/libnss_nis.so.X
implements `nis' source for glibc2
/lib/libnss_nisplus.so.2
implements `nisplus' source for glibc 2.1

 

NOTES

Within each process that uses nsswitch.conf, the entire file is read only once; if the file is later changed, the process will continue using the old configuration.

With Solaris, it isn't possible to link programs using the NSS Service statically. With Linux, this is no problem.

Etc

Most popular humor pages:

Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg  : C++ Humor : ARE YOU A BBS ADDICT? : Object oriented programmers of all nationsC Humor : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humorPseudoScience Related Humor : Networking Humor  : Shell Humor: Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : The Most Comprehensive Collection of Editor-related Humor : Microsoft plans to buy Catholic Church : Education Humor : IBM HumorAssembler-related HumorVIM Humor Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor : Best Russian Programmer Humor : Russian Musical Humor : The Perl Purity TestPolitically Incorrect Humor : GPL-related Humor : OFM Humor : IDS Humor : Real Programmers Humor : Scripting Humor : Web Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor :

The Last but not Least


Copyright © 1996-2013 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License. Site uses AdSense so you need to be aware of Google privacy policy. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine. This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...

You can use PayPal to make a contribution, supporting hosting of this site with different providers to distribute and speed up access. Currently there are two functional mirrors: softpanorama.info (the fastest) and softpanorama.net.

Disclaimer:

The statements, views and opinions presented on this web page are those of the author and are not endorsed by, nor do they necessarily reflect, the opinions of the author present and former employers, SDNP or any other organization the author may be associated with. We do not warrant the correctness of the information provided or its fitness for any purpose.

Last modified: August 12, 2009