GETNAMEINFO(1) | General Commands Manual | GETNAMEINFO(1) |
getnameinfo
—
resolve IP addresses and ports to host and service
names
getnameinfo |
[-46FHNnrSu ] [-f
family] [-p
port] [IP-address] |
The getnameinfo
utility resolves IP
addresses and port numbers to hostnames and service names as if with the
getnameinfo(3) library
routine and formats them to standard output.
The output is a single line of space-separated fields:
hostname service
Depending on the flags specified, the output may consist only of the hostname or service name, or their numeric representations. By default, both are shown.
Although getnameinfo
may query the DNS or
other sources for name resolution depending on the system's
nsswitch.conf(5)
configuration, it is not intended to replace DNS-specific tools like
dig(1).
The following options are available:
-4
-6
-F
NI_NOFQDN
flag in
getnameinfo(3).-f
-H
-N
NI_NUMERICSERV
flag in
getnameinfo(3).-n
NI_NUMERICHOST
flag in
getnameinfo(3).-p
port-r
NI_NAMEREQD
flag in
getnameinfo(3).-S
-u
NI_DGRAM
flag in
getnameinfo(3).The getnameinfo
utility exits 0 on
success, and >0 if an error occurs.
Look up the hostname and service name for an IPv4 address:
$ getnameinfo -4 -p 80 93.184.216.34 example.com http
Look up the numeric host and service for an IPv6 address:
$ getnameinfo -nN -p 443 2606:2800:220:1:248:1893:25c8:1946 2606:2800:220:1:248:1893:25c8:1946 443
Resolve an address to its hostname but suppress the service name:
$ getnameinfo -H -p 22 192.0.2.1 example-host
Resolve a hostname and service for a UDP connection:
$ getnameinfo -u -p 53 198.51.100.2 example-dns-server domain
dig(1), getaddrinfo(1), getaddrinfo(3), getnameinfo(3), inet(3), hosts(5), nsswitch.conf(5)
February 6, 2025 | NetBSD 10.99 |