Linux command
netstat 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Show all connections
netstat -a
Show listening ports only
netstat -l
Show TCP connections
netstat -tn
Show listening ports with process IDs
sudo netstat -tulnp
Show routing table
netstat -r
Show network interface statistics
netstat -i
Show protocol statistics
netstat -s
Continuously refresh
netstat -c
说明
netstat displays network connections, routing tables, interface statistics, masquerade connections, and multicast memberships. It is a traditional tool for network troubleshooting and monitoring. Without options, netstat shows open sockets. The most common usage (netstat -tulnp) shows TCP and UDP listening ports with process information and numeric addresses. The routing table (-r) shows how packets are directed, while interface statistics (-i) show traffic and errors per network interface. Output columns include: Proto (protocol), Recv-Q/Send-Q (data queued), Local/Foreign Address (endpoints), State (connection state like LISTEN, ESTABLISHED, TIME_WAIT), and optionally PID/Program (process using the socket).
参数
- -a, --all
- Show both listening and non-listening sockets
- -l, --listening
- Show only listening sockets
- -t, --tcp
- Show TCP connections
- -u, --udp
- Show UDP connections
- -n, --numeric
- Show numeric addresses instead of resolving names
- -p, --program
- Show PID and program name for each socket
- -r, --route
- Display kernel routing table
- -i, --interfaces
- Display network interface table
- -g, --groups
- Display multicast group membership
- -s, --statistics
- Display protocol statistics (SNMP)
- -M, --masquerade
- Display masqueraded connections
- -c, --continuous
- Refresh display every second
- -e, --extend
- Display extended information (use twice for more)
- -o, --timers
- Include networking timer information
- -v, --verbose
- Verbose output
- -W, --wide
- Don't truncate IP addresses
- -4
- Show IPv4 only
- -6
- Show IPv6 only
- -A _FAMILY_
- Address families (inet, inet6, unix, ipx, etc.)
FAQ
What is the netstat command used for?
netstat displays network connections, routing tables, interface statistics, masquerade connections, and multicast memberships. It is a traditional tool for network troubleshooting and monitoring. Without options, netstat shows open sockets. The most common usage (netstat -tulnp) shows TCP and UDP listening ports with process information and numeric addresses. The routing table (-r) shows how packets are directed, while interface statistics (-i) show traffic and errors per network interface. Output columns include: Proto (protocol), Recv-Q/Send-Q (data queued), Local/Foreign Address (endpoints), State (connection state like LISTEN, ESTABLISHED, TIME_WAIT), and optionally PID/Program (process using the socket).
How do I run a basic netstat example?
Run `netstat -a` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -a, --all do in netstat?
Show both listening and non-listening sockets