netstat命令用于显示与IP、TCP、UDP和ICMP协议相关的统计数据,一般用于检验本机各端口的网络连接情况。netstat是在内核中访问网络及相关信息的程序,它能提供TCP连接,TCP和UDP监听,进程内存管理的相关报告。

  1. [root@localhost ~]# netstat --help
  2. usage: netstat [-vWeenNcCF] [<Af>] -r netstat {-V|--version|-h|--help}
  3. netstat [-vWnNcaeol] [<Socket> ...]
  4. netstat { [-vWeenNac] -I[<Iface>] | [-veenNac] -i | [-cnNe] -M | -s [-6tuw] } [delay]
  5. -r, --route display routing table
  6. -I, --interfaces=<Iface> display interface table for <Iface>
  7. -i, --interfaces display interface table //显示接口列表
  8. -g, --groups display multicast group memberships
  9. -s, --statistics display networking statistics (like SNMP) //显示收发信息
  10. -M, --masquerade display masqueraded connections
  11. -v, --verbose be verbose
  12. -W, --wide don't truncate IP addresses
  13. -n, --numeric don't resolve names //不解析主机名,可以加快查询速度
  14. --numeric-hosts don't resolve host names
  15. --numeric-ports don't resolve port names
  16. --numeric-users don't resolve user names
  17. -N, --symbolic resolve hardware names
  18. -e, --extend display other/more information
  19. -p, --programs display PID/Program name for sockets //显示进程名
  20. -o, --timers display timers
  21. -c, --continuous continuous listing
  22. -l, --listening display listening server sockets //显示监听的套接字
  23. -a, --all display all sockets (default: connected) //显示所有套接字
  24. -F, --fib display Forwarding Information Base (default)
  25. -C, --cache display routing cache instead of FIB
  26. -Z, --context display SELinux security context for sockets
  27. <Socket>={-t|--tcp} {-u|--udp} {-U|--udplite} {-S|--sctp} {-w|--raw}
  28. {-x|--unix} --ax25 --ipx --netrom
  29. <AF>=Use '-6|-4' or '-A <af>' or '--<af>'; default: inet
  30. List of possible address families (which support routing):
  31. inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25)
  32. netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP)
  33. x25 (CCITT X.25)

参数

  • -a或—all显示所有连线中的套接字。
  • -A <网络类型>或-<网络类型>列出该网络类型连线中的相关地址。
  • -c或—continuous持续列出网络状态。
  • -C或—cache显示路由器配置的快取信息。
  • -e或—extend显示网络其他相关信息。
  • -F或—fib显示FIB。
  • -g或—groups显示多重广播功能分组组成员列表。
  • -h或—help在线帮助。
  • -i或—interfaces显示网络界面信息表单。
  • -l或—listening显示监视中的服务器的套接字。
  • -M或-假面舞会显示伪装的网络连线。
  • -n或—numeric直接使用IP地址,而不通过域名服务器。
  • -N或—netlink或—symbolic显示网络硬件外围设备的符号连接名称。
  • -o或—timers显示计时器。
  • -p或—programs显示正在使用套接字的程序识别码和程序名。
  • -r或—route显示路由表。
  • -s或—statistice显示网络工作信息统计表。
  • -t或—tcp显示TCP传输协议的连线状况。
  • -u或—udp显示UDP传输协议的连线状况。
  • -v或—verbose显示指令执行过程。
  • -V或—version显示版本信息。
  • -w或—raw显示RAW传输协议的连线状况。
  • -x或—unix此参数的效果和指定“ -A unix”参数相同。
  • —ip或—inet此参数的效果和指定“ -A inet”参数相同。

状态说明

  • LISTEN:侦听来自远方的TCP端口的连接请求
  • SYN-SENT:再发送连接请求后等待匹配的连接请求(如果有大量这样的状态包,检查是否中招了)
  • SYN-RECEIVED:再收到和发送一个连接请求后等待对方对连接请求的确认(如有大量此状态,估计被flood攻击了)
  • ESTABLISHED:代表一个打开的连接
  • FIN-WAIT-1:等待远程TCP连接中断请求,或先前的连接中断请求的确认
  • FIN-WAIT-2:从远程TCP等待连接中断请求
  • CLOSE-WAIT:等待从本地用户发来的连接中断请求
  • CLOSING:等待远程TCP对连接中断的确认
  • LAST-ACK:等待原来的发向远程TCP的连接中断请求的确认(不是什么好东西,此项出现,检查是否被攻击)
  • TIME-WAIT:等待足够的时间以确保远程TCP接收到连接中断请求的确认
  • CLOSED:没有任何连接状态

示例

  1. //显示所有套接字、显示TCP、显示进程名
  2. [root@localhost ~]#netstat -atp
  3. 可以查看很多网络信息,具体还是百度吧