Skip to main content

netstat command

Detailed Explanation

netstat (network statistics) is a command-line tool that displays network connections for the Transmission Control Protocol (both incoming and outgoing), routing tables, and a number of network interface and network protocol statistics. It is largely considered obsolete in modern Linux and replaced by the ss and ip commands.

Basic Syntax

netstat [options]

Common Flags/Options

OptionDescription
-tShow TCP connections.
-uShow UDP connections.
-lShow only listening sockets.
-nShow numerical addresses instead of trying to determine symbolic host, port or user names.
-pShow the PID and name of the program to which each socket belongs.

Real-world Examples

Display all active listening ports:

netstat -l

Display all listening TCP ports and their associated processes:

sudo netstat -tlnp

Display all listening UDP ports:

netstat -ulnp

Display the kernel routing table:

netstat -rn

Display network interface statistics:

netstat -i