netstat(8)
Display network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
Synopsis
netstat [OPTION]... [--tcp|--udp|--raw|--unix] [--listening|--all]Description
netstat displays information about the Linux networking subsystem. It shows active connections, listening ports, routing table entries, network interface statistics, and protocol statistics. Use it to diagnose network problems, monitor active connections, and verify service availability.
Note: netstat is deprecated on many modern systems; use ss, ip, and related tools instead. However, netstat remains widely used and familiar to most administrators.
Common options
| Flag | What it does |
|---|---|
-a, --all | Show both listening and non-listening sockets |
-l, --listening | Display only listening sockets (server ports) |
-n, --numeric | Show IP addresses and port numbers instead of names |
-t, --tcp | Display only TCP connections |
-u, --udp | Display only UDP connections |
-p, --program | Show the PID and name of the program owning each socket |
-r, --route | Display the kernel routing table |
-i, --interfaces | Display a table of all network interfaces |
-s, --statistics | Show summary statistics for each protocol |
-e, --extend | Display additional information (use with -i) |
-c, --continuous | Continuously refresh the display every second |
-x, --unix | Show Unix domain sockets |
Examples
List all listening TCP sockets with numeric output and associated programs (very common for checking open ports)
netstat -tlnpShow all established connections without name resolution
netstat -an | grep ESTABLISHEDFind which process is listening on port 80
netstat -tulnp | grep :80Display summary statistics for all protocols
netstat -sShow network interface statistics (packets, errors, collisions)
netstat -iDisplay the kernel routing table
netstat -rContinuously monitor network connections with numeric output, updating every second
netstat -c -nCount the number of listening ports on the system
netstat -anp | grep LISTEN | wc -l