Operations 7 min read

How to Quickly Identify and Fix “Address Already in Use” Errors on Linux

This guide explains how to diagnose the “Address already in use” error by listing listening ports with netstat, ss, and lsof, interpreting their output, filtering results, and locating the offending process on Linux and macOS systems.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Quickly Identify and Fix “Address Already in Use” Errors on Linux
Address already in use

is a common error; this article shows how to quickly locate the cause using netstat, ss and lsof on Linux/macOS.

What Is a Listening Port

A network port is identified by its number, associated IP address, and protocol (TCP/UDP). A listening port is a port on which an application or process waits for incoming connections, acting as a communication endpoint. Ports can be opened or closed by firewalls, and two services cannot listen on the same IP address and port simultaneously.

Checking Listening Ports with netstat

netstat

provides information about network connections. To list all listening TCP and UDP ports with the associated services, run: sudo netstat -tunlp Options: -t – show TCP ports -u – show UDP ports -n – display numeric addresses -l – show only listening ports -p – show PID and program name (requires root)

Key columns in the output are Proto (protocol), Local Address (IP and port), and PID/Program name. To filter for a specific port, e.g., TCP port 22: sudo netstat -tnlp | grep :22 If the output is empty, no process is listening on that port.

Note: netstat is deprecated; ss and ip are preferred, but netstat remains widely used.

Checking Listening Ports with ss

ss

is a modern replacement for netstat. Use the same options: sudo ss -tunlp The output format is similar, showing listening sockets and their owning processes.

Checking Listening Ports with lsof

lsof

lists open files, including network sockets. To list all listening TCP ports: sudo lsof -nP -iTCP -sTCP:LISTEN Important options: -n – do not resolve hostnames -P – do not convert port numbers to names

To find the process listening on a specific port, e.g., 3306: sudo lsof -nP -iTCP:3306 -sTCP:LISTEN The output shows the command, PID, user, and the listening port.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

networktroubleshootingnetstatlsofport listeningss
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.