What is /etc/nsswitch.conf?

/etc/nsswitch.conf is a Linux configuration file that specifies how the system should switch between different name service providers. The file can be used to configure which services should be used for hostname lookup, password lookups, and so on.

The /etc/nsswitch.conf file is read by the Name Service Switch (NSS) library when the system starts up. The NSS library then uses the information in /etc/nsswitch.conf to determine which name service providers should be used for each type of lookup.

/etc/nsswitch.conf is a critical part of the Linux operating system, and any changes to the file can potentially cause serious problems. As such, it is important to understand how /etc/nsswitch.conf works before making any changes to the file.

You can view the content of the /etc/nsswitch.conf file using the following command.

cat /etc/nsswitch.conf 

Output:

# # Example configuration of GNU Name Service Switch functionality. # If you have the `glibc-doc-reference' and `info' packages installed, try: # `info libc "Name Service Switch"' for information about this file. passwd: files systemd group: files systemd shadow: files gshadow: files hosts: files dns networks: files protocols: db files services: db files ethers: db files rpc: db files netgroup: nis

Understand the use of /etc/nsswitch.conf with an example

Let’s understand the uses of /etc/nsswitch.conf with an example. In this file, check for the below line:

hosts:          files dns

The above entry tells the order to resolve any domain name. First, the system will check domain mapping in files (/etc/hosts), If a matching entry is found it will use it.

Any domain resolve request will go to the DNS server, only if no matching entry is found in the /etc/hosts file.