netstat Cheatsheet - Linux Network Troubleshooting Reference
All essential netstat commands organized by use case, with 39+ entries you can copy and run directly. Find the right command fast when you need it.
Back to SysOpsConnections 6
netstatShow所有活跃Connection
netstat -aShow所有监听和非监听Port
netstat -at只Show TCP Connection
netstat -au只Show UDP Connection
netstat -an不解析域名和Port名(更快)
netstat -anpDisplay PID 和Process名(需 root)
Listening Ports 6
netstat -lShow所有监听Port
netstat -ltShow TCP 监听Port
netstat -luShow UDP 监听Port
netstat -lxShow Unix 域套接字监听
netstat -lntpShow TCP 监听及Process(需 root),最常用
netstat -lnupShow UDP 监听及Process
Routing & Interfaces 5
netstat -rShowroute表,equivalent to route
netstat -rnShowroute表不解析主机名(更快)
netstat -iShowNetworkinterface统计(收发package)
netstat -ieShowinterface详情,equivalent to ifconfig
netstat -rn | grep UG只看默认网关route
Protocol Stats 5
netstat -sShow所有协议统计信息
netstat -stShow TCP 协议统计
netstat -suShow UDP 协议统计
netstat -s | grep -i errorShowNetwork错误统计
netstat -s | grep -i retransShow TCP 重传统计
Filter & Debug 6
netstat -an | grep ESTABLISHEDShow已建立的Connection
netstat -an | grep TIME_WAITShow TIME_WAIT Connection
netstat -an | grep :80Show 80 Port相关Connection
netstat -lntp | grep :80Show 80 Port被哪个Process监听
netstat -an | awk '{print $6}' | sort | uniq -c统计各Connectionstate分布
netstat -an | grep ESTABLISHED | wc -l统计当前活跃Connection数
Advanced Options 6
-n不解析 IP 和Port为名称,Display更快
-pDisplayusagePort的Process PID 和名称(需 root)
-c 1每秒持续Output,real-time monitorConnection变化
-oDisplayConnection计时器信息
-eDisplayverbose信息,附加User和 inode 列
-vverbose模式,Display未Configure的interface
ss / ip 5
ss -tlnpss 替代 netstat -tlnp,速度更快
ss -tn state establishedss 按stateFilter已建立Connection
ss -sss ShowConnection统计摘要
ip addrip 替代 ifconfig/netstat -ie Showinterface
ip routeip 替代 netstat -r Showroute表
💡 Tips
- netstat 已被 ss 命令逐步替代,新System建议优先用 ss(更快更现代)。
- ShowProcess需要 root Permission,否则 PID 列Display为 -。
- TIME_WAIT 过多可能是短Connection频繁,考虑用长Connection或Connection池。
- netstat -an 速度最快,-p 会降低性能因为要查Processmap。
- ss 使用 netlink interface直接Read内核数据,比 netstat 快一个数量级。
- 排查Portusage最常用的组合是 netstat -tlnp | grep <Port>。
Official References
Commands are compiled from the official docs below. Click to verify the latest usage.
Maintained by LaoHand
Publicly updated on Jul 21, 2026, continuously proofread against official docs.
Found an error? Report it
Wrong command or description? Open an issue to help us fix it.
Found an error? Report it