Pages

Sunday, April 16, 2017

What is the use of nsswitch.conf

nsswitch - Name Service Switch configuration file (nsswitch.conf)

The Name Service Switch configuration file (/etc/nsswitch.conf), is used by the GNU C Specifies the method to use and the order in which to use them when looking  for a users passwords, hosts ip and group. you can also specify what action the system takes based on whether a method works or fails.

Each category of information is identified by a database name. The file is plain ASCII text, with columns separated by spaces or tab characters.  The first column specifies the database name.  The remaining columns describe the order of sources to query and a limited set of actions that can be performed by lookup result.  

/etc/nsswitch.conf covers way more than host names: it also covers the resolution of mail aliases, user and group names, network protocol, service and segment names and others.

Syntax of file : info: method [[action]] [method] action

Some Sample entries from conf file

passwd:     files
shadow:     files
group:      files
hosts:      files dns
#hosts:     db files nisplus nis dns

Valid entries include:

nisplus  = Use NIS+ (NIS version 3)
nis = Use NIS (NIS version 2), also called YP
dns = Use DNS (Domain Name Service)
files = Use the local files
db =  Use the local database (.db) files
compat =  Use NIS on compat mode
hesiod =   Use Hesiod for user lookups
[NOTFOUND=return] Stop searching if not found so far

To use db, put the "db" in front of "files" for entries you want to be

[STATUS=ACTION] , [!STATUS=ACTION]

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

The ! negates the test, matching all possible results except the one specified. The case of the keywords is not significant.

The STATUS value can be one of:

successNo error occurred and the requested entry is returned. The default action for this condition is "return".

notfoundThe lookup succeeded, but the requested entry was not found. The default action for this condition is "continue".

unavail The service is permanently unavailable. This can mean either that the required file cannot be read, or, for network services, that the server is not available or does not allow queries. The default action for this condition 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 for this condition is "continue".

The ACTION value can be one of:

returnReturn a result now. Do not call any further lookup functions. However, for compatibility reasons, if this is the selected action for the group database and the notfound status, and the configuration file does not contain the initgroups line, the next lookup function is always called, without affecting the search result.

The entry '[NOTFOUND=return]' means that the search for an  entry should stop if the search in the previous entry turned  up nothing. Note that if the search failed due to some other reason  (like no NIS server responding) then the search continues with the  next entry.

continueCall the next lookup function.

What is the difference between /etc/host.conf and /etc/nsswitch.conf

In simplet terms, GNU C Library 2.x uses /etc/nsswitch.conf and older versions use /etc/hosts.conf.

To Check the GNU lib C Version, use ldd -version

[user@XXXX]# ldd --version
ldd (GNU libc) 2.12

No comments:

Post a Comment