Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Find What Listening TCP Port Mac: 5 Commands

· 4 min read · Home Tech

In this article
  1. Why You Need to Check Listening Ports
  2. The Primary Command: lsof
  3. Alternative: netstat
  4. Finding a Specific Port
  5. Understanding the Output Fields
  6. Common Misconceptions
  7. Frequently Asked Questions

To find what TCP port a Mac is listening on, open Terminal and run sudo lsof -iTCP -sTCP:LISTEN -n -P. This lists every process with an open listening TCP port, the port number, and the process name; add sudo to see ports used by other users and system processes.

Why You Need to Check Listening Ports

Every network service on a Mac—web servers, SSH, file sharing, databases—opens a TCP port to accept connections. Knowing which ports are listening helps you:

  • Confirm a service (like Apache or PostgreSQL) started correctly.
  • Identify unexpected processes that might be security risks.
  • Free up a port that another application needs.
  • Troubleshoot connection failures when a client says “connection refused.”

Ports below 1024 are “privileged” and usually require root to bind, while higher ports are open to any user. A listening port doesn’t mean a connection is active—it just means the system is ready to accept one.

The Primary Command: lsof

The lsof command (list open files) is the standard tool on macOS. On Unix systems, network sockets are treated as files, so lsof can show them. The exact command with useful options:

sudo lsof -iTCP -sTCP:LISTEN -n -P

Breakdown of the flags:

  • -iTCP – show only TCP connections (omit for UDP too).
  • -sTCP:LISTEN – filter to sockets in the LISTEN state.
  • -n – don’t resolve hostnames (faster, cleaner output).
  • -P – don’t convert port numbers to service names (shows raw numbers).

Sample output:

COMMAND   PID   USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
nginx 1234 root 11u IPv4 0x123456789abcdef 0t0 TCP *:8080 (LISTEN)
python3 5678 alice 5u IPv6 0xabcdef123456789 0t0 TCP [::1]:5432 (LISTEN)

The NAME column shows the address and port. *:8080 means the service listens on all network interfaces; [::1]:5432 means only on the IPv6 loopback (localhost).

Alternative: netstat

macOS also includes netstat, but its syntax differs from Linux. Use:

sudo netstat -anv | grep LISTEN

The -a shows all sockets, -n skips name resolution, and -v adds the PID and process name. The output is less readable than lsof, but it works on older macOS versions. For a more focused view, you can filter by port:

sudo netstat -anv | grep ".8080.*LISTEN"

Finding a Specific Port

To check if a particular port (say 3000) is already in use, use lsof with the port filter:

sudo lsof -iTCP:3000 -sTCP:LISTEN

If nothing prints, the port is free. If a process appears, you have the PID and command name. To kill that process (use with caution):

sudo kill -9 <PID>

For a quick check without sudo (only shows your own processes):

lsof -iTCP:3000 -sTCP:LISTEN

Understanding the Output Fields

Here’s what each column in lsof output means:

  • COMMAND – the executable name (e.g., nginx).
  • PID – process identifier; useful for killing or inspecting.
  • USER – the account that owns the process.
  • FD – file descriptor (often 11u for a socket).
  • TYPE – socket type (IPv4 or IPv6).
  • NAME – local address and port, plus state. *:8080 means all interfaces; a specific IP like 192.168.1.5:22 means only that interface.

The state is always LISTEN because of the filter. If you omit the filter, you’ll also see ESTABLISHED (active connections) and TIME_WAIT (closed sockets waiting).

Common Misconceptions

“Port 80 is always HTTP.” While port 80 is the default for HTTP, any process can bind to it. The listening process determines what protocol is used. Always check the process name, not just the port number.

“If a port shows LISTEN, it’s a security risk.” Not necessarily. macOS itself listens on several ports for legitimate services like AirDrop (port 5000) and Remote Management (port 5900). Only investigate ports that you didn’t intentionally open.

“lsof requires sudo every time.” Without sudo, you’ll only see your own processes. For a full system view, sudo is needed, but you can run lsof -iTCP -sTCP:LISTEN as a normal user to see your own ports.

Frequently Asked Questions

How do I see UDP listening ports on my Mac?

Replace -iTCP with -iUDP in the lsof command: sudo lsof -iUDP -n -P. UDP doesn’t have a LISTEN state, so the filter -sTCP:LISTEN won’t work; instead, you’ll see all UDP sockets, which are effectively listening.

What does “*:8080” mean in the output?

The asterisk means the service is listening on all network interfaces—both Wi-Fi and Ethernet, and any VPN. A specific IP (e.g., 127.0.0.1:8080) means it’s only reachable from that address, usually localhost.

Why does lsof show a port but netstat doesn’t?

Different tools may use different address families or filters. Also, netstat on macOS might require -v to show PID. Ensure you’re using the same options; lsof is generally more reliable for this task.

How do I find the PID of a process listening on a port?

Run sudo lsof -iTCP:<port> -sTCP:LISTEN and look at the PID column. For example, sudo lsof -iTCP:80 -sTCP:LISTEN shows which process is using port 80.

Can I see listening ports in Activity Monitor?

Activity Monitor doesn’t show ports directly. You need to use Terminal commands like lsof or netstat. Third-party GUI apps exist, but the built-in tools are sufficient and free.

Is it safe to kill a process that’s listening on a port?

Only if you know it’s not a critical system service. Killing a system process (like mDNSResponder) can cause network issues. Always check the process name and user first, and prefer a graceful shutdown (kill without -9) before resorting to force kill.