Skip to main content

Command Palette

Search for a command to run...

Find Unused Unix Ports

Port 443 is already used. Find another free port.

Updated
1 min read
Find Unused Unix Ports

Problem

You need to bring up another Unix web server but port 443 is already in use. How do you find another unused Unix port?

Solution

Use the netstat command to discover which ports are already used

netstat -ln | grep LISTEN | awk '{print $4}' | grep ":" | sort | uniq

Breakdown of commands

netstal -ln : List all the numerical Unix ports that are listening for network traffic

grep LISTEN : Display the output lines that are in LISTEN status

awk '{print $4} : Print the fourth column of the output that has the port numbers that Unix processed are LISTENING

sort | uniq : Sort the output and only show unique values

You will get an output similar to

0.0.0.0:443

0.0.0.0:5353
0.0.0.0:68
0.0.0.0:80
10.0.2.15:123
::1:10089
::1:123

The number after the last colon is the port in use, e.g. 443, 80, 123, 5353.  Pick any Unix port not already in use and assigned.

3 views

Quick Hacks

Part 1 of 1

Quick Hacks for DevOps problems