Install netstat
If netstat answers "command not found", install net-tools:
sudo apt install net-tools # Ubuntu, Debian
sudo dnf install net-tools # AlmaLinux, Rocky LinuxThe package also brings back ifconfig, route, and arp. net-tools is considered legacy, so for new scripts use ss and ip, which come with iproute2 on current systems; the netstat man page itself calls the program mostly obsolete. netstat stays useful when you follow older documentation or your hands still know its options.
List Listening Ports
sudo netstat -tulpn- -t: TCP sockets.
- -u: UDP sockets.
- -l: listening sockets only.
- -p: PID and program name; needs root to show other users' processes.
- -n: numeric addresses and ports, no name lookups.
Example output:
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 812/sshd
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 990/mariadbd
tcp6 0 0 :::80 :::* LISTEN 1022/apache20.0.0.0 means every IPv4 address, 127.0.0.1 only the server itself, and ::: every IPv6 address. A tcp6 line on ::: often accepts IPv4 connections as well. To find the program on one port, add a filter: sudo netstat -tulpn | grep :80.
All Connections
sudo netstat -tanp-a shows listening and connected sockets together. The State column reads ESTABLISHED for open connections, TIME_
netstat -tan | grep -c ESTABLISHEDRouting Table
netstat -rnThe line with destination 0.0.0.0 and a gateway address shows the default route. See what is a default gateway.
Interface Statistics
netstat -iShows packets received and sent per interface, with error and drop counters in the RX-ERR, RX-DRP, TX-ERR, and TX-DRP columns. Rising errors point to a link problem; drops can mean the server is too busy to take packets in.
Protocol Statistics
netstat -sPrints totals per protocol since boot: segments retransmitted, failed connection attempts, resets sent, and more. The totals alone say little; run it twice a few minutes apart and compare the numbers that grew.
netstat and Its Replacements
| netstat | Replacement |
|---|---|
netstat -tulpn | ss -tulpn |
netstat -tanp | ss -tanp |
netstat -rn | ip route |
netstat -i | ip -s link |
netstat -s | nstat -az |
netstat -g | ip maddr |
ss takes most of the same letters, so ss -tulpn works as a direct swap. It is faster on servers with many connections and has filters by state and port that netstat lacks; see the ss command guide. The ip command is covered in ip command with examples.
Common Problems
- A dash instead of a program name: run the command with sudo; without root,
-pcannot see other users' processes. - Slow output: without
-n, netstat looks up every address and port by name. Add it. - Watch it change:
netstat -crepeats the output every second until Ctrl+C; with ss, runwatch ss -sfor a running summary. - A port in use, no program shown: the socket may belong to the kernel or a container; lsof and ss give a second view.
Updated:
Linux VPS with Full Root Access
MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.
More Guides
No Limits on Service or Support
You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

- 100% customer satisfaction goal
- Our own hardware
- 24/7 ticket and email support
- 4 countries with locations