2024年11月Linux中netstat命令操作实例汇总(5)

发布时间:

  ⑴[rootlocalhost ~]# stat -l

  ⑵Active Inter connections (only servers

  ⑶Proto Recv-Q Send-Q Local Address Foreign Address State

  ⑷tcp localhost:smux *:* LISTEN

  ⑸tcp *:svn *:* LISTEN

  ⑹tcp *:ssh *:* LISTEN

  ⑺udp localhost:syslog *:*

  ⑻udp *:snmp *:*

  ⑼Active UNIX domain sockets (only servers

  ⑽Proto Reft Flags Type State I-Node Path

  ⑾unix [ A ] STREAM LISTENING /tmp/ssh-yKnDB/agent.

  ⑿unix [ A ] STREAM LISTENING /var/run/audispd_events

  ⒀[rootlocalhost ~]#

  ⒁实例:显示所有已建立的有效连接

  ⒂命令:stat -n

  ⒃[rootlocalhost ~]# stat -n

  ⒄Active Inter connections (w/o servers

  ⒅Proto Recv-Q Send-Q Local Address Foreign Address State

  ⒆tcp ...: ...: ESTABLISHED

  ⒇Active UNIX domain sockets (w/o servers

  ⒈Proto Reft Flags Type State I-Node Path

  ⒉unix [ ] DGRAM //kernel/udev/udevd

  ⒊unix [ ] DGRAM /dev/log

  ⒋unix [ ] DGRAM

  ⒌unix [ ] DGRAM

  ⒍unix [ ] STREAM CONNECTED

  ⒎unix [ ] STREAM CONNECTED

  ⒏[rootlocalhost ~]#

  ⒐实例:显示关于以太网的统计数据

  ⒑命令:stat -e

  ⒒[rootlocalhost ~]# stat -e

  ⒓Active Inter connections (w/o servers

  ⒔Proto Recv-Q Send-Q Local Address Foreign Address State User Inode

  ⒕tcp ...:ssh ...: ESTABLISHED root

  ⒖Active UNIX domain sockets (w/o servers

  ⒗Proto Reft Flags Type State I-Node Path

  ⒘unix [ ] DGRAM //kernel/udev/udevd

  ⒙unix [ ] DGRAM /dev/log

  ⒚unix [ ] DGRAM

  ⒛unix [ ] DGRAM

  ①unix [ ] STREAM CONNECTED

  ②unix [ ] STREAM CONNECTED

  ③[rootlocalhost ~]#

  ④用于显示关于以太网的统计数据。它列出的项目包括传送的数据报的总字节数、错误数、删除数、数据报的数量和广播的数量。这些统计数据既有发送的数据报数量,也有接收的数据报数量。这个选项可以用来统计一些基本的网络流量

  ⑤实例:显示关于路由表的信息

  ⑥命令:stat -r

  ⑦[rootlocalhost ~]# stat -r

  ⑧Kernel IP routing table

  ⑨Destination Gateway Genmask Flags MSS Window irtt Iface

  ⑩... * ... U eth

  Ⅰ... ... ... UG eth

  Ⅱ... ... ... UG eth

  Ⅲdefault ... ... UG eth

  Ⅳ[rootlocalhost ~]#

  Ⅴ实例:列出所有 tcp 端口

  Ⅵ命令:stat -at

  Ⅶ[rootlocalhost ~]# stat -at

  ⅧActive Inter connections (servers and established

  ⅨProto Recv-Q Send-Q Local Address Foreign Address State

  Ⅹtcp localhost:smux *:* LISTEN

  ㈠tcp *:svn *:* LISTEN

  ㈡tcp *:ssh *:* LISTEN

  ㈢tcp ...:ssh ...: ESTABLISHED

  ㈣[rootlocalhost ~]#

  ㈤实例:统计机器中网络连接各个状态个数

  ㈥命令:stat -a | awk ‘/^tcp/ {++S[$NF]} END {for(a in S print a, S[a]}’

  ㈦[rootlocalhost ~]# stat -a | awk ‘/^tcp/ {++S[$NF]} END {for(a in S print a, S[a]}’

  ㈧ESTABLISHED

  ㈨[rootlocalhost ~]#

  ㈩实例:把状态全都取出来后使用uniq -c统计后再进行排序

  命令:stat -nat |awk ‘{print $}’|sort|uniq -c

  [rootandy ~]# stat -nat |awk ‘{print $}’|sort|uniq -c

   CLOSE_WAIT

   established

   ESTABLISHED

   Foreign

   TIME_WAIT

  [rootandy ~]# stat -nat |awk ‘{print $}’|sort|uniq -c|sort -rn

   ESTABLISHED

   CLOSE_WAIT

   TIME_WAIT

   Foreign

   established

  [rootandy ~]#