# what uses /etc/nsswitch.conf?



## johnblue (Oct 6, 2013)

Similar to using ping to query /etc/hosts for name resolution, is there another utility that uses /etc/nsswitch.conf?


```
$ ping john
PING john (10.10.10.10): 56 data bytes
^C
--- john ping statistics ---
3 packets transmitted, 0 packets received, 100.0% packet loss
```

Optionally, this works:
	
	



```
$ getent hosts john
10.10.10.10       john  john.blue.com
```

As best as I can tell, getent is only reading the file and matching.  If it uses gethostbyname(3)() then that would be dandy, but I do not think that it does.

And whilst we are on the subject of /etc/hosts, does anyone know why the uncommented example has the alias *before* the FQDN:


```
::1                     localhost localhost.my.domain
127.0.0.1               localhost localhost.my.domain
```
whereas the "Imaginary network" format is FQDN followed by the alias?

```
# Imaginary network.
#10.0.0.2               myname.my.domain myname
#10.0.0.3               myfriend.my.domain myfriend
```


----------



## tzoi516 (Oct 6, 2013)

nsswitch.conf(5)


> The nsswitch.conf file specifies how the nsdispatch(3) (name-service
> switch dispatcher) routines in the C library should operate.



Hope this helps.


----------



## johnblue (Oct 6, 2013)

tzoi516 said:
			
		

> nsswitch.conf(5)
> 
> Hope this helps.


Thanks for posting, and I have read it but it only talks about "how" it is used, not "who" makes use of all of the library functions outlined therein.


----------



## SirDice (Oct 7, 2013)

It doesn't say who because we don't really know. It does mention the C API calls that use nsswitch.conf(5). And since pretty much every program that needs to resolve uses those functions it's safe to assume nearly every program is "who" uses it.


----------



## johnblue (Oct 7, 2013)

SirDice said:
			
		

> And since pretty much every program that needs to resolve uses those functions it's safe to assume nearly every program is "who" uses it.


Agreed.

The reason why I was wondering about a different utility because I dislike using `ping` for name resolution of the hosts file if something else does job directly.


----------



## kpa (Oct 7, 2013)

Use dig(1) for querying name servers if you are interested in seeing only the results of DNS resolution and not how the system resolver happens to behave.


----------



## johnblue (Oct 8, 2013)

kpa said:
			
		

> Use dig(1) for querying name servers if you are interested in seeing only the results of DNS resolution and not how the system resolver happens to behave.


Thanks for the post @kpa but I think conversation has sort of got sidetracked.



True, dig(1) and nslookup(1) are commonly well known tools to use for name resolution, but there does not appear to be a tool dedicated for use (as you say) for how the system resolver works with the exception of ping(8).

Any thoughts on why the naming convention for FQDN and alias is swapped in /etc/hosts?


----------



## oops (Oct 8, 2013)

johnblue said:
			
		

> ```
> $ getent hosts john
> 10.10.10.10       john  john.blue.com
> ```
> ...


Er, getent(1) does query dns source, even returns ipv6 since 9.2-RELEASE.

```
$ getent hosts freebsd.org
2001:1900:2254:206a::50:0  freebsd.org
8.8.178.110       freebsd.org
```

For sockets try getaddrinfo(1) (from netbsd):

```
$ getaddrinfo freebsd.org
dgram inet6 udp 2001:1900:2254:206a::50:0 0
stream inet6 tcp 2001:1900:2254:206a::50:0 0
seqpacket inet6 sctp 2001:1900:2254:206a::50:0 0
dgram inet udp 8.8.178.110 0
stream inet tcp 8.8.178.110 0
seqpacket inet sctp 8.8.178.110 0
```


----------

