iftop对linux网络流量实时监控

  • iftop对linux网络流量实时监控已关闭评论
  • 115,292 views
  • A+
所属分类:运维实战

作用

可以实时的网络流量,监控TCP/IP连接,反向解析IP,显示端口信息等,最早之前我们服务器被当成肉机的时候也是用iftop查出来的

安装

#yum -y install iftop

如果没找到安装包的话,那就只能源码编译安装了,官网地址如下:

http://www.ex-parrot.com/pdw/iftop/download/

选择个最新的编译安装就行

参数说明

[root@iZwz9bpg2u1r39ml9st8qzZ ~]# iftop -h
iftop: display bandwidth usage on an interface by host

Synopsis: iftop -h | [-npblNBP] [-i interface] [-f filter code]
 [-F net/mask] [-G net6/mask6]

 -h display this message #显示本帮助信息 
 -n don't do hostname lookups #不进行主机名查找,直接显示ip地址
 -N don't convert port numbers to services #直接显示服务端口号,而不是服务
 -p run in promiscuous mode (show traffic between other 
 hosts on the same network segment)#混合模式(显示网络相关的其他主机信息)
 -b don't display a bar graph of traffic #不显示流量图形条
 -B Display bandwidth in bytes #以字节(Byte)为单位,显示带宽(Bandwidth);默认以比特(bit)显示的 
 -i interface listen on named interface #监控的网卡接口,如eth0等
 -f filter code use filter code to select packets to count
 (default: none, but only IP packets are counted)
 # 包统计时,使用过滤码;默认:无,只统计IP包  
 -F net/mask show traffic flows in/out of IPv4 network #显示特定IPv4网段的进出流量(Flow);如# iftop -F 10.16.172.0/24  
 -G net6/mask6 show traffic flows in/out of IPv6 network #显示特定IPv6网段的进出流量(Flow)
 -l display and count link-local IPv6 traffic (default: off) #显示并统计IPv6本地(Local)链接的流量(默认:关) 
 -P show ports as well as hosts #显示端口(Port) 
 -m limit sets the upper limit for the bandwidth scale #设置显示界面上侧的带宽刻度(liMit)
 -c config file specifies an alternative configuration file #指定配置(Config)文件
 -t use text interface without ncurses #使用不带窗口菜单的文本(text)接口

Sorting orders:
 -o 2s Sort by first column (2s traffic average)
 -o 10s Sort by second column (10s traffic average) [default]
 -o 40s Sort by third column (40s traffic average)
 -o source Sort by source address
 -o destination Sort by destination address

The following options are only available in combination with -t
 -s num print one single text output afer num seconds, then quit
 -L num number of lines to print

iftop, version 1.0pre4
copyright (c) 2002 Paul Warren <pdw@ex-parrot.com> and contributors

操作命令

iftop执行后,通过键盘输入命令也可以调整切换相关信息:

按h切换是否显示帮助。
按n切换显示本机的IP或主机名。
按s切换是否显示本机的host信息。
按d切换是否显示远端目标主机的host信息。
按t切换显示格式为2行/1行/只显示发送流量/只显示接收流量。
按N切换显示端口号或端口服务名称。
按S切换是否显示本机的端口信息。
按D切换是否显示远端目标主机的端口信息。
按p切换是否显示端口信息。
按P切换暂停/继续显示。
按b切换是否显示平均流量图形条。
按B切换计算2秒或10秒或40秒内的平均流量。
按T切换是否显示每个连接的总流量。
按l打开屏幕过滤功能,输入要过滤的字符,比如ip,按回车后,屏幕就只显示这个IP相关的流量信息。
按L切换显示画面上边的刻度。刻度不同,流量图形条会有变化。
按j或按k可以向上或向下滚动屏幕显示的连接记录。
按1或2或3可以根据右侧显示的三列流量数据进行排序。
按<根据左边的本机名或IP排序。
按>根据远端目标主机的主机名或IP排序。
按o切换是否固定只显示当前的连接。
按q退出监控。

运行iftop

执行iftop,如下图:

iftop对linux网络流量实时监控

如上图,最前面ip的一列是本机的ip,后面IP远程主机,中间的<= =>这两个左右箭头,表示的是流量的方向。

右侧的三列数值:
第一列是:在此次刷新之前2s或10s或40s的平均流量(按B设置秒数)。
第二列是:在此次刷新之前10秒钟的总流量的一半。
第三列是:在此次刷新之前40秒钟的总流量的1/5。
TX:发送(Transmit)流量;RX:接收(Receive)流量;TOTAL:总流量。
cum:运行iftop到目前时间的总和(Cum);peak:流量峰(Peak)值。
rates:分别表示过去 2s 10s 40s 的平均流量。

输入操作命令,可以获取相关输出信息,我这里举例说明,用N命令,画面输入N,右上角如图:

iftop对linux网络流量实时监控

按h就会切换到帮助界面,如图:

iftop对linux网络流量实时监控

 

  • 安卓客户端下载
  • 微信扫一扫
  • weinxin
  • 微信公众号
  • 微信公众号扫一扫
  • weinxin
avatar