netstat to ss Mapping
netstat is deprecated on Linux; ss is the replacement and takes the same flag letters for the common cases. The last two rows moved to instead.
| netstat | ss / ip | What it shows |
|---|---|---|
| Listening TCP ports with the owning process | ||
| Listening UDP ports with the owning process | ||
| Both, one table | ||
| All sockets, listening and connected | ||
| Current TCP connections, numeric | ||
| Summary statistics by protocol | ||
| Routing table | ||
| Interfaces with packet and error counters |
The letters mean: TCP, UDP, listening only, numeric (skip DNS, always worth it), process info (needs for other users' processes), all.
Listening Ports
| Command | What it does |
|---|---|
| Every listening TCP port and who owns it | |
| Is something on port 80 | |
| Same, filtered by ss itself | |
| TCP and UDP listeners together | |
| Listening sockets without process info (no sudo needed) | |
| Which port is sshd actually on |
If a port shows a listener bound to , it only accepts local connections; or means all interfaces. To test a port from the outside instead, use the SSH port checker.
Established Connections
| Command | What it does |
|---|---|
| All current TCP connections | |
| Only live connections | |
| Live connections with the owning process | |
| Outbound HTTPS connections | |
| Connections to one host | |
| How many sockets in TIME_WAIT |
Recipes:
# Who is connected to my web server right now, by IP:
ss -tn state established '( sport = :443 or sport = :80 )'
# Count connections by state (spot SYN floods and CLOSE_WAIT leaks):
ss -tan | awk 'NR>1 {print $1}' | sort | uniq -c | sort -rn
# Count established connections per client IP:
ss -tn state established | awk 'NR>1 {split($5,a,":"); print a[1]}' | sort | uniq -c | sort -rnss Filters
ss filters sockets itself, no grep needed. Quote the expression, and put spaces around the parentheses and operators.
| Command | What it does |
|---|---|
| Filter by state (, , , also work) | |
| By destination port | |
| By source (local) port | |
| Either port | |
| Connections to a subnet | |
| Port comparisons work too | |
| Kill matching connections (kernel support required) |
Routing Table and Stats
The parts of netstat that ss does not cover, and their modern forms.
| Command | What it does |
|---|---|
| Routing table (); the line is your gateway | |
| Which route and interface a destination would use | |
| Interfaces with RX/TX and error counters () | |
| Socket totals by state and protocol ( is more detailed) | |
| Full per-protocol counters: retransmits, resets, ICMP (needs net-tools) |
Windows netstat
netstat is not deprecated on Windows. Run these in an elevated Command Prompt or PowerShell; is Windows grep.
| Command | What it does |
|---|---|
| All connections and listeners, numeric, with PID | |
| Filter to one port | |
| Listeners only | |
| Live connections only | |
| Name the process behind PID 4312 | |
| Show the executable name inline (needs an admin prompt, slower) | |
| Routing table | |
| Interface byte and packet counters | |
| Reprint every 5 seconds (Ctrl+C stops) | |
| Kill the process holding a port |
macOS netstat
macOS ships a BSD netstat with different flags, and no for processes ( selects a protocol instead). Use for the process view.
| Command | What it does |
|---|---|
| Listening ports | |
| TCP sockets ( for UDP) | |
| Which process is on port 8080 | |
| Every listener with its process | |
| Routing table |
Gotchas
- on a modern distro is expected: the default answer is , and brings netstat back if a script insists on it.
- Without , the column is blank for processes owned by other users, including every system service. No error, just missing names.
- Always add . Without it both tools resolve every address and port name, which is slow and turns into mid-scan.
- ss filter expressions are picky about spacing: works, does not.
- A service bound to will look fine in but be unreachable from outside. Check the Local Address column, not just the port.
- Connections you see in ss can still be invisible to clients if the firewall drops packets first. When listeners look right but connections fail, capture with tcpdump and check iptables.