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.

SysOps·39 commands·Last updated 2026-07-21
Back to SysOps

Connections 6

netstat
Show所有活跃Connection
netstat -a
Show所有监听和非监听Port
netstat -at
只Show TCP Connection
netstat -au
只Show UDP Connection
netstat -an
不解析域名和Port名(更快)
netstat -anp
Display PID 和Process名(需 root)

Listening Ports 6

netstat -l
Show所有监听Port
netstat -lt
Show TCP 监听Port
netstat -lu
Show UDP 监听Port
netstat -lx
Show Unix 域套接字监听
netstat -lntp
Show TCP 监听及Process(需 root),最常用
netstat -lnup
Show UDP 监听及Process

Routing & Interfaces 5

netstat -r
Showroute表,equivalent to route
netstat -rn
Showroute表不解析主机名(更快)
netstat -i
ShowNetworkinterface统计(收发package)
netstat -ie
Showinterface详情,equivalent to ifconfig
netstat -rn | grep UG
只看默认网关route

Protocol Stats 5

netstat -s
Show所有协议统计信息
netstat -st
Show TCP 协议统计
netstat -su
Show UDP 协议统计
netstat -s | grep -i error
ShowNetwork错误统计
netstat -s | grep -i retrans
Show TCP 重传统计

Filter & Debug 6

netstat -an | grep ESTABLISHED
Show已建立的Connection
netstat -an | grep TIME_WAIT
Show TIME_WAIT Connection
netstat -an | grep :80
Show 80 Port相关Connection
netstat -lntp | grep :80
Show 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更快
-p
DisplayusagePort的Process PID 和名称(需 root)
-c 1
每秒持续Output,real-time monitorConnection变化
-o
DisplayConnection计时器信息
-e
Displayverbose信息,附加User和 inode 列
-v
verbose模式,Display未Configure的interface

ss / ip 5

ss -tlnp
ss 替代 netstat -tlnp,速度更快
ss -tn state established
ss 按stateFilter已建立Connection
ss -s
ss ShowConnection统计摘要
ip addr
ip 替代 ifconfig/netstat -ie Showinterface
ip route
ip 替代 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