Cloud VPS from $1.98/mo · pay with Bitcoin, Ethereum, Monero, USDT or Solana · paid in crypto
Linux

netstat on Linux: each option and its ss or ip replacement

netstat on modern Linux: install net-tools if you must, read connection states and queues, and translate every common netstat option to ss, ip and nstat.

CloudSat teamNovember 18, 20266 min read
Abstract illustration of an old dial gauge handing its readings over to a row of sleek modern meters
On this pageIf a script needs netstat itself

netstat comes from the net-tools package, and most server images no longer install it. Typing it on a fresh Ubuntu, Debian or AlmaLinux server usually ends in "command not found". Its jobs moved to three tools from iproute2, which every distribution ships: ss for sockets, ip for interfaces, addresses and routes, and nstat for protocol counters. This guide maps each netstat habit to its replacement, explains the columns you will read, and shows how to troubleshoot connections, not just list ports.

If a script needs netstat itself

sudo apt install net-tools      # Debian and Ubuntu
sudo dnf install net-tools      # RHEL, AlmaLinux, Rocky Linux, Fedora

That brings back netstat, ifconfig, route and arp. They still work, but new kernel features show up in iproute2 first, and output formats differ slightly between the old and new tools, so update scripts when you touch them anyway.

The translation table

netstat or friend Replacement What it shows
netstat -tulpn ss -tulpn Listening TCP and UDP sockets with their processes
netstat -tan ss -tan Every TCP socket, numeric addresses
netstat -s nstat -az, or ss -s for a summary Protocol counters
netstat -r, route -n ip route, ip -6 route Routing tables
netstat -i ip -s link Packets, errors and drops per interface
netstat -g ip maddr Multicast group memberships
netstat -M conntrack -L Connections tracked by NAT
netstat -c watch -n 2 ss -s Refreshing output
ifconfig ip addr, ip -br addr Addresses per interface
arp -n ip neigh The neighbor (ARP and NDP) table

The letters mostly carry over to ss: -t TCP, -u UDP, -l listening, -a all, -n numeric, -p process (which needs sudo to show other users' processes). Finding which service owns which listening port is covered in detail in check open and listening ports; the rest of this guide is about live connections and the network around them.

Read the columns

State   Recv-Q  Send-Q   Local Address:Port    Peer Address:Port
LISTEN  0       4096           0.0.0.0:443          0.0.0.0:*
ESTAB   0       0          203.0.113.10:443    198.51.100.7:51544
ESTAB   0       38412      203.0.113.10:443    198.51.100.9:60211

The two queue columns mean different things depending on the state:

  • On a LISTEN socket, Recv-Q is the number of finished connections waiting for the application to accept them, and Send-Q is the maximum the queue may hold. A Recv-Q that stays above zero means the application is not keeping up.
  • On an ESTAB socket, Recv-Q is data that arrived but the application has not read yet, and Send-Q is data sent but not yet acknowledged by the other side. A large, stuck Send-Q, like the last line above, points at a slow client or a congested path.

Connection states worth knowing

State Meaning When to worry
ESTAB Open connection Far more than your normal traffic
SYN-SENT This machine is trying to connect Many of them: the destination is down or a firewall drops the packets
SYN-RECV A client started a connection that is not complete Thousands: a SYN flood, or clients on very bad links
TIME-WAIT Recently closed by this side, kept briefly to absorb late packets Rarely; thousands are normal on busy servers
CLOSE-WAIT The peer closed, the application has not Growing steadily: the application leaks connections
FIN-WAIT-2 This side closed, waiting for the peer Many lingering: peers that never finish closing

CLOSE-WAIT is the one that points at a bug in your own software: the kernel has done its part and is waiting for the program to call close().

Questions answered in one line

Count connections per state:

ss -Htan | awk '{print $1}' | sort | uniq -c | sort -rn

See which clients hold the most connections to your HTTPS port. With a state filter, ss drops the state column, so the peer address is the fourth field:

ss -Htn state established '( sport = :443 )' \
  | awk '{sub(/:[0-9]+$/, "", $4); print $4}' | sort | uniq -c | sort -rn | head

Find which process holds connections to a database, or which one leaks CLOSE-WAIT sockets:

sudo ss -tnp state established '( dport = :5432 )'
sudo ss -tanp state close-wait

Look inside individual connections: ss -tin adds round-trip time, congestion window and retransmission counters for each socket, and -o shows its timers. A connection with a high retrans count is losing packets somewhere along its path.

When one client holds a stuck connection that the application will not drop, ss can close it from outside, on kernels built with socket-destroy support, which most distribution kernels are:

sudo ss -tK dst 198.51.100.9 dport = :60211

Use it for a single misbehaving socket, not as a routine: the application sees an error on that connection, and it is a stopgap while you fix the cause.

Interfaces, routes and neighbors

ip -br addr                     # one line per interface with its addresses
ip -s -h link show eth0         # packets, errors and drops, in readable units
ip route                        # IPv4 routes; ip -6 route for IPv6
ip route get 1.1.1.1            # which route, interface and source address a packet would use
ip neigh                        # neighbors and their state

ip route get answers the question netstat never could: given this destination, which interface and source address will the kernel use? It settles most "why does traffic leave through the wrong interface" mysteries. In ip neigh, REACHABLE and STALE entries are normal; FAILED means a neighbor, often the gateway, did not answer.

Error and drop counters in ip -s link should stay at or near zero. Counters that climb under load point at the interface or the virtual network below it, not at your application.

Protocol counters with nstat

nstat reads the same kernel counters as netstat -s, under their kernel names:

nstat -az | grep -E 'TcpRetransSegs|TcpExtListenOverflows|TcpExtListenDrops|TcpExtTCPSynRetrans'
nstat                            # only what changed since the last run

TcpExtListenOverflows and TcpExtListenDrops count connections lost because an accept queue was full, which matches a LISTEN socket with a busy Recv-Q. A climbing TcpRetransSegs means packets are being lost or delayed. Without options, nstat remembers its previous run and prints only the difference, which makes it easy to measure one busy minute.

Scripting with the new tools

ss -H drops the header line, which simplifies parsing, and -O keeps each socket on one line even with -i, whose details otherwise wrap onto a second line. ip can print JSON, which is safer to parse than columns:

ip -j addr show dev eth0
ip -j route | python3 -m json.tool

FAQ

Is netstat deprecated?

In practice, yes. It still installs and works, but distributions leave it out of default images, and documentation for current kernels uses ss and ip.

What do * and [::] mean in the address columns?

They are wildcards. A socket on 0.0.0.0:443 or *:443 listens on every IPv4 address, and one on [::]:443 on every IPv6 address, usually IPv4 as well.

How do I watch connections change in real time?

Wrap any of the one-liners in watch, for example watch -n 2 'ss -Htan | awk "{print \$1}" | sort | uniq -c', to refresh the state counts every two seconds. ss -s inside watch gives a lighter summary.

Should I tune the kernel to get rid of TIME-WAIT sockets?

Usually not. They cost little memory and protect new connections from stray old packets. The old tcp_tw_recycle setting broke clients behind NAT and was removed from the kernel in version 4.12, so ignore guides that recommend it.

What is the Windows equivalent?

Windows still ships its own netstat: netstat -ano lists connections with process IDs. In PowerShell, Get-NetTCPConnection returns the same data as objects you can filter.

Run it on CloudSat. Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. See plans or deploy a server.