# netstat Command Reference
## What it does
Displays network connections, listening ports, routing tables, and network interface statistics.
## Basic Usage
```bash
netstat # Show all active connections
netstat -a # Show all connections and listening ports
netstat -l # Show only listening ports
```
## Connection Display
| Argument | Description |
|----------|-------------|
| `-a` | Show all connections and listening ports |
| `-l` | Show only listening ports |
| `-n` | Show numerical addresses (don't resolve) |
| `-p` | Show process ID and name (requires sudo) |
| `-t` | Show TCP connections only |
| `-u` | Show UDP connections only |
## Network Statistics
```bash
# Show interface statistics
netstat -i
# Show routing table
netstat -r
# Show network statistics by protocol
netstat -s
```
## Protocol Options
| Argument | Description |
|----------|-------------|
| `-t` | TCP connections only |
| `-u` | UDP connections only |
| `-r` | Show routing table |
| `-i` | Show network interfaces |
| `-s` | Show protocol statistics |
## Quick Commands
```bash
# Active connections with process info
sudo netstat -tulpn
# Show listening ports
netstat -an | grep LISTEN
# Show routing table
netstat -rn
# Network interface stats
netstat -i
# Connections to specific port
netstat -an | grep :80
```
## Common Combinations
```bash
# Most useful: all listening ports (numeric)
netstat -an | grep LISTEN
# Active TCP connections
netstat -tn
# UDP connections
netstat -un
# Full connection details
sudo netstat -tulpn
```
## Reading Results
```bash
tcp4 0 0 127.0.0.1.3000 *.* LISTEN
tcp4 0 0 *.22 *.* LISTEN
```
- `tcp4` → Protocol and IP version
- `127.0.0.1.3000` → Local address and port
- `*.*` → Remote address (any)
- `LISTEN` → Connection state
## Pro Tips
> - Use `-n` to avoid slow DNS lookups
> - Combine with `grep` to filter specific ports
> - `sudo` required for process information