
简介
在类Unix系统中可以使用top查看系统资源,进程,内存占用等信息,查看网络状态可以使用netstat、nmap等工具,若要查看实时的网络流量,监控TCP/IP连接,反向解析IP,显示端口信息等,则可以使用iftop,关于centos上安装iftop有两种方法,一种是直接yum安装,一种是自己编译安装。
yum方式安装比较简单,直接以下命令即可:
yum -y install iftop
一般情况下这样就可以安装好了,但是有的小伙伴会遇到以下问题:
# 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 //什么都没干
出现这种情况,我们就需要自己下载iftop,解压,配置,编译安装。
iftop官网下载,官网链接:http://www.ex-parrot.com/pdw/iftop/download/,选择最新版本(当前最新版iftop-1.0pre4.tar.gz),
开始之前,我们先安装iftop所需的依赖软件
# 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 //编译安装
如何使用
直接执行iftop即可运行查看流量情况。
执行iftop -h得到帮助信息
- [root@www ~]#iftop -h
- iftop: display bandwidth usage on an interface by host
- Synopsis: iftop -h | [-npbBP] [-i interface] [-f filter coolcode] [-N net/mask]
- -h display this message
- -n don’t do hostname lookups
- -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
- -i interface listen on named interface
- -f filter coolcode use filter coolcode to select packets to count
- (default: none, but only IP packets are counted)
- -F net/mask show traffic flows in/out of network
- -P show ports as well as hosts
- -m limit sets the upper limit for the bandwidth scale
- -c config file specifies an alternative configuration file