$linuxjunkies
>

netstat(8)

Display network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.

UbuntuDebianFedoraArch

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

FlagWhat it does
-a, --allShow both listening and non-listening sockets
-l, --listeningDisplay only listening sockets (server ports)
-n, --numericShow IP addresses and port numbers instead of names
-t, --tcpDisplay only TCP connections
-u, --udpDisplay only UDP connections
-p, --programShow the PID and name of the program owning each socket
-r, --routeDisplay the kernel routing table
-i, --interfacesDisplay a table of all network interfaces
-s, --statisticsShow summary statistics for each protocol
-e, --extendDisplay additional information (use with -i)
-c, --continuousContinuously refresh the display every second
-x, --unixShow Unix domain sockets

Examples

List all listening TCP sockets with numeric output and associated programs (very common for checking open ports)

netstat -tlnp

Show all established connections without name resolution

netstat -an | grep ESTABLISHED

Find which process is listening on port 80

netstat -tulnp | grep :80

Display summary statistics for all protocols

netstat -s

Show network interface statistics (packets, errors, collisions)

netstat -i

Display the kernel routing table

netstat -r

Continuously monitor network connections with numeric output, updating every second

netstat -c -n

Count the number of listening ports on the system

netstat -anp | grep LISTEN | wc -l

Related commands