Command referencenetstat
netstat command (Linux / bash / sh / zsh)
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 / option | Meaning |
|---|---|
| -t | Show TCP sockets. |
| -u | Show UDP sockets. |
| -l | Show listeners. |
| -n | Keep addresses numeric. |
| -p | Show 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.
Related commands
- ssInspect network sockets, listeners, and connection statistics.
- pingTest IP reachability and measure round-trip response time.
- netstatDisplay active connections, listening ports, routing data, and protocol statistics.
- ipconfigDisplay and manage Windows IP configuration and DNS client state.
- pingTest reachability and measure response time with ICMP echo requests.
- curlTransfer data to or from URLs using many network protocols.
- sshOpen a secure remote shell or run a command over SSH.
- Invoke-WebRequestSend HTTP and HTTPS requests and return response metadata and content.
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.