netstat — Network Connections and Statistics at a Glance
Practical guide to netstat — active connections, listening ports, routing table and interface statistics, with the most common option combinations.
netstat is the classic tool for inspecting active connections, listening ports, the kernel routing table, and interface statistics from the command line. It runs on Linux, macOS, and Windows and ships pre-installed on many systems. On modern Linux distributions, ss from the iproute2 package is the designated successor – faster and actively maintained. For quick cross-platform diagnostics, however, netstat remains the familiar first port of call.
Connection Listing
netstat — Show all active connections (TCP and Unix sockets).
netstatnetstat -a — Show all connections and listening ports.
netstat -anetstat -l — Show only listening sockets.
netstat -lnetstat -t — Show TCP connections only.
netstat -tnetstat -u — Show UDP connections only.
netstat -unetstat -x — Show Unix domain sockets only.
netstat -xnetstat -w — Show RAW sockets.
netstat -wDisplay Options
netstat -n — Numeric output — show IP addresses and port numbers instead of names.
netstat -nnetstat -p — Show PID and program name for each connection (requires root).
sudo netstat -pnetstat -e — Show extended information (user, inode).
netstat -enetstat -o — Show timer information.
netstat -onetstat -c — Continuously refresh the output every second.
netstat -cnetstat --wide — Do not truncate IP addresses in output.
netstat --wideCommon Combinations
netstat -tlnp — Show TCP listening ports with port numbers and processes. Most common usage.
sudo netstat -tlnpnetstat -tulnp — Show all TCP and UDP listening ports with processes.
sudo netstat -tulnpnetstat -tanp — Show all TCP connections with port numbers and processes.
sudo netstat -tanpnetstat -anp — Show all connections with numeric addresses and process info.
sudo netstat -anpnetstat -ltpe — Show listening TCP ports with processes and extended info.
sudo netstat -ltpeRouting Table
netstat -r — Show the kernel routing table.
netstat -rnetstat -rn — Show the routing table with numeric addresses (no DNS).
netstat -rnInterface Statistics
netstat -i — Show a table of all network interfaces with statistics.
netstat -inetstat -ie — Show interfaces with extended info (similar to ifconfig).
netstat -ienetstat -I INTERFACE — Show statistics for a specific interface.
netstat -I eth0Protocol Statistics
netstat -s — Show protocol statistics (TCP, UDP, ICMP, IP).
netstat -snetstat -st — Show TCP statistics only.
netstat -stnetstat -su — Show UDP statistics only.
netstat -suMulticast
netstat -g — Show multicast group memberships.
netstat -gPractical Examples
netstat -tlnp | grep :80 — Find which process is listening on port 80.
sudo netstat -tlnp | grep :80netstat -an | grep ESTABLISHED | wc -l — Count established connections.
netstat -an | grep ESTABLISHED | wc -lnetstat -an | grep TIME_WAIT | wc -l — Count TIME_WAIT connections.
netstat -an | grep TIME_WAIT | wc -lnetstat -tn | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -rn | head — Show top remote IPs by connection count.
netstat -tn | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -rn | headnetstat -an | awk '/tcp/ {print $6}' | sort | uniq -c | sort -rn — Show count of connections by TCP state.
netstat -an | awk '/tcp/ {print $6}' | sort | uniq -c | sort -rnnetstat -tulnp | grep -v 127.0.0.1 | grep -v ::1 — Show listening ports accessible from outside (not localhost-only).
sudo netstat -tulnp | grep -v 127.0.0.1 | grep -v ::1 Conclusion
For quick diagnostics – which process is listening on port 80, how many established connections are open, what does the routing table say? – netstat is still a solid first choice. On modern Linux systems, get familiar with ss: it delivers the same information faster and exposes TCP-internal state that netstat hides.
Further Reading
- netstat – Wikipedia – background and history
- netstat(8) – Linux man page – complete option reference