How to generate random port number on the command line

The following Linux shell command will generate a random port number between 1024 and 65535 (inclusive):

random_port_shuf.sh
shuf -i 1024-65535 -n 1

Example:

random_port_example.txt
$ shuf -i 1024-65535 -n 1
45508

 


Check out similar posts by category: Linux, Networking