netstat
Display network connections, routing tables, and network interface statistics
Syntax
netstat [options]
Basic Usage
Show all connections
netstat -a
Displays all active network connections.
Show TCP connections
netstat -t
Show UDP connections
netstat -u
Show listening ports
netstat -l
Common Options
-a, --all: Show all connections and listening ports-t, --tcp: Show TCP connections-u, --udp: Show UDP connections-l, --listening: Show only listening ports-n, --numeric: Show numeric addresses instead of resolving names-p, --programs: Show process/program name-r, --route: Show routing table-i, --interfaces: Show network interfaces-s, --statistics: Show network statistics-c, --continuous: Update continuously
Practical Examples
Show all active TCP connections
netstat -t
Show listening ports with process names
netstat -tulnp
Show routing table
netstat -r
Show network interface statistics
netstat -i
Show network statistics by protocol
netstat -s
Show connections for specific port
netstat -tuln | grep :80
Show connections with continuous updates
netstat -tuln -c
Show only established connections
netstat -tuln | grep ESTABLISHED
Understanding Output
Connection States
LISTEN: Port is listening for connectionsESTABLISHED: Active connectionCLOSE_WAIT: Connection closingTIME_WAIT: Connection timed outSYN_SENT: Connection attempt
Output Columns
Proto: Protocol (tcp/udp)Recv-Q: Receive queueSend-Q: Send queueLocal Address: Local IP and portForeign Address: Remote IP and portState: Connection state
Best Practices
Monitoring Use Cases
- Check which services are listening on ports
- Monitor active network connections
- Troubleshoot network connectivity issues
- Verify firewall rules effectiveness
- Monitor network usage patterns
Important Notes
- netstat is deprecated in favor of ss and ip commands
- Use -n flag for faster output (no DNS resolution)
- Combine with grep for filtering specific information
- Use -c for continuous monitoring
- Consider using ss command for newer systems