Skip to content

free

portcheck free

Find free ports

Synopsis

Find free local ports in a range (default 1024-65535).

Ports are returned in ascending order, or a random one with --random. Another process can still grab a port after portcheck reports it, so bind it soon.

portcheck free [range] [flags]

Examples

  portcheck free                      # first free port >= 1024
  portcheck free 3000-3999 -n 3       # three free ports in a range
  portcheck free --random 20000-30000
  PORT=$(portcheck free -o plain 8000-9000 | tail -1)

Options

  -n, --count int      number of free ports to find (default 1)
  -h, --help           help for free
      --proto string   protocol: tcp or udp (default "tcp")
      --random         pick a random free port instead of the lowest

Options inherited from parent commands

      --json                shorthand for --output json
      --log-format string   log format: text or json (default "text")
      --no-color            disable colors (also honors NO_COLOR)
  -o, --output string       output format: table, plain, csv, json (default: table on a terminal, plain otherwise)
  -v, --verbose             log diagnostic details to stderr

SEE ALSO

  • portcheck - See what's using your ports, find free ones, and free them up