GETNAMEINFO(1) | General Commands Manual | GETNAMEINFO(1)

# NAME

`getnameinfo` — resolve IP addresses and ports to host and service names

# SYNOPSIS

`getnameinfo` | [`-46FHNnrSu`] [`-f` family] [`-p` port] [IP-address]

# DESCRIPTION

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`
  Restrict the lookup to IPv4 addresses only.
`-6`
  Restrict the lookup to IPv6 addresses only.
`-F`
  Suppress the fully-qualified domain name (FQDN). This is equivalent to the `NI_NOFQDN` flag in getnameinfo(3).
`-f`
  Specify an address family numerically or as a name, eg. “inet”.
`-H`
  Display only the hostname, omitting the service name.
`-N`
  Display the numeric service name instead of resolving to a service name. This is equivalent to the `NI_NUMERICSERV` flag in getnameinfo(3).
`-n`
  Display the numeric host address instead of resolving to a hostname. This is equivalent to the `NI_NUMERICHOST` flag in getnameinfo(3).
`-p` port
  Specify the port number to be used in the lookup.
`-r`
  Ensure that a name is returned. If no name can be resolved, an error is reported. This is equivalent to the `NI_NAMEREQD` flag in getnameinfo(3).
`-S`
  Display only the service name, omitting the hostname.
`-u`
  Use UDP instead of the default TCP. This is equivalent to the `NI_DGRAM` flag in getnameinfo(3).

# EXIT STATUS

The `getnameinfo` utility exits 0 on success, and >0 if an error occurs.

# EXAMPLES

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

# SEE ALSO

dig(1), getaddrinfo(1), getaddrinfo(3), getnameinfo(3), inet(3), hosts(5), nsswitch.conf(5)

February 6, 2025 | NetBSD 10.99