Differences between revisions 1 and 6 (spanning 5 versions)
Revision 1 as of 2020-11-10 04:07:23
Size: 1801
Comment:
Revision 6 as of 2025-12-19 21:32:56
Size: 2202
Comment: Fixed link
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= nsswitch.conf = = NsSwitch.Conf =

The '''Name Service Switch configuration file''' (or '''`nsswitch.conf(5)`'''), typically found at `/etc/nsswitch.conf`, declares how domain names should be translated into [[Protocols/IP|IP addresses]].
Line 31: Line 33:
The first column (delimited by spaces or tab characters) indicates a database, while every subsequent column is a source. Some common database sources are listed below. The first column (delimited by spaces or tab characters) indicates a '''database''', while every subsequent column is a '''service specification''' or '''optional action'''.
Line 33: Line 35:
For `hosts`...

=== Service Specifications ===

Common service specifications are:
Line 35: Line 42:
 * `dns` (i.e. run-time lookups based on `/etc/resolv.conf`)  * `dns` (i.e. runtime lookups based on `/etc/resolv.conf`)
Line 37: Line 44:
 * `mymachine` which connects to `systemd-machined` (see `nss-mymachines(8)`)
 * `resolve` which connects to `systemd-resolved` (see `nss-resolve(8)`)
 * `mymachine` which connects to [[Linux/Systemd|systemd-machined]] (see `nss-mymachines(8)`)
 * `resolve` which connects to [[Linux/SystemdResolved|systemd-resolved]] (see `nss-resolve(8)`)



=== Optional Actions ===

Option actions follow the pattern of `[STATUS=ACTION]` and `[!STATUS=ACTION]`.

A '''status''' can be any of:

 * `success` meaning 'no error'.
 * `notfound` meaning 'error in lookup'.
 * `unavail` indicates a connection couldn't be made.
 * `tryagain` indicates 'temporarily unavailability', as with locked connections.

An '''action''' can be any of:

 * `return` meaning 'return the result'
 * `continue` meaning 'try the next item'
 * `merge` causes the system to try both the preceding and the following items

By default, only a `success` status results in a `return` action. Anything else will result in a `continue`. The exception the `group` database, where a `notfound` status will lead to a `continue` action regardless of any action specified.
Line 44: Line 72:
=== Action Items === == See also ==
Line 46: Line 74:
'''Action items''' follow one the following patterns: `[STATUS=ACTION]` and `[!STATUS=ACTION]`.

`STATUS` can be any of...
 * `success` meaning 'no error'.
 * `notfound` meaning 'error in lookup'.
 * `unavail` indicates a connection couldn't be made.
 * `tryagain` indicates 'temporarily unavailability', as with locked connections.

`ACTION` can be any of...
 * `return` meaning 'return the result'
 * `continue` meaning 'try the next item'
 * `merge` causes the system to try both the preceding and the following items, and

By default, only a `success` status results in a `return` action. Anything else will result in a `continue`. The exception is for a `group` lookup-a `notfound` status will lead to a `continue` action regardless of any action specified.
[[https://man.archlinux.org/man/nsswitch.conf.5|nsswitch.conf(5)]]

NsSwitch.Conf

The Name Service Switch configuration file (or nsswitch.conf(5)), typically found at /etc/nsswitch.conf, declares how domain names should be translated into IP addresses.


Example

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


Syntax

Databases

The first column (delimited by spaces or tab characters) indicates a database, while every subsequent column is a service specification or optional action.

Service Specifications

Common service specifications are:

  • files (i.e. /etc/hosts)

  • dns (i.e. runtime lookups based on /etc/resolv.conf)

  • myhostname (see nss-myhostname(8))

  • mymachine which connects to systemd-machined (see nss-mymachines(8))

  • resolve which connects to systemd-resolved (see nss-resolve(8))

Optional Actions

Option actions follow the pattern of [STATUS=ACTION] and [!STATUS=ACTION].

A status can be any of:

  • success meaning 'no error'.

  • notfound meaning 'error in lookup'.

  • unavail indicates a connection couldn't be made.

  • tryagain indicates 'temporarily unavailability', as with locked connections.

An action can be any of:

  • return meaning 'return the result'

  • continue meaning 'try the next item'

  • merge causes the system to try both the preceding and the following items

By default, only a success status results in a return action. Anything else will result in a continue. The exception the group database, where a notfound status will lead to a continue action regardless of any action specified.


See also

nsswitch.conf(5)


CategoryRicottone

Linux/NsSwitchConf (last edited 2025-12-19 21:32:56 by DominicRicottone)