Linux下流量监控:iftop的安装与使用
1.简介
用途
对定位机器上的流量异常问题,和服务间调用问题比较有用。
2.安装
有两种安装方式
1. yum/apt安装
2.源码编译安装
2.1 yum/apt
#Ubuntu sudo apt install -y iftop/xenial #Centos sudo yum install -y iftop.x86_64
2.2 源码编译安装
2.2.1 预装系统包
#Ubuntu sudo apt-get install flex byacc libpcap0.8 libncurses5 #Centos sudo yum install -y flex byacc libpcap ncurses-devel libpcap-devel
2.2.2 编译安装iftop
#下载iftop的安装包
wget http://www.ex-parrot.com/pdw/iftop/download/iftop-0.17.tar.gz
#解压缩iftop的安装包
tar xzvf iftop-0.17.tar.gz
#进入对应目录
cd iftop-0.17/
#配置
sudo ./configure
#编译
sudo make
#安装
sudo make install
3. 运行iftop
3.1 帮助
执行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
-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
-a display bandwidth in packets
-i interface listen on named interface
-f filter code use filter code to select packets to count
(default: none, but only IP packets are counted)
-F net/mask show traffic flows in/out of IPv4 network
-G net6/mask6 show traffic flows in/out of IPv6 network
-l display and count link-local IPv6 traffic (default: off)
-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
-t use text interface without ncursesSorting 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 addressThe 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
3.2 例子
1. 直接使用iftop :iftop
2.iftop -B
以Byte为单位展示而不是Bit为单位展示
3.iftop -n
不展示hosts信息,也可以在iftop后按n进行切换
显示为主机名
显示为ip
4.iftop -N
不展示端口号;默认展示的ip后面会带端口号。可以进入iftop后按N切换
5.iftop -F 网段
例如: iftop -F 192.168.21.0/192.168.21.0
6.iftop -P
展示host信息和端口信息
7.iftop -i eth0
指定只展示eth0网卡的进出流量,默认只展示eth0的网卡信息
8. 排序(最重要的)
iftop -o 2s,按照rate(2秒内平均流量)那列排序,也可以进入iftop按1
iftop -o 10s,按照rate(10秒内平均流量)那列排序,也可以进入iftop按2
iftop -o 40s,按照rate(40秒内平均流量)那列排序,也可以进入iftop按3
iftop -o source,按照源地址排序,也可以进入iftop按<
iftop -o source,按照目的地址排序,也可以进入iftop按>
9. 常用快捷键
q:退出
?:帮助模式
P: 停止屏幕信息刷新
S: 切换source端口展示
D:切换dest端口展示
j/k:向前后滚动屏幕信息
以上就是iftop相关的介绍了,有问题可以在评论区里留言~
博主:测试生财(一个不为996而996的测开码农)
座右铭:专注测试开发与自动化运维,努力读书思考写作,为内卷的人生奠定财务自由。
内容范畴:技术提升,职场杂谈,事业发展,阅读写作,投资理财,健康人生。
csdn:https://blog.csdn.net/ccgshigao
博客园:https://www.cnblogs.com/qa-freeroad/
51cto:https://blog.51cto.com/14900374
微信公众号:测试生财(定期分享独家内容和资源)