what uses /etc/nsswitch.conf?

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

Code:
$ 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:
Code:
$ 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:

Code:
::1                     localhost localhost.my.domain
127.0.0.1               localhost localhost.my.domain
whereas the "Imaginary network" format is FQDN followed by the alias?
Code:
# Imaginary network.
#10.0.0.2               myname.my.domain myname
#10.0.0.3               myfriend.my.domain myfriend
 
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.
 
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.

;)
 
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.
 
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.

:D

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?
 
Last edited by a moderator:
johnblue said:
Code:
$ 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.
Er, getent(1) does query dns source, even returns ipv6 since 9.2-RELEASE.
Code:
$ 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):
Code:
$ 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
 
Back
Top