netstat Linux Command
Displays network connections, routing tables, interface statistics, and more.
What does netstat do?
Displays network connections, routing tables, interface statistics, and more.
Syntax
netstat [options]Practical example
netstat -tulpnQuestions about netstat
How do I see all active connections?
Use `netstat -a` to display all active connections including listening sockets and TCP/UDP connections.
What does netstat -tulpn show?
`-t` shows TCP, `-u` shows UDP, `-l` shows listening ports, `-p` shows process names, `-n` shows numeric addresses (no DNS resolution).
How do I see which ports are listening?
Use `netstat -tlnp` to show all listening TCP ports with the process using each port. This is essential for checking open services.
How do I see the routing table with netstat?
Use `netstat -r` or `netstat -rn` (numeric, no DNS) to display the kernel routing table.
How do I see network interface statistics?
Use `netstat -i` to display packet counts, errors, and other statistics for each network interface.
Why is netstat deprecated?
netstat is part of the net-tools package. The `ss` command is the modern replacement that is faster and provides more socket information.
How do I install netstat?
On Debian/Ubuntu: `sudo apt install net-tools`. On RHEL/CentOS: `sudo yum install net-tools`.
How do I see connections by state?
Use `netstat -an | grep ESTABLISHED` to see only established connections. Replace ESTABLISHED with LISTEN, TIME_WAIT, etc.
Related Networking Commands
ipModern replacement for ifconfig. Shows and manipulates routing, devices, and tunnels.
ssModern replacement for netstat. Dumps socket statistics quickly.
ifconfigDisplays or configures network interface parameters (deprecated, use ip).
curlTransfers data from or to a server using various protocols (HTTP, FTP, etc.).
pingSends ICMP echo request packets to test network connectivity to a host.
wgetDownloads files from the internet non-interactively via HTTP, HTTPS, or FTP.