NIS Client Networking  «Prev  Next»
Lesson 4/etc/nsswitch.conf
ObjectiveDescribe the Function and Purpose of nsswitch.conf

Function and Purpose of nsswitch.conf

The Network Services switch file /etc/nsswitch.conf determines the order of look-ups performed when a certain piece of information is requested.
You can choose the order of the look-ups. For example, you can configure Linux to resolve hostnames by first checking local files, then NIS, and finally DNS. Other information maps hold user and password information.

What is the purpose of the nsswitch.conf file in Red Hat Linux

The nsswitch.conf file in Red Hat Linux is a configuration file that determines the order in which various databases and services are consulted when looking up information about users, groups, hosts, and other system entities.
The "nss" in nsswitch stands for "Name Service Switch", which is a system that allows different sources of system information to be combined into a single interface. The nsswitch.conf file specifies which sources of information should be used first, second, and so on, until the requested information is found.
For example, if a user tries to log in to a Red Hat Linux system, the system will consult the nsswitch.conf file to determine the order in which it should look up the user's name and password. By default, the file specifies that the system should first check the local files (e.g. /etc/passwd) and then the LDAP directory service.
The nsswitch.conf file can be modified to change the order in which databases and services are consulted or to add new sources of information. This can be useful in a variety of scenarios, such as when using a centralized user management system or integrating with other network services.

nsswitch.conf elements

In the nsswitch.conf file, lines beginning with a # are comments.
Every other non-blank line determines the look-up order for a particular type of information. To see explanations for a typical command line, roll your mouse over each term in the MouseOver below.

nsswitch.conf line for NIS
  1. Linux refers to this line when seeking information about hosts. Other information maps include password services and protocols
  2. On this particular network, Linux first checks the NIS server for hostname information
  3. If the NIS system fails to find the requested information, the local files are checked. In this case, Linux checks
  4. After NIS and local files have failed to return the sought for information, Linux checks the DNS system. If DNS fails, the user application that requested the information receives an error message.

Typical nsswitch.conf line

Controlling look-ups

You can control the behavior of information look-ups further with a line in nsswitch.conf like the following:
hosts: nis [notfound=return] files dns

The [notfound=return] controls the use of look-up methods such as NIS. It tells Linux that if NIS is working, but the requested host is not found, it should skip the local files as well as DNS and return an error. On the other hand, if the NIS server simply does not respond, Linux proceeds to check the local files and then DNS.
See the nsswitch.conf man page for detailed information on available databases and look-up methods.
The next lesson shows you how to use authconfig to configure an NIS client machine.

nsswitch Function Elements

Before moving on to the next lesson, click the link below to practice matching the nsswitch elements to their functions.
nsswitch Function Elements