The netstat command shows network sockets, routing information and interface counters on Linux. It can help identify listening services and inspect current connections; it does not record a history of network activity.

Install netstat if needed

netstat is supplied by the net-tools package. Use the command for your distribution:

# Debian or Ubuntu
sudo apt install net-tools

# Supported distributions using DNF
sudo dnf install net-tools

# Arch Linux: this also performs a full system upgrade
sudo pacman -Syu net-tools

Review the proposed package changes before accepting them. On modern Linux systems, ss is usually available as an alternative.

Inspect sockets

Show listening TCP and UDP sockets with numeric addresses and ports:

sudo netstat -lntup

Show listening sockets and active TCP or UDP connections:

sudo netstat -antup

Here, -l selects listening sockets, -a includes all sockets, -n avoids name lookups, -t and -u select TCP and UDP, and -p shows the associated process where permissions allow. Administrator access is needed to see details for other users’ processes.

Inspect routing and interfaces

netstat -rn
netstat -i

The first command shows the routing table without name lookups. The second shows interface counters, which are a snapshot rather than a bandwidth report.

For listening sockets with the newer tool, use:

sudo ss -lntup