Updated 8 hours ago
Your computer is having conversations you don't know about. Right now, dozens of connections are open—some you initiated, some that services opened on your behalf, and possibly some you'd rather not have. netstat shows you all of them.
Every open port is a door. netstat shows you which doors exist, which are open, and who's walking through them.
The Essential Command
Forget the basic netstat command—it's nearly useless. This is what you actually want:
This shows every TCP port listening for connections, with the program responsible:
Three services, three open doors:
- SSH on port 22, accepting connections from anywhere (0.0.0.0)
- MySQL on port 3306, but only from localhost (127.0.0.1)—smart
- Nginx on port 80, accepting connections from anywhere
The flags:
-t: TCP only (add-ufor UDP)-l: Listening ports only-n: Show numbers, not names (much faster—no DNS lookups)-p: Show the program (requires sudo)
See Active Connections
Shows every TCP connection, including who you're connected to:
Your machine is connected to two remote hosts and recently finished talking to a third.
Connection States (What They Actually Mean)
LISTEN: A door is open, waiting for someone to knock.
ESTABLISHED: Active conversation. Data is flowing.
SYN_SENT: You knocked. Waiting to see if anyone's home.
TIME_WAIT: The conversation ended, but you're waiting a moment to make sure the goodbye was heard. Normal. You'll see lots of these.
CLOSE_WAIT: The other side hung up, but your program hasn't closed the connection yet. Many of these might indicate a buggy application.
FIN_WAIT: You said goodbye, waiting for acknowledgment.
Finding Things
Is anything listening on port 80?
What's using port 3000?
All connections to a specific IP:
What's Firefox connected to?
Security: Who Left the Door Open?
Find everything listening on all interfaces:
Services bound to 0.0.0.0 accept connections from anywhere on the network. Make sure that's intentional.
Find unexpected listeners:
Everything not bound to localhost. Review the list. Recognize every program?
Count connections by state:
Routing Table
Shows where packets go:
Default gateway is 192.168.1.1. Local traffic (192.168.1.x) goes directly out eth0.
Interface Statistics
Errors and drops should be zero or near-zero. Non-zero values indicate hardware problems or network congestion.
Protocol Statistics
Shows packet counts, retransmissions, errors—useful for diagnosing network problems at the protocol level.
Platform Notes
Linux: Full features. On modern systems, ss is faster but netstat is more familiar.
macOS: Similar flags, but -p may not show program names.
Windows: Use netstat -ano to see process IDs, then match them in Task Manager. Use -b (as administrator) to see executable names.
netstat vs. ss
On Linux, ss is the modern replacement—faster and more powerful. The syntax is nearly identical:
netstat still matters because it works everywhere and everyone knows it.
Quick Reference
| Command | Shows |
|---|---|
netstat -tlnp | Listening TCP ports with programs |
netstat -ulnp | Listening UDP ports with programs |
netstat -ant | All TCP connections |
netstat -rn | Routing table |
netstat -i | Interface statistics |
netstat -s | Protocol statistics |
Always use -n to avoid slow DNS lookups. Use sudo to see program names.
Frequently Asked Questions About netstat
Was this page helpful?