Cybersecurity

How do I find what ports are open on my system?

Learn the tools and techniques to identify which network ports are listening on your system, from using command-line utilities to network scanning tools.

By Inventive HQ Team

To find open ports on your system, use the built-in command for your OS: on Linux run ss -tulpn, on macOS run sudo lsof -iTCP -sTCP:LISTEN -n -P, and on Windows run netstat -ano. Each lists the ports where a program is listening for incoming connections, along with the owning process. To see your machine the way an outsider does — probing across the network instead of reading the local socket table — run nmap localhost or nmap <your-ip>. Local tools show every bound socket; nmap shows only what actually answers.

That's the summary an AI overview gives you. What it can't give you is the part that trips people up: these tools measure different things, macOS silently rejects the Linux flags everyone copies, and a port "listening" in ss can still be invisible from the network. The table and diagram below map each method to what it actually reveals — and the rest of this guide covers how to read the output, find the process behind a port, and check what's exposed to the internet.

Scanning a host for open (listening) ports A host with several ports; a scanner beam sweeps across them, marking listening ports open and closed ports shut. Listening ports are open doors — the rest stay shut YOUR HOST 22 443 8080 scanner ss / nmap LISTENING (open) not bound (closed)

The one-command answer for each OS

Most of the time you don't need a deep scan — you need the single built-in command that lists what's listening. Here's the method per operating system, what each one actually shows, and the gotcha to know before you copy it:

OSCommandWhat it showsNotes / gotcha
Linux (modern)ss -tulpnTCP + UDP listening sockets, numeric ports, owning process/PIDThe current standard (iproute2). Add sudo to see processes you don't own. -p = process, -l = listening only.
Linux (legacy)netstat -tulpnSame as aboveDeprecated but familiar; may not be installed by default. ss is preferred.
macOSsudo lsof -iTCP -sTCP:LISTEN -n -PTCP listeners with process name and PIDmacOS uses BSD netstat — the Linux -tuln flags do not work. lsof is the reliable path.
macOS (all sockets)netstat -an -p tcpEvery TCP socket + stateBSD syntax; filter for LISTEN yourself. Use -p udp for UDP.
Windowsnetstat -anoAll connections + listeners with PIDPipe to findstr LISTENING for listeners only; map PID with tasklist.
Windows (PowerShell)Get-NetTCPConnection -State ListenTCP listeners as objects (scriptable)Cleaner output; join with Get-Process to get the app name.
Any (network view)nmap localhost or nmap <ip>Ports that actually respond over the networkProbes packets, not the socket table — reveals what's reachable, not just bound. Only scan hosts you own.

The key distinction the table encodes: ss, lsof, and netstat read your machine's own socket table (including localhost-only services); nmap sends real packets and shows only what answers across the network. That's why a port can be "listening" locally yet invisible to nmap — it may be bound to 127.0.0.1 or blocked by a firewall.

Identifying Open Ports on Your System

Open ports represent potential entry points for attackers and often indicate which services are running on your system. Whether you're an IT administrator managing infrastructure, a security professional conducting network assessments, or a developer troubleshooting application connectivity, knowing how to identify open ports is a fundamental skill. This guide covers the most practical methods for discovering which ports are listening on your system.

The process of finding open ports involves querying your system to determine which ports have services actively listening for incoming connections. This differs from simply knowing which services you've installed—it reveals what's actually accessible over the network. Understanding your port landscape is the first step toward securing your systems properly.

Loading interactive tool...

Windows Methods for Identifying Open Ports

Using netstat Command

The netstat command is the most straightforward way to view listening ports on Windows:

netstat -ano

This command displays all connections and listening ports with detailed information:

  • -a: Shows all connections and listening ports
  • -n: Displays addresses and port numbers in numerical form
  • -o: Includes the owning process ID (PID) associated with each connection

The output shows columns including Protocol, Local Address, Foreign Address, State, and PID. To identify which process is using a specific port, look up the PID in Task Manager or use:

tasklist /FI "PID eq XXXX"

Replace XXXX with the specific PID number. This correlates the port listener with the actual application.

For a more focused view of listening ports only:

netstat -ano | findstr LISTENING

This filters the output to show only ports in the LISTENING state, making it easier to identify active services.

Advertisement

Using PowerShell

Modern Windows systems support PowerShell, which provides more powerful commands:

Get-NetTCPConnection | Where-Object {$_.State -eq "Listen"} | Select-Object LocalAddress, LocalPort, OwningProcess

This PowerShell command provides a cleaner output than netstat and is more suitable for scripting and automation. You can even get the process name directly:

Get-NetTCPConnection | Where-Object {$_.State -eq "Listen"} | ForEach-Object {
    $proc = Get-Process -Id $_.OwningProcess -ErrorAction SilentlyContinue
    [PSCustomObject]@{
        LocalPort = $_.LocalPort
        Process = $proc.ProcessName
        PID = $_.OwningProcess
    }
}

Using netstat with More Details

For UDP ports specifically:

netstat -ano | findstr UDP

Or to see all TCP listening ports:

netstat -ano | findstr "LISTENING"

Resource Monitor GUI

Windows provides a graphical interface for viewing network connections:

  1. Press Windows Key + R
  2. Type "resmon" and press Enter
  3. Navigate to the Network tab
  4. Expand "Listening Ports" to view all open ports

This visual method helps identify which applications are using which ports.

netstat with Specific Port

To check if a specific port is listening:

netstat -ano | findstr :8080

Replace 8080 with your target port number.

Linux/macOS Methods for Identifying Open Ports

Using netstat Command

On Linux, the classic invocation is:

netstat -tuln

The flags mean:

  • -t: Show TCP connections
  • -u: Show UDP connections
  • -l: Show only listening sockets
  • -n: Show numeric addresses and ports

Important — this does not work on macOS. macOS ships the BSD version of netstat, where -t, -u, and -l do not have these meanings, so netstat -tuln will error or return unexpected output. On a Mac, use lsof (below) or the BSD syntax:

netstat -an -p tcp    # all TCP sockets; filter for LISTEN yourself

To scope the modern Linux netstat to a single protocol, drop the flag you don't need — netstat -tln for TCP only, netstat -uln for UDP only.

Using ss Command (Modern Linux)

The ss command is the modern replacement for netstat on newer Linux systems:

ss -tulpn

The flags: -t (TCP), -u (UDP), -l (listening only), -p (show the owning process/PID — run with sudo to see processes you don't own), -n (numeric ports). This provides similar output to netstat but reads socket state directly from the kernel, giving much better performance on systems with thousands of connections.

Using lsof Command

lsof (list open files) can identify processes using network ports:

lsof -i -P -n | grep LISTEN

This shows listening ports with the associated process names and PIDs. The flags mean:

  • -i: Selects IP sockets
  • -P: Shows port numbers instead of service names
  • -n: Shows IP addresses instead of hostnames

For a specific port:

lsof -i :8080

Using nmap (Network Mapper)

For a more comprehensive network scan of your local machine:

nmap localhost

Or with more detailed information:

nmap -sV localhost

The -sV flag attempts to identify service versions running on each port. This tool is powerful for understanding not just which ports are open, but what services are listening.

Using nc (netcat) for Port Testing

Test if a specific port is listening:

nc -zv localhost 8080

The flags mean:

  • -z: Scan mode (without sending data)
  • -v: Verbose output
  • Replace 8080 with your target port

A successful connection indicates the port is open, while a connection refusal indicates it's not listening.

Comprehensive Port Scanning Tools

Using nmap for Deep Scanning

While the above methods check local systems, nmap can scan your external port visibility:

nmap -p- -A localhost

This comprehensive scan:

  • -p-: Scans all 65535 ports (takes longer)
  • -A: Enables aggressive scanning with OS detection, version detection, and script scanning

Online Port Scanning Services

For checking which ports are visible from the internet:

  1. ShieldsIO: Visit shields.io for quick port scanning
  2. CanYouSeeMe.org: Simple tool to check if a specific port is open from the internet
  3. Shodan: More advanced tool for finding exposed services globally

These services scan your public IP address from the internet to determine which ports are actually visible outside your network.

Understanding Port States

When identifying open ports, you'll encounter several states:

LISTENING: The port is open and actively accepting incoming connections. The associated service is running and available.

ESTABLISHED: An active connection exists on this port. Data may be actively flowing.

CLOSE_WAIT: The connection is closing, with the remote system having closed its side first.

TIME_WAIT: The port is waiting before releasing the socket after connection closure.

SYN_RECEIVED: The system has received a connection request and is responding.

Securing Your Open Ports

Once you've identified your open ports, take these security steps:

Inventory Services: Document what service should legitimately be listening on each port. Any unexpected ports are immediately suspicious.

Close Unnecessary Ports: If a port isn't needed, disable the associated service or block it with a firewall rule.

Apply Firewall Rules: Restrict access to necessary ports only from trusted IP addresses or networks.

Keep Software Updated: Services on open ports should be running the latest patched versions.

Monitor Port Changes: Unexpected new listening ports might indicate a compromise. Use monitoring tools to alert on changes.

Change Default Ports: Moving services from default ports (like moving SSH from 22 to 2222) reduces automated attack attempts.

Best Practices for Port Management

Regular Scanning: Run port identification commands regularly (weekly or monthly) to detect unauthorized changes.

Automated Monitoring: Use tools like Nagios, Zabbix, or Prometheus to automatically monitor port availability and alert on changes.

Documentation: Keep detailed documentation of which ports should be open and what services use them.

Testing After Changes: Always verify that intended ports open and unintended ports close after system changes or firewall updates.

Principle of Least Privilege: Only open ports absolutely necessary for business operations.

Conclusion

Identifying open ports is a critical first step in understanding your system's network posture. Whether using simple command-line tools like netstat and ss, or more advanced scanning utilities like nmap, regular port discovery should be part of your security routine. By understanding what ports are open, why they're open, and what services use them, you can make informed decisions about network security, identify unauthorized access points, and ensure your systems are exposed only to the extent necessary for legitimate operations.

Frequently Asked Questions

What command shows open ports?

It depends on your operating system. On modern Linux, use ss -tulpn (TCP + UDP, listening only, with process and numeric ports). On macOS, use sudo lsof -iTCP -sTCP:LISTEN -n -P for TCP listeners, because macOS ships the BSD version of netstat, which does not accept the Linux -tuln flags. On Windows, use netstat -ano and read the PID column, or the PowerShell equivalent Get-NetTCPConnection. To see ports the way an outsider does, run nmap localhost. All of these list local listeners; only nmap actually probes the network.

What is the difference between ss and netstat?

ss is the modern replacement for netstat on Linux, shipped with the iproute2 package. It reads socket data directly from the kernel rather than parsing /proc, so it is significantly faster on busy servers with thousands of connections. netstat still works and uses similar flags, but it is deprecated on most Linux distributions and may not be installed by default. On macOS and Windows, ss is not available and netstat remains the built-in tool.

How do I find which process is using a port?

On Linux, add the -p flag: ss -tulpn shows the process name and PID next to each listening socket (run with sudo to see processes you do not own). On macOS, lsof -i :PORTNUMBER lists the owning process directly. On Windows, netstat -ano shows the PID in the last column, then run tasklist /FI "PID eq XXXX" to map that PID to an application name, or use Get-Process -Id in PowerShell.

Does netstat -tuln work on macOS?

No. macOS uses the BSD version of netstat, where -t, -u, and -l do not mean what they mean on Linux, so netstat -tuln returns an error or unexpected output. On macOS, use lsof to list listeners (sudo lsof -iTCP -sTCP:LISTEN -n -P) or the BSD-style netstat -an -p tcp to view all TCP sockets. This is one of the most common mistakes when copying Linux commands onto a Mac.

What does LISTENING mean in netstat output?

LISTENING means a service has bound to that port and is waiting for incoming connections — the port is open and a program is ready to accept traffic on it. Other common states include ESTABLISHED (an active connection is exchanging data), TIME_WAIT (a closed connection is briefly held before the socket is freed), and CLOSE_WAIT (the remote side has closed and the local application has not yet finished). Only LISTENING ports represent services accepting new connections.

How do I check open ports without installing anything?

Every major OS has a built-in tool. Linux has ss (and usually netstat); macOS has lsof and netstat; Windows has netstat and PowerShell's Get-NetTCPConnection. None of these require an install. You only need a third-party tool like nmap if you want to scan a port range, detect service versions, or probe a machine over the network rather than list its local listeners.

Why does nmap show different ports than netstat?

They measure different things. netstat, ss, and lsof read the local socket table and show every port a program has bound on the machine — including services listening only on 127.0.0.1 (localhost). nmap sends real packets and reports which ports actually respond, so it reflects what is reachable across the network after firewalls and the loopback boundary. A port that shows as listening in ss can appear filtered or closed in nmap if it is bound only to localhost or blocked by a firewall.

How can I see which ports are open from the internet?

Local tools cannot tell you this, because they only see the machine's own socket table — not what your router, NAT, or ISP allows through. To check external visibility, scan your public IP from outside your network using an online service such as CanYouSeeMe.org (single port) or a hosted nmap scan, or search Shodan for your IP to see what it has already indexed. Always scan only systems you own or are authorized to test.

network securityportsport scanningdiagnostics