How to Find Port in Use in Ubuntu

The Socket Binding Audit Vector

When operating a headless Ubuntu Linux server, the OS relies on numerical routing channels known as “Ports” to direct incoming network traffic to specific software daemons (e.g., Port 80 for HTTP, Port 22 for SSH, Port 3306 for MySQL). A catastrophic conflict occurs when you attempt to launch a new service (like an Nginx web server) but the target port is already mathematically bound to a rogue, zombie, or deprecated process running in the background. The kernel will violently reject the launch, throwing an “Address already in use” error. You must instruct the core OS to dump the raw telemetry of its network stack, revealing exactly which process ID (PID) is hijacking the specific port.

How to Find Port in Use in Ubuntu

The UNIX architecture provides two primary God-level command-line binaries for auditing socket connections: the legacy `netstat` (which is deprecated but still widely used) and the modernized `ss` (Socket Statistics) daemon.

1. Open your terminal application or connect to the server via SSH.
2. Method 1: The Modernized `ss` Daemon (The Optimal Vector):
* This is the mathematically superior and significantly faster pathway for modern Ubuntu kernels.
* To audit all active, listening TCP ports and identify the hijacking daemon, type exactly:

sudo ss -tulpn

* Press Enter and inject your administrator password.
* The Flag Breakdown:
* `-t` (TCP sockets)
* `-u` (UDP sockets)
* `-l` (Listening ports only)
* `-p` (Show the exact Process ID/Program name)
* `-n` (Numeric output; prevents the daemon from wasting time resolving hostnames).
* The Output Matrix: Look at the Local Address:Port column (e.g., `0.0.0.0:80`). Follow that row to the absolute right under the Process column. You will see the exact daemon (e.g., `nginx`) and its PID (e.g., `pid=4598`).
3. Method 2: The Surgical Strike (Grep Filtering):
* If you already know the specific port you want to investigate (e.g., Port 8080) and want to filter out the massive block of visual noise.
* Type exactly:

sudo ss -tulpn | grep :8080

* Press Enter.
* The OS pipes the raw output directly into the `grep` search daemon, which prints only the single row of telemetry containing that specific numerical string.
4. Method 3: The Legacy `netstat` Override:
* If your specific server architecture lacks the `ss` binary.
* Type exactly:

sudo netstat -tulpn | grep LISTEN

* Press Enter. This executes the exact same mathematical audit, dumping the listening ports and their associated PIDs.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.