Netstat Command: Ports, Connections, and Process IDs

An IT professional examines network activity on computer monitors.

Written by

in

Every open port on a machine belongs to a process, and the netstat command is the fastest built-in way to prove which one. On Windows, run netstat -ano in Command Prompt to list every listening port and connection with its process ID (PID), then match that PID to an application with tasklist /FI "PID eq 1234" or the Details tab in Task Manager. On Linux the equivalent is sudo netstat -tulnp (or ss -tulnp), and on macOS it is netstat -anv paired with lsof.

An IT professional examines network activity on computer monitors.

Netstat (short for network statistics) shows local network status: sockets, TCP states, routing tables, and protocol counters. It cannot tell you whether a remote client can reach a port, and that gap causes most misread results. Once you can read a socket line correctly, you can tell a binding problem from a firewall or routing problem in under a minute.

At PacketTools, netstat is the first local check in nearly every network troubleshooting session, before any external test runs. The examples below come from that workflow: real flag combinations, annotated output, and the follow-up checks that confirm what netstat suggests.

How Do You Find Listening Ports and Their Processes on Windows?

You find listening ports on Windows by combining -a, -n, and -o, filtering the result with findstr, and resolving the PID with tasklist or Task Manager. The same steps work on Windows 10, Windows 11, and Windows Server; only -b needs an elevated prompt.

Open Command Prompt and Start With netstat -ano

Press Win + R, type cmd, and press Enter. For -b later, right-click Command Prompt and choose Run as administrator instead.

Then run:

netstat -ano

Each flag does one job:

Flag What it adds
-a All connections plus TCP and UDP listening ports
-n Numeric addresses and ports, no name lookups
-o The owning process ID (PID) for each line

Used without parameters, netstat displays only active TCP connections, so listeners stay hidden until you add -a. The -n flag also speeds the output considerably, because netstat stops trying to resolve every address.

Find a Port With findstr and Confirm Its Local Address

On a busy server, netstat -ano prints hundreds of lines. Pipe it through findstr to isolate one port:

netstat -ano | findstr :3389

Sample output:

  TCP    0.0.0.0:3389      0.0.0.0:0         LISTENING       1144
  TCP    [::]:3389         [::]:0            LISTENING       1144
  UDP    0.0.0.0:3389      *:*                               1144

The :3389 match also catches ports like 33890, so read the local address column to confirm the exact port. Here, PID 1144 listens on every IPv4 and IPv6 address for TCP and UDP, which is normal for the RDP port when Remote Desktop is enabled. Add LISTENING to the filter (findstr :3389 | findstr LISTENING) when you only care about listeners.

Match a PID to an Application With tasklist or Task Manager

A PID on its own tells you nothing, so resolve it:

tasklist /FI "PID eq 1144"
Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
svchost.exe                   1144 Services                   0     12,480 K

When the result is svchost.exe, add /SVC to see which Windows services run inside that host process:

tasklist /SVC /FI "PID eq 1144"

In Task Manager, open the Details tab and sort by the PID column. Right-click the process and choose Open file location to see the executable path, which helps when two programs share a generic name like node.exe or java.exe.

Show Executable Names With netstat -b

The -b flag skips the PID lookup and prints the executable directly under each line. From an elevated prompt:

netstat -anob
  TCP    0.0.0.0:443       0.0.0.0:0      LISTENING       4
 Can not obtain ownership information
  TCP    0.0.0.0:5432      0.0.0.0:0      LISTENING       3812
 [postgres.exe]

Microsoft notes that -b can be time-consuming and will fail unless you have sufficient permissions. PID 4 is the System process, which means the kernel-mode HTTP.sys driver owns port 443; check netsh http show servicestate to find which application registered that URL.

How Do You Read Addresses, Ports, and Socket States?

A network administrator views a diagram of connected devices on a computer monitor.

Each netstat line describes one socket: the protocol, a local IP address and port, a foreign address and port, and for TCP a connection state. Reading the local address correctly tells you who can connect, and the state tells you where the conversation stands.

Read an Annotated TCP and UDP Output Example

Here is a trimmed netstat -ano from a Windows host running a web server and a local database:

  Proto  Local Address          Foreign Address        State           PID
  TCP    0.0.0.0:80             0.0.0.0:0              LISTENING       2210   (1)
  TCP    127.0.0.1:5432         0.0.0.0:0              LISTENING       3812   (2)
  TCP    192.168.1.20:80        203.0.113.45:51822     ESTABLISHED     2210   (3)
  TCP    192.168.1.20:52114     140.82.112.4:443       TIME_WAIT       0      (4)
  TCP    [::]:80                [::]:0                 LISTENING       2210   (5)
  UDP    0.0.0.0:5353           *:*                                    1980   (6)
  1. The web server accepts TCP connections on port 80 on every IPv4 interface.
  2. PostgreSQL accepts connections only from the machine itself.
  3. A remote client at 203.0.113.45 is connected to the web server. Your port is 80; theirs is an ephemeral port.
  4. Your machine opened an outbound HTTPS connection that has closed and is waiting out its timer. PID 0 is normal here.
  5. The same web server listens on all IPv6 interfaces.
  6. A UDP socket bound for mDNS. UDP is connectionless, so the state column stays blank.

A quick rule for client versus server roles: if the local port is a well-known service port and the foreign port is high, you are the server. If the local port is high and the foreign port is 443 or 80, you are the client.

Understand LISTENING, ESTABLISHED, TIME_WAIT, and CLOSE_WAIT

Four states cover most troubleshooting work:

State Meaning When to worry
LISTENING A process waits for new TCP connections When the expected service is missing, or an unexpected one is present
ESTABLISHED Data can flow both ways When counts climb without matching user load
TIME_WAIT Your side closed first and holds the socket briefly Thousands of them can exhaust ephemeral ports on busy clients
CLOSE_WAIT The remote side closed; your application has not Growing counts point to an application that leaks sockets

CLOSE_WAIT is the one that signals a code bug. The kernel has done its part, and the socket sits there until the owning process calls close, so restarting the service clears it temporarily while the leak returns. You will also see transient states such as SYN_SENT (your outbound connection gets no reply, often a firewall drop) and SYN_RECEIVED.

Interpret Loopback, Wildcard, IPv4, and IPv6 Listening Addresses

The local address of a listener decides which interfaces accept traffic:

Local address Who can connect
127.0.0.1:port Only processes on this machine (IPv4 loopback)
[::1]:port Only this machine (IPv6 loopback)
0.0.0.0:port Any IPv4 interface
[::]:port Any IPv6 interface; on dual-stack Linux, often IPv4 too
192.168.1.20:port Only traffic arriving on that one address

A service bound to 127.0.0.1 will never answer a remote client, regardless of firewall rules. This is the most common reason a freshly installed database or dev server works locally and fails from another host. If a service listens only on [::] and IPv4 clients fail, check its dual-stack setting; the differences between IPv4 and IPv6 addressing explain why one family can succeed while the other fails.

Why a Local Listener Does Not Prove External Reachability

A LISTENING line proves one thing: a process asked the operating system to accept connections on that address and port. Netstat reads the local socket table, and it is not affected by your firewall configuration, so it reports the listener even when every inbound packet is dropped.

Between the socket and a remote client sit the host firewall, any network firewall or security group, NAT or port forwarding on the router, and the ISP. Any one of them can block the path. To confirm reachability, test from outside with an open port checker, or from another internal host with Test-NetConnection server -Port 443.

Which Windows Flags Help Diagnose Network Problems?

An IT professional examines network connection data on a computer monitor.

Beyond -ano, Windows netstat commands can filter by protocol, refresh on a timer, show routing tables, and dump protocol and Ethernet counters. These flags turn a one-off socket snapshot into evidence about drops, retransmits, and path selection.

Filter Protocols With netstat -p and Refresh Output at Intervals

On Windows, -p selects a protocol: tcp, udp, tcpv6, or udpv6.

netstat -ano -p tcp

Add a number at the end to repeat the output every N seconds until you press Ctrl+C:

netstat -ano -p tcp 5 | findstr :443

Interval mode is useful when you want to watch a connection move from SYN_SENT to ESTABLISHED, or to see whether CLOSE_WAIT counts keep climbing during a load test. Redirect it to a file (> sockets.txt) for longer captures.

Choose Numeric Addresses or Fully Qualified Domain Names

The -n flag prints raw IPs and port numbers, which is faster and easier to filter. The -f flag does the opposite for foreign addresses, showing the fully qualified domain name (FQDN) of each remote host:

netstat -f
  TCP    192.168.1.20:52200    lb-140-82-112-4-iad.github.com:https    ESTABLISHED

Use -f when you want to identify which cloud service or CDN a process talks to. Expect it to run slowly, because each address triggers a reverse DNS lookup, and some hosts return only generic PTR names.

Inspect Bound Nonlistening TCP Ports With netstat -q

The -q flag lists all connections, listeners, and bound nonlistening TCP ports. A bound nonlistening port belongs to a socket that reserved a port but is neither listening nor fully connected.

netstat -anoq | findstr BOUND

These entries explain the confusing case where an application reports “address already in use” yet netstat -ano shows nothing on that port. Microsoft’s own example combines everything into netstat -anobq for a complete view with PIDs and executables.

Read Routing Tables With netstat -r

netstat -r prints the IP routing table, the same output as route print. The key lines are in the IPv4 section:

Network Destination        Netmask          Gateway       Interface  Metric
          0.0.0.0          0.0.0.0      192.168.1.1   192.168.1.20     25
          0.0.0.0          0.0.0.0         10.8.0.1       10.8.0.6     5

Two default routes appear here, and the one with the lower metric (the VPN at 10.8.0.1) wins. When traffic takes an unexpected path, check the metrics first, then confirm the gateway matches your router IP address for the physical network.

Compare Protocol and Ethernet Statistics With netstat -s and netstat -e

netstat -s prints counters per protocol, and netstat -e prints interface byte and packet totals. Combine them, and narrow by protocol if needed:

netstat -e -s
netstat -s -p tcp

Watch these lines in the TCP section:

  • Segments Retransmitted: rising fast relative to segments sent points to packet loss on the path.
  • Reset Connections: high counts suggest a firewall or application rejecting sessions.
  • Failed Connection Attempts: outbound connections that never completed.

In -e output, nonzero Errors or Discards on received packets point at the local NIC, driver, or cabling. Run the command twice a minute apart and compare deltas, since the counters accumulate from boot.

Check NetworkDirect Connections With netstat -x Where Supported

netstat -x lists NetworkDirect connections, listeners, and shared endpoints. NetworkDirect is the Windows RDMA interface used by high-performance features such as SMB Direct and Storage Spaces Direct on Windows Server with RDMA-capable adapters.

On a typical workstation the command returns an empty table, which is expected. On a Hyper-V or storage cluster, an empty table where you expect SMB Direct sessions means traffic has fallen back to regular TCP, and throughput drops accordingly.

What Changes on Linux, macOS, and PowerShell?

Netstat exists on Linux and macOS too, but the flags differ and some letters mean different things. Modern Linux favors ss and ip, macOS leans on lsof for process ownership, and Windows PowerShell offers Get-NetTCPConnection for scriptable output.

Use Linux netstat -tulnp and Understand the Different Meaning of -p

On Linux, the standard listener check is:

sudo netstat -tulnp
Flag Linux meaning
-t / -u TCP / UDP sockets
-l Listening sockets only
-n Numeric output
-p Show PID and program name

Note the trap: on Linux, -p shows the owning process, while on Windows -p selects a protocol. Sample output:

Proto Local Address    Foreign Address  State   PID/Program name
tcp   0.0.0.0:3306     0.0.0.0:*        LISTEN  3686/mysqld
tcp6  :::443           :::*             LISTEN  2218/httpd
tcp6  :::22            :::*             LISTEN  1051/sshd

Run it with sudo. Without root, the PID/Program column stays blank for sockets owned by other users.

Inspect macOS Sockets With netstat -anv and Identify Owners With lsof

macOS netstat follows BSD syntax. Filter by address family and protocol, and add -v for extra columns:

netstat -anv -p tcp | grep LISTEN

On recent macOS releases, the verbose output includes a process name and PID column; older releases omit it. For reliable ownership, use lsof:

sudo lsof -nP -iTCP -sTCP:LISTEN
sudo lsof -nP -iTCP:8080

The -nP pair keeps hosts and ports numeric. Note that macOS uses a dot before the port in netstat (*.8080, 127.0.0.1.5432) where Linux and Windows use a colon.

Use ss and ip When Linux net-tools Is Missing

On many current distributions, netstat: command not found means the net-tools package is absent. You can install it, or use the tools that replaced it:

Old netstat Modern equivalent
netstat -tulnp sudo ss -tulnp
netstat -ant ss -ant
netstat -rn ip route
netstat -i ip -s link

ss reads socket data directly from the kernel and filters by state natively, for example ss -tn state established '( dport = :443 )'. On servers with tens of thousands of sockets, it returns noticeably faster than netstat.

Query Windows TCP Connections With Get-NetTCPConnection

PowerShell returns objects you can filter and join. List listeners with their owning process:

Get-NetTCPConnection -State Listen |
  Select-Object LocalAddress, LocalPort, OwningProcess,
    @{n='Process';e={(Get-Process -Id $_.OwningProcess).ProcessName}} |
  Sort-Object LocalPort

Check one port:

Get-NetTCPConnection -LocalPort 443 -ErrorAction SilentlyContinue

For UDP, use Get-NetUDPEndpoint. Object output makes it easy to export to CSV, compare snapshots, or alert when a new listener appears, which plain netstat text handles poorly.

How Do You Turn Socket Evidence Into a Troubleshooting Plan?

Treat netstat output as evidence about the local host, then run targeted tests for everything beyond it. The steps below follow the order in which most failures reveal themselves: socket ownership, binding, network path, and finally intent.

Investigate Port Conflicts Without Blindly Terminating Processes

When a service fails with “address already in use,” identify the owner before killing anything. taskkill /PID 4 /F will fail, and terminating a svchost.exe instance can stop several unrelated Windows services at once.

A safer sequence:

  1. Find the PID with netstat -ano | findstr :8080.
  2. Resolve it with tasklist /SVC /FI "PID eq <pid>".
  3. Stop the owning service or application through its normal method (Stop-Service, systemctl stop, or the app itself).
  4. If both programs need to run, change one of them to a different port in its configuration.
  5. Rerun netstat to confirm the port is free before starting the intended service.

Also check for Windows excluded port ranges with netsh int ipv4 show excludedportrange protocol=tcp. Hyper-V and WSL reserve blocks of ports that no process appears to own.

Separate Binding Problems From Firewall, NAT, and Routing Failures

Work outward from the socket and stop at the first layer that fails:

Observation Likely layer
No LISTENING line for the port Service not running or misconfigured
Listener on 127.0.0.1 only Binding: change the bind address
Listener on 0.0.0.0, local curl works, LAN test fails Host firewall
LAN test works, internet test fails NAT/port forwarding or upstream firewall
Client stuck in SYN_SENT Packets dropped somewhere on the path
Wrong default route in netstat -r Routing table or VPN metric

On Windows, Test-NetConnection host -Port 443 gives a quick TcpTestSucceeded result from any other host on the network, which isolates the host firewall from the network path.

Correlate Local Results With PacketTools DNS, Ping, Traceroute, and TLS Checks

Once netstat confirms the right process listens on the right address, test the path from outside. A ping test confirms basic reachability and latency, though many hosts block ICMP, so a failed ping alone is not a verdict.

When packets stall partway, trace the route to see which hop stops responding. If clients connect to the wrong address entirely, the netstat listener is fine and the fault sits in name resolution, so troubleshoot DNS issues by comparing the record clients receive against the server’s real IP.

For HTTPS services, an ESTABLISHED socket followed by an immediate close usually means a certificate or TLS version mismatch. The PacketTools SSL/TLS Checker shows the certificate chain and protocols the server presents, and PacketTools logs none of the IPs or queries you test.

Assess Unexpected Connections Without Treating netstat as a Malware Detector

An unfamiliar ESTABLISHED connection deserves investigation, not panic. Most turn out to be update services, telemetry, sync clients, or browser processes talking to CDNs.

Check in this order: resolve the PID to an executable path, confirm the file’s digital signature (Properties > Digital Signatures on Windows), look up who owns the foreign IP, and check whether the connection repeats on a schedule. A signed binary in Program Files talking to its vendor’s address range is routine.

Netstat reads what the operating system reports, and rootkit-level malware can hide sockets from that view. Anything suspicious belongs in your endpoint security tools and network flow logs, where a compromised host cannot edit the evidence.

Confirm the Process, Then Test the Network Path

Netstat answers one question precisely: which process owns which socket, on which address, in which state. On Windows, netstat -ano plus tasklist gets you there; on Linux, sudo netstat -tulnp or ss -tulnp; on macOS, netstat -anv with lsof -nP -iTCP.

Read the local address before anything else. A listener on 127.0.0.1 will never accept remote clients, while 0.0.0.0 or [::] means the socket side is ready. Watch for CLOSE_WAIT buildup as an application bug and SYN_SENT as a sign of dropped packets.

From there, move outward: host firewall, NAT, routing table, DNS, and TLS. Run your external port, ping, traceroute, and certificate checks only after netstat confirms the correct process holds the port on the correct address.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *