bindresvport - Linux


Overview

bindresvport reserves a port below 1024 for a specific process and returns it to the user. This command is commonly used to acquire a privileged port for applications that require low-level network access.

Syntax

bindresvport [options] [udp|tcp] [port]

Options/Flags

  • -s, –stdout-port: Output the assigned port to stdout.
  • -u, –udp: Reserve a UDP port.
  • -t, –tcp: Reserve a TCP port (default).

Examples

Simple TCP Port Reservation

bindresvport tcp 80

This command reserves TCP port 80 for the process.

Outputting Reserved Port to Stdout

bindresvport -s udp 1234

The reserved port will be printed to the terminal.

Specifying a Specific Process

bindresvport -s udp 5335 < /dev/null &

This command reserves UDP port 5335 for the process reading from /dev/null.

Common Issues

  • Permission Denied: The user may not have sufficient privileges to bind to a port below 1024.
  • Port Already in Use: The specified port may already be in use by another process.
  • Invalid Port Number: The provided port number must be an integer between 1 and 1023.

Integration

bindresvport can be used in conjunction with other commands to create complex network configurations. For example, it can be used with socat to create a reverse proxy:

bindresvport -s tcp 80 | socat - tcp:localhost:80,reuseaddr

Related Commands

  • socat: A multi-purpose networking tool
  • netcat: A network debugging and exploration tool
  • portreserve: Reserves a TCP port for a specified time