Network
The netstat command
Shows network connections, listening ports and routes (the classic tool).
Most useful options
-tTCP connections only-uUDP connections only-lListening sockets only, the ports waiting for connections-nAddresses and ports as numbers, without resolving names-pAdds the PID and program name that own each socket-aAlso shows sockets that are not listening-rKernel routing tableCopy-ready examples
$ netstat -tulnlists listening TCP and UDP sockets, without resolving names.$ sudo netstat -tulnpthe same, with the program that owns each port.$ netstat -an | grep ESTABLISHEDshows only the active connections with other machines.$ netstat -rshows the kernel routing table.$ netstat -sshows statistics per protocol: packets, errors and retransmissions.You can try them in the browser terminal: it does not touch your computer.
Common errors
| Message | Cause | Fix |
|---|---|---|
| (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) | You asked for -p without being root and there are sockets from other users: netstat cannot see their processes. | Run it with sudo to see all processes. Without root, the column only shows your own. |
Typical mistakes
- Without -p you cannot see which program owns each socket; without root, -p only shows your own.
- Without -n it tries to resolve every address through DNS, which makes it slow with many connections.
- Many newer distributions do not install it by default: it is in the net-tools package. Today ss is recommended.
- It is a snapshot of the moment. To watch it update, use -c, which repeats it until you stop it.
Differences from similar commands
- ss: replaces it: it is faster and has state and address filters. It comes with iproute2.
- ip: according to netstat's own manual, netstat -i is the same as ip -s link, and the replacement for netstat -g is ip maddr.
- lsof: lsof -i starts from the process and lists its network connections; netstat starts from the network and looks up the process.
FAQ
Is netstat still useful today?
For old tutorials and documentation, yes. But its own manual points to ip and ss as replacements.
Which process is using port 8080?
With sudo netstat -tulnp | grep 8080 you see the PID and program name in the last column.
Why do some processes show no name?
Without root, netstat cannot see other users' processes and prints a notice. Run it with sudo to see them all.
More Network commands
Learn to actually use it
The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.
Start the free course