简介

显示网络连接,路由表,接口状态,伪装连接,网络链路信息和组播成员组。

参数

netstat

  • 显示打开的套接字
1
2
3
4
5
6
7
$ netstat

Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State

Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags Type State I-Node Path
  • Proto: 套接字使用的协议
  • Recv-Q: 连接此套接字带的用户程序未拷贝的字节数
  • Send-Q: 远程主机未确认的字节数
  • State: 套接字的状态
    • ESTABLISHED
    • SYN_SENT
    • SYN_RECV
    • FIN_WAIT1
    • FIN_WAIT2
    • TIME_WAIT
    • CLOSED
    • CLOSE_WAIT
    • LAST_ACK
    • LISTEN
    • CLOSING
    • UNKNOWN

netstat -r

  • 显示内核路由表
1
2
3
4
$ netstat -r

Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface

netstat -s

  • 显示每种协议的统计信息
1
$ netstat -s

常用组合

netstat -anp | grep :80

  • 查找占用 80 端口的连接或进程
1
netstat -anp | grep :80

netstat -tulnp

  • 查看监听端口及对应进程
1
netstat -tulnp