在类Unix系统中可以使用top查看系统资源,进程,内存占用等信息。查看网络状态可以使用netstat、nmap等工具。
若要查看实时的网络流量,监控TCP/IP连接,反向解析IP,显示端口信息等,则可以使用iftop。
1、安装
由于使用yum install命令,无法进行直接安装。
# yum install iftop //用命令直接安装
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.skyshe.cn
* extras: centos.ustc.edu.cn
* updates: mirrors.skyshe.cn
Setting up Install Process
No package iftop available. //没有可用的安装包
Error: Nothing to do //什么都没干
那么,就必须使用第二种安装方式,即下载,解压,配置,并编译安装。
从其官网(http://www.ex-parrot.com/pdw/iftop/download/)上,选择一个最新版本(iftop-1.0pre4.tar.gz)
yum install -y flex byacc libpcap ncurses-devel libpcap-devel //先要安装必需的软件 # mkdir iftop # cd iftop/ # wget http://www.ex-parrot.com/pdw/iftop/download/iftop-1.0pre4.tar.gz //下载 # tar zxvf iftop-1.0pre4.tar.gz //解压 # cd iftop-1.0pre4 # ./configure //配置 # make && make install //编译安装badge- PRIMARY SUCCESS DANGER WARNING INFO
2、命令说明
语法: iftop -h | [-npblNBP] [-i interface] [-f filter code] [-F net/mask] [-G net6/mask6] -h 显示本帮助(Help)信息 -n 不进行主机名(hostName)查找 -N 不将端口号(port Number)转换成对应的服务 to services -p 混合(Promiscuous)模式(显示网络相关的其他主机信息) -b 不显示流量图形条(Bar) -B 以字节(Byte)为单位,显示带宽(Bandwidth);默认以比特(bit)显示的 -i interface 监控的网卡接口(interface) -f filter code 包统计时,使用过滤码;默认:无,只统计IP包 -F net/mask 显示特定IPv4网段的进出流量(Flow);如# iftop -F 10.10.1.0/24 -G net6/mask6 显示特定IPv6网段的进出流量(Flow) -l 显示并统计IPv6本地(Local)链接的流量(默认:关) -P 显示端口(Port) -m limit 设置显示界面上侧的带宽刻度(liMit) -c config file 指定配置(Config)文件 -t 使用不带窗口菜单的文本(text)接口 排序: -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
界面上面显示的是类似刻度尺的刻度范围,为显示流量图形的长条作标尺用的。
前面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 的平均流量;
界面显示时的交互命令:
主机显示:
n - DNS主机解析的开关
s - 源(Source)主机显示的开关
d - 目标(Dest)主机显示的开关
t - 循环切换行显示模式
端口显示:
N - toggle service resolution
S - toggle show source port
D - toggle show destination port
p - toggle port display
排序:
1/2/3 - sort by 1st/2nd/3rd column
< - sort by source name
> - sort by dest name
o - freeze current order
普通:
P - 暂停(Pause)显示
h - 本帮助(Help)的显示或隐藏
b - 图形条(Bar)的显示或隐藏
B - cycle bar graph average
T - toggle cumulative line totals
j/k - scroll display
f - edit filter code
l - set screen filter
L - lin/log scales
! - shell command
q - quit