netstat
(network statistics) is a command-line tool that provides detailed information about active network connections, ports in listening mode, protocol activity (TCP, UDP, ICMP), and routing tables. It’s part of the deprecated net-tools
package and often replaced by the newer ss
utility in modern Linux systems.
If not already installed, use your package manager:
sudo apt install net-tools # Debian / Ubuntu
sudo yum install net-tools # CentOS / RHEL
netstat [options]
Example: show active connections:
netstat -tuln
Option | Description | Example |
---|---|---|
-t | Show TCP connections |
|
-u | Show UDP connections |
|
-l | Show listening ports |
|
-n | Do not resolve hostnames |
|
-p | Show PID and program name |
|
-a | Show all connections |
|
-r | Show routing table |
|
-s | Show protocol statistics |
|
To view listening ports with process info:
netstat -tulnp
Sample output:
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 1234/mysqld
Modern Linux systems use ss
for faster, richer socket inspection:
ss -tuln
ss -p
-p
to identify which process owns a port-n
to improve performancenetstat
remains a valuable tool for network diagnostics, despite being replaced by ss
in many distributions. Its ability to list open ports, view process associations, and display routing information makes it essential for system administrators. Mastering netstat
builds a strong foundation for managing Linux network security and performance.