Skip to main content

netstat Cheatsheet

By Dejan Panovski Updated on Download PDF

Quick reference for listing network connections, listening ports, routes, interface counters, and protocol statistics with netstat

The `netstat` command shows network connections, listening ports, routing tables, interface counters, and protocol statistics on Linux. This cheatsheet covers the most useful `netstat` flags and common troubleshooting patterns.

Basic Syntax

Core netstat command forms and output controls.

CommandDescription
netstatShow active non-listening sockets
sudo netstat -aShow all sockets
sudo netstat -nShow numeric addresses and ports
sudo netstat -pShow PID and program name where available
sudo netstat -cRefresh output every second

Listening Ports

Find services that are accepting local connections.

CommandDescription
sudo netstat -tulnShow TCP and UDP listening sockets
sudo netstat -tulnpShow listening sockets with PID and process name
sudo netstat -tnlpShow listening TCP sockets only
sudo netstat -unlpShow listening UDP sockets only
sudo netstat -tulnp | grep ':80'Find the process listening on port 80

Connections and TCP States

Inspect active connections and common TCP states.

CommandDescription
sudo netstat -atShow all TCP sockets
sudo netstat -auShow all UDP sockets
sudo netstat -antShow TCP sockets with numeric addresses
sudo netstat -ant | grep ESTABLISHEDShow established TCP connections
sudo netstat -ant | grep TIME_WAITShow TCP connections in TIME_WAIT
sudo netstat -atncWatch TCP connection output continuously

Counts and Filters

Use shell filters with netstat output.

CommandDescription
sudo netstat -ant | wc -lCount TCP output rows
sudo netstat -ant | grep ':80' | wc -lCount TCP connections involving port 80
sudo netstat -ant | grep ESTABLISHED | wc -lCount established TCP connections
sudo netstat -tulnp | grep nginxFind sockets owned by nginx
sudo netstat -ant | grep 203.0.113.10Filter connections by remote IP address

Routes, Interfaces, and Stats

Show routing, interface, and protocol information.

CommandDescription
netstat -rnShow the routing table with numeric addresses
netstat -rShow the routing table with name resolution
netstat -iShow interface counters
netstat -ieShow extended interface details
netstat -sShow protocol statistics
netstat -stShow TCP protocol statistics
netstat -suShow UDP protocol statistics

Modern Replacements

Use current Linux tools for new workflows and scripts.

netstat CommandModern Command
netstat -tulnss -tuln
sudo netstat -tulnpsudo ss -tulnp
netstat -rnip route
netstat -iip -s link
netstat -sss -s

Troubleshooting

Common netstat issues and quick fixes.

IssueCheck
netstat: command not foundInstall the net-tools package or use ss
Process column is emptyRun with sudo when using -p
Output is slowAdd -n to disable name resolution
Port lookup matches too muchSearch with a colon, such as grep ':80'
Need listeners onlyAdd -l with protocol flags such as -tuln

Use these guides for full walkthroughs and modern alternatives.

GuideDescription
netstat Command in LinuxFull netstat guide with examples
ss Command in LinuxModern socket inspection tool
ip Command in LinuxModern routes and interface management
How to Check Listening Ports in LinuxCompare ss, netstat, and lsof
lsof Command in LinuxTie sockets and files back to processes