Linux(CentOS)网络流量实时监控(iftop)

来源:互联网 发布:莱斯特大学怎么样 知乎 编辑:程序博客网 时间:2024/05/04 20:48
在类Unix系统中可以使用top查看系统资源,进程,内存占用等信息。查看网络状态可以使用netstatnmap等工具。
若要查看实时的网络流量,监控TCP/IP连接,反向解析IP,显示端口信息等,则可以使用iftop

1、安装

由于使用yum install命令,无法进行直接安装。
[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. # yum install iftop //用命令直接安装  
  2. Loaded plugins: fastestmirror  
  3. Loading mirror speeds from cached hostfile  
  4.  * base: mirrors.skyshe.cn  
  5.  * extras: centos.ustc.edu.cn  
  6.  * updates: mirrors.skyshe.cn  
  7. Setting up Install Process  
  8. No package iftop available. //没有可用的安装包  
  9. Error: Nothing to do //什么都没干  
那么,就必须使用第二种安装方式,即下载,解压,配置,并编译安装。
从其官网(http://www.ex-parrot.com/pdw/iftop/download/)上,选择一个最新版本(iftop-1.0pre4.tar.gz)
[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. # yum install -y flex byacc libpcap ncurses-devel libpcap-devel //先要安装必需的软件  
  2. # mkdir iftop  
  3. # cd iftop/  
  4. # wget http://www.ex-parrot.com/pdw/iftop/download/iftop-1.0pre4.tar.gz //下载  
  5. # tar zxvf iftop-1.0pre4.tar.gz //解压  
  6. # cd iftop-1.0pre4  
  7. # ./configure //配置  
  8. # make && make install //编译安装  

2、命令说明

[plain] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. 语法: iftop -h | [-npblNBP] [-i interface] [-f filter code] [-F net/mask] [-G net6/mask6]  
  2.    -h                  显示本帮助(Help)信息  
  3.    -n                  不进行主机名(hostName)查找  
  4.    -N                  不将端口号(port Number)转换成对应的服务 to services  
  5.    -p                  混合(Promiscuous)模式(显示网络相关的其他主机信息)  
  6.    -b                  不显示流量图形条(Bar)  
  7.    -B                  以字节(Byte)为单位,显示带宽(Bandwidth);默认以比特(bit)显示的  
  8.    -i interface        监控的网卡接口(interface)  
  9.    -f filter code      包统计时,使用过滤码;默认:无,只统计IP包  
  10.    -F net/mask         显示特定IPv4网段的进出流量(Flow);如# iftop -F 10.10.1.0/24  
  11.    -G net6/mask6       显示特定IPv6网段的进出流量(Flow)  
  12.    -l                  显示并统计IPv6本地(Local)链接的流量(默认:关)  
  13.    -P                  显示端口(Port)  
  14.    -m limit            设置显示界面上侧的带宽刻度(liMit)  
  15.    -c config file      指定配置(Config)文件  
  16.    -t                  使用不带窗口菜单的文本(text)接口  
  17.   
  18.    排序:  
  19.    -o 2s                Sort by first column (2s traffic average)  
  20.    -o 10s               Sort by second column (10s traffic average) [default]  
  21.    -o 40s               Sort by third column (40s traffic average)  
  22.    -o source            Sort by source address  
  23.    -o destination       Sort by destination address  
  24.   
  25.    The following options are only available in combination with -t  
  26.    -s num              print one single text output afer num seconds, then quit  
  27.    -L num              number of lines to print  

3、界面说明


界面上面显示的是类似刻度尺的刻度范围,为显示流量图形的长条作标尺用的。
前面IP是本机的(Source),后面IP远程主机的(Dest);
中间的<= =>这两个左右箭头,表示的是流量的方向。
右侧的三列数值:
第一列是:在此次刷新之前2s或10s或40s的平均流量(按B设置秒数); 
第二列是:在此次刷新之前10秒钟的总流量的一半; 
第三列是:在此次刷新之前40秒钟的总流量的1/5;
TX:发送(Transmit)流量;RX:接收(Receive)流量;TOTAL:总流量;
cum:运行iftop到目前时间的总和(Cum);peak:流量峰(Peak)值;
rates:分别表示过去 2s 10s 40s 的平均流量;

界面显示时的交互命令:
[plain] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. 主机显示:                                
  2.  n - DNS主机解析的开关                      
  3.  s - 源(Source)主机显示的开关                
  4.  d - 目标(Dest)主机显示的开关                 
  5.  t - 循环切换行显示模式   
  6. 端口显示:                                
  7.  N - toggle service resolution                
  8.  S - toggle show source port                  
  9.  D - toggle show destination port             
  10.  p - toggle port display                       
  11. 排序:  
  12.  1/2/3 - sort by 1st/2nd/3rd column  
  13.  < - sort by source name  
  14.  > - sort by dest name  
  15.  o - freeze current order  
  16. 普通:                           
  17.  P - 暂停(Pause)显示  
  18.  h - 本帮助(Help)的显示或隐藏  
  19.  b - 图形条(Bar)的显示或隐藏  
  20.  B - cycle bar graph average          
  21.  T - toggle cumulative line totals    
  22.  j/k - scroll display                 
  23.  f - edit filter code                 
  24.  l - set screen filter                
  25.  L - lin/log scales                   
  26.  ! - shell command                    
  27.  q - quit         
0 0