On Unix/Linux systems that use Name Service Switch (NSS), which configuration file specifies the order and sources (for example, files, DNS, NIS) for lookups like hosts and passwd?

Difficulty: Easy

Correct Answer: /etc/nsswitch.conf

Explanation:


Introduction / Context:
Name Service Switch (NSS) lets administrators define where system lookups obtain data—local files, DNS, NIS, LDAP—and in what order. Centralizing this policy avoids editing multiple tools and ensures consistent behavior across libc-resolved queries.


Given Data / Assumptions:

  • GNU/Linux or UNIX with NSS is in use.
  • We want to control lookup order for databases like hosts, passwd, group, services.
  • We need the file that sets the policy—not the data files themselves.


Concept / Approach:
'/etc/nsswitch.conf' defines per-database lookup sequences, such as 'hosts: files dns' or 'passwd: files nis'. The resolver consults modules in the specified order until success or terminal conditions (for example, '[NOTFOUND=return]'). By contrast, '/etc/hosts' contains static host mappings; '/etc/services' maps service names to port numbers; '/etc/nsorder' is not standard on modern Linux.


Step-by-Step Solution:

Open /etc/nsswitch.conf with a text editor.Locate the relevant database line (for example, 'hosts:').Set the desired sources and order (for example, 'files dns').Save and test with 'getent hosts name'.


Verification / Alternative check:
Use 'getent' to query databases and confirm that lookups follow the configured order. For hosts, temporarily edit '/etc/hosts' and verify precedence before DNS by querying with 'getent hosts testname'.


Why Other Options Are Wrong:

  • /etc/services: Port/service mappings, not NSS policy.
  • /etc/hosts: Static hostname table, one of the data sources.
  • /etc/nsorder: Nonstandard/obsolete on many systems.


Common Pitfalls:
Misordering sources causing slow lookups (for example, DNS before files for localhost), or forgetting to install the corresponding NSS modules for NIS/LDAP.


Final Answer:
/etc/nsswitch.conf

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion