Is netstat installed on my machine?
Often not. netstat belongs to the net-tools package, which most distributions stopped installing by default years ago in favor of iproute2, the suite that provides ss and ip. Install it if you want it:
apt install net-tools # Ubuntu, Debian dnf install net-tools # Rocky Linux, AlmaLinux, CentOS Stream
FreeBSD 14 has its own netstat in the base system, with somewhat different flags. The Linux examples below assume net-tools.
How do I list listening ports?
netstat -tulpn
The flags read as: TCP, UDP, listening sockets only, show the program, numeric addresses. Run it as root to see process names for every socket. Each line shows a local address such as 0.0.0.0:443, meaning all IPv4 addresses, or 127.0.0.1:6379, meaning loopback only. A database you thought was private showing 0.0.0.0:5432 is worth fixing at once, since every machine has a public address.
How do I see active connections?
netstat -tnp | grep ESTABLISHED | head
netstat -tn | awk 'NR>2 {print $6}' | sort | uniq -c | sort -rn
The second line counts connections by state. Thousands in TIME_WAIT on a busy web server are normal; a growing pile of CLOSE_WAIT means your application is not closing sockets, a bug worth chasing; many SYN_RECV can indicate a flood, which the edge DDoS filtering in front of every machine is designed to absorb before it reaches your port.
What else can netstat show?
| Command | Shows | Modern equivalent |
|---|---|---|
netstat -tulpn | Listening sockets with programs | ss -tulpn |
netstat -tanp | All TCP sockets | ss -tanp |
netstat -rn | Routing table | ip route |
netstat -i | Interface packet and error counters | ip -s link |
netstat -s | Protocol statistics: retransmits, resets | nstat -az |
netstat -g | Multicast group memberships | ip maddr |
Why move to ss?
Speed and detail. netstat reads text files under /proc/net and parses them, which becomes slow on machines with tens of thousands of sockets, exactly the busy proxies and APIs where you need answers fast. ss asks the kernel directly through netlink, returns quickly at any scale and adds filters by state, port and address, plus TCP internals such as round-trip time and congestion window. Its flags mirror netstat's closely, so ss -tulpn works the way your fingers expect. The full guide is The ss command.
How do I read the routing table?
netstat -rn ip route
On our machines, the default route points to the gateway on the other end of the /31 link. For example, with the address 203.0.113.25/31, the gateway is 203.0.113.24. The IPv4 on a /31 entry explains why two addresses are enough for a point-to-point link. The ip command, covered in The ip command, shows the same table with more detail.
How do I spot retransmissions?
netstat -s | grep -iE 'retrans|reset|failed' nstat -az TcpRetransSegs TcpExtTCPLostRetransmit
Growing retransmission counters point to packet loss somewhere between your machine and the client. Compare with a path test using tracepath vs traceroute or mtr to see where loss begins.
How do I watch connections change live?
Add -c to repeat the listing every second, for example netstat -tnc | grep ':443', which is crude but quick when you want to see clients arrive during a test. A cleaner modern loop is watch -n 2 'ss -s', which refreshes a compact summary of socket counts by state every two seconds without flooding the terminal.
Should I keep netstat in scripts?
For new scripts, use ss and ip; they are installed everywhere and maintained. For old scripts, net-tools still works and is packaged on every current release, so there is no rush, but expect parsing differences if you switch, since column layouts differ.
Keep Reading
The ss command
List sockets fast with ss: listening ports, filters by state, port and address, TCP internals like RTT, summaries and killing stuck sockets.
OpenThe ip command
Read addresses, links, routes and neighbors with ip, understand the /31 setup on our machines and make test changes without losing SSH.
OpenIPv4 on a /31
Why each machine gets one public IPv4 on a /31 network, how the two addresses split between gateway and server, and how to configure it.
OpenEdge DDoS filtering
How common volumetric attacks are filtered at the network edge before they reach your ports, and what you still handle on the box.
OpenFAQ
Quick Answers
It is part of net-tools, which current images do not install by default. Install it or use ss instead.
Run netstat -tulpn as root to see listening TCP and UDP ports with their programs.
ss for sockets and ip for routes and interfaces, both from iproute2.
The remote side closed the connection but your application has not. Many of them suggest a socket leak.
Run netstat -rn, or ip route on current systems.