netstat
Overview
The netstat
command displays network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
Syntax
netstat [options]
Common Options
Option | Description |
---|---|
-a |
All connections |
-n |
Numeric addresses |
-p |
Show PID/Program |
-t |
TCP connections |
-u |
UDP connections |
-l |
Listening sockets |
-i |
Interface stats |
-r |
Routing table |
-s |
Protocol stats |
-c |
Continuous output |
-e |
Extended info |
-v |
Verbose mode |
Connection States
State | Description |
---|---|
LISTEN | Waiting for connection |
SYN_SENT | Active open |
SYN_RECV | Passive open |
ESTABLISHED | Connection ok |
FIN_WAIT1 | Closing |
FIN_WAIT2 | Closing |
TIME_WAIT | 2MSL wait |
CLOSED | Socket is free |
CLOSE_WAIT | Remote closed |
LAST_ACK | Closing |
Key Use Cases
- Connection monitoring
- Port scanning
- Process tracking
- Network debugging
- Security auditing
Examples with Explanations
Example 1: Active Connections
netstat -tuln
Show TCP/UDP listeners
Example 2: Process Info
netstat -tp
Show with program names
Example 3: Route Table
netstat -r
Show routing table
Common Usage Patterns
Check listeners:
netstat -an | grep LISTEN
Process ports:
netstat -tulpn
Interface stats:
netstat -i
Additional Resources
Best Practices
- Use specific filters
- Check permissions
- Regular monitoring
- Document findings
- Compare states
Security Considerations
- Port exposure
- Connection states
- Process verification
- Network mapping
- Information leakage
Troubleshooting
- Connection issues
- Port conflicts
- Process problems
- Routing errors
- Interface status
Common Output Fields
- Protocol
- Local address
- Foreign address
- State
- PID/Program name