getrpcport - Linux


Overview

getrpcport retrieves the registered port number for the specified remote procedure call (RPC) program and protocol. It’s useful for obtaining the port used by RPC services, such as the Network File System (NFS) or the Sun Remote Procedure Call (RPC) daemon.

Syntax

getrpcport [options] program protocol

Options/Flags

  • -f: Use TCP instead of UDP for the RPC connection.
  • -n: Use a port number instead of a port name.
  • -p: Specify the protocol version (usually 2).
  • -s: Report the IP addresses of the hosts that support the specified RPC.
  • -u: Use UDP instead of TCP for the RPC connection.
  • -w: Wait for the server to respond before returning. The default timeout is 1 second.

Examples

  • Get the port number for NFS over TCP:
getrpcport -p 2 -u nfs mountd
  • Obtain the IP addresses of hosts running the Sun RPC daemon:
getrpcport -s portmap 1
  • Check if a port number is available:
getrpcport -n 80

Common Issues

  • No response from server: Ensure that the RPC service is running on the specified host and port.
  • Incorrect program or protocol: Verify the program name and protocol version.
  • Timeout error: Increase the timeout period using the -w flag if the server is slow to respond.

Integration

getrpcport can be combined with other commands, such as:

  • Port scanning: nmap -sU -p $(getrpcport -n portmap UDP) scans for UDP ports associated with RPC services.
  • Service checking: if getrpcport -n 80; then echo "Web server is running"; else echo "Web server is down"; fi checks if the web server is accessible.

Related Commands

  • rpcinfo: Displays RPC program and service information.
  • nfsmount: Mounts an NFS file system.
  • rpcbind: Manages RPC port binding.