Sockets, ports and connections: reading netstat, ss and Get-NetTCPConnection
In short: A socket is one end of a network connection: an IP address, a port and a protocol. Servers listen on well-known ports, and clients use temporary ephemeral ports. Tools such as netstat, ss and Get-NetTCPConnection list every listening port and connection with its state and owning process, which is invaluable for troubleshooting and for spotting unexpected connections.
Ports and sockets
An IP address gets traffic to the right computer; a port gets it to the right program. A socket is the combination of protocol, IP address and port that a program uses. A TCP connection is uniquely identified by four values: client IP and port, server IP and port.
- Server programs listen on a fixed port, such as 443 for HTTPS or 22 for SSH.
- Clients use an ephemeral port chosen by the operating system for each connection: 49152 to 65535 on Windows and many systems, and 32768 to 60999 by default on Linux.
TCP connection states
- LISTEN: a server waiting for connections.
- SYN_SENT: a client has sent a SYN and is waiting. Many of these to one address suggest a firewall is dropping the traffic.
- ESTABLISHED: an open connection carrying data.
- TIME_WAIT: the side that closed first waits a short time before reusing the port. Thousands of these on a busy server are normal.
- CLOSE_WAIT: the other side closed, but the local program has not. Large numbers usually mean an application bug.
Windows
netstat -ano | findstr :443
netstat -ano | findstr LISTENING
Get-NetTCPConnection -State Listen | Sort-Object LocalPort
Get-NetTCPConnection -LocalPort 3389 | Select-Object LocalAddress,RemoteAddress,State,OwningProcess
Get-Process -Id 1234
The -o option shows the process ID (PID). Match it in Task Manager's Details tab or with Get-Process to see which program owns the port.
Linux
ss -tulpn # TCP and UDP listening sockets with process names
ss -tn state established
sudo lsof -i :8080 # which process uses port 8080
ss replaces the older netstat on modern Linux. -t TCP, -u UDP, -l listening, -p process, -n numbers instead of names.
Common uses
- "Address already in use" when starting a service: find which process is already listening on that port.
- Is the service actually listening? If a web server only listens on 127.0.0.1:8080, nothing from the network can reach it.
- What is this PC talking to? List established connections and look for unexpected remote addresses, a simple first check during a security investigation.
- Running out of ephemeral ports: a proxy or NAT device making huge numbers of outbound connections can exhaust them.
Real-world example: the website that worked only on the server
A developer's new web app worked when tested on the server itself but not from any other PC. The firewall was open. ss -tulpn showed the app listening on 127.0.0.1:5000, the loopback address, not on all interfaces. Changing the app's bind address to 0.0.0.0 (and keeping the firewall rule) made it reachable.
Practice
What four values uniquely identify a TCP connection?
Which Linux command lists listening TCP and UDP sockets with the owning process?
ss -tulpn.What might many connections stuck in SYN_SENT indicate?
Key takeaways
- A socket is an IP address, port and protocol; servers listen and clients use ephemeral ports.
- Know the TCP states: LISTEN, SYN_SENT, ESTABLISHED, TIME_WAIT, CLOSE_WAIT.
- netstat -ano and Get-NetTCPConnection on Windows; ss and lsof on Linux.
- Check that services listen on the right address, not just loopback.
Original content written by Mohamed Fayas for FM TecHub. © 2026 FM TecHub. You're welcome to share a link to this page; please don't copy the text elsewhere without permission.