netstat Command Guide for the Classic Network Snapshot
netstat (“network statistics”) prints connection tables, routing tables, and interface counters — the long-time standard network tool that ss and ip modernized.
What is netstat, and Why Use It?
netstat takes a full snapshot of a machine’s network stack: every open connection, every listening port, the routing table, interface traffic counters, and masquerade connections. For decades it was the answer to “what is this machine doing on the network?”
It is being superseded by ss and ip — those tools are faster and still maintained — but netstat remains valuable for three reasons:
- It is everywhere. Every old server, tutorial, and troubleshooting guide uses
netstat, and understanding its output is required reading. - It sometimes shows things newer tools hide — notably per-interface traffic statistics and multicast group membership.
- Habit and speed — on a machine without
iproute2,netstatis often the only option.
Why Learn netstat?
- You will meet it in the wild — admin guides, forums, and incident writeups assume you recognize
netstat -tulpn. - It teaches the concepts — its output format is what
ssinherited; learn one and you know the other. - Some output has no modern twin — interface statistics and multicast memberships are still clearest here.
netstatships in the deprecatednet-toolspackage on many distributions — install it when you need it, but preferssfor new work.
1. Seeing Connections
The default invocation lists all connections:
netstat
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 192.168.1.20:52144 93.184.216.34:443 ESTABLISHED
tcp 0 0 192.168.1.20:52100 151.101.1.69:443 TIME_WAIT
Each row: protocol, queue sizes, local and foreign addresses, and connection state. The default view hides listening ports; the useful flags are next.
2. The Flags You Will Actually Use
The classic combinations:
netstat -t # TCP connections
netstat -u # UDP
netstat -l # listening sockets (no remote side)
netstat -a # everything — listening and connected
netstat -n # numeric addresses, no DNS lookups (fast)
The famous one combines them all:
netstat -tulpn
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 541/sshd
tcp6 0 0 :::22 :::* LISTEN 541/sshd
udp 0 0 0.0.0.0:68 0.0.0.0:* 412/dhclient
What each letter adds:
-t/-u— TCP / UDP sockets.-l— listening sockets only.-p— the PID and program name owning each socket (needs root for other users).-n— skip DNS resolution; addresses and ports stay numeric.
netstat -tulpn is the command for “what is this machine offering on the network?” — the same job ss -tulpn does.
3. Routing and Interfaces
Beyond sockets, netstat shows the rest of the network stack:
netstat -r # the kernel routing table
netstat -rn # routing table, numeric (fast)
netstat -i # per-interface statistics: packets, errors, collisions
netstat -g # multicast group memberships
netstat -I # interface configuration (older flag styles vary)
netstat -i is where netstat still wins:
Iface MTU RX-OK RX-ERR RX-DRP TX-OK TX-ERR
lo 0 15234 0 0 15234 0
eth0 0 98321 0 0 54321 0
Receive/transmit packet counts and errors per interface — quick answers to “is this interface dropping packets?”.
4. Counting Connections
To see what is hammering a machine by protocol and state:
netstat -t | awk '{print $6}' | sort | uniq -c | sort -rn
312 TIME_WAIT
12 ESTABLISHED
8 CLOSE_WAIT
This counts connection states for TCP — a rising TIME_WAIT count means many short-lived connections (normal for web servers), while growing CLOSE_WAIT means the local program is not closing its sockets (a bug worth chasing).
5. The Modern Equivalents
netstat is deprecated in favor of its replacements. The mapping:
| Old command | Modern replacement |
|---|---|
netstat -tulpn | ss -tulpn |
netstat -r | ip route |
netstat -i | ip -s link |
netstat -s | nstat or ip -s |
When a tutorial says netstat, mentally substitute ss — the output is nearly identical, and ss is faster on busy machines.
Common Pitfalls
- It may not be installed —
netstatlives in the deprecatednet-toolspackage; on newer systems you may needsudo apt install net-tools(or thednf/pacmanequivalent) before it exists at all. -pneeds root to see everything — without sudo, process names for other users’ sockets are blank.- Slow output without
-n— DNS lookups for every address can hang the command; add-nwhenever speed matters. - Confusing
netstat -ierrors with problems — RX-DRP and TX-ERR counts are cumulative since boot; only increasing counts indicate a live issue.
Related Pages
| Page | Relationship |
|---|---|
| ss | The modern replacement — prefer it for new work |
| ip | Modern replacement for interface and routing views |
| ping | Tests whether a listed address is reachable |
| lsof | Shows which files and sockets a process has open |
netstat Cheatsheet
| Command | What it does |
|---|---|
netstat | List all connections |
netstat -t | TCP connections |
netstat -tuln | Listening TCP/UDP ports, numeric |
netstat -tulpn | Listening ports with owning process (as root) |
netstat -r | Kernel routing table |
netstat -rn | Routing table, numeric |
netstat -i | Per-interface packet and error statistics |
netstat -g | Multicast group memberships |
netstat -t | awk '{print $6}' | sort | uniq -c | Count connection states |