Skip to main content

Command referencenetstat

netstat command (Linux / bash / sh / zsh)

Linuxbashshzshnetworkintermediate

What it does

Display legacy network connections, routes, and interface statistics. When people search for the netstat command linux ports, they usually want netstat's everyday flags, safe examples, and how it differs from related tools. Below you'll find syntax, options, and copyable examples for Bash/sh/zsh.

Display legacy network connections, routes, and interface statistics.

Syntax

netstat [OPTION]...

Common options

Flag / optionMeaning
-tShow TCP sockets.
-uShow UDP sockets.
-lShow listeners.
-nKeep addresses numeric.
-pShow process information when permitted.

Practical examples

TCP listeners

netstat -ltn

Lists numeric TCP listening sockets.

Connections and programs

sudo netstat -tunp

Shows TCP and UDP connections with processes.

Routing table

netstat -rn

Prints numeric kernel routes.

Linux ↔ Windows equivalent

Closest match: netstat (Windows / CMD). Display active connections, listening ports, routing data, and protocol statistics.

Common mistakes

  • Installing or relying on deprecated net-tools when ss is available.
  • Expecting process names without elevated permissions.

FAQ

What does netstat do in Linux?

Display legacy network connections, routes, and interface statistics.

How do I use netstat from the terminal?

Start with `netstat [OPTION]...`, then choose only the options needed for the task.

What is a practical netstat example?

Try `netstat -ltn` — Lists numeric TCP listening sockets.

Can I use netstat in a shell script?

Yes. netstat works in Bash, sh, and Zsh, but scripts should handle quoting, errors, and command output explicitly.

Browse the full Linux and Windows command reference to search more bash, CMD, PowerShell, Conda, and GitHub CLI commands.