Cheatsheet: Find Listening Ports

Last updated 2026-09-20

Using lsof (Linux and macOS)

Find the process listening on a specific port. Works the same on Linux and macOS.

lsof -i :<port_number>

List all network connections and listening processes, with numeric ports/addresses.

lsof -i -P -n

Restrict to TCP sockets that are actually in the LISTEN state.

lsof -nP -iTCP -sTCP:LISTEN

Print only the PID(s) for a port, useful for scripting (e.g. kill whatever is bound to it).

kill $(lsof -t -i :<port_number>)

Using netstat (per-OS differences)

Linux: find the process ID and program name for a specific port with the -p flag.

netstat -tulnp | grep <port_number>

Linux: list all listening TCP/UDP processes.

netstat -tulnp

macOS/BSD: netstat has no -p flag, so it can confirm the port is listening but not the owning process.

netstat -an | grep LISTEN | grep <port_number>

macOS: pair netstat's confirmation with lsof to get the PID, since netstat alone can't show it.

netstat -an | grep <port_number>
lsof -i :<port_number>

Using ss (Linux)

Find details about a specific port, including the owning process with -p.

ss -tulnp | grep <port_number>

List all listening TCP/UDP processes.

ss -tulnp

Restrict output to listening sockets only (the -l flag).

ss -tlnp

Filter by destination or source port directly using ss's own port syntax instead of piping to grep.

ss -tlnp sport = :<port_number>

Using fuser

Find the process using a specific port

fuser <port_number>/tcp

FAQ