Linux檢視網路卡流量方法的工具和命令彙總

chenfeng發表於2019-05-14

一.iptraf

安裝方法:

# yum install iptraf -y

Loaded plugins: fastestmirror

Setting up Install Process

Loading mirror speeds from cached hostfile

epel/metalink                                                                                                               | 7.8 kB     00:00     

 * base: mirrors.163.com

 * epel: mirrors.yun-idc.com

 * extras: mirrors.aliyun.com

 * updates: centos.ustc.edu.cn

base                                                                                                                        | 3.7 kB     00:00     

epel                                                                                                                        | 4.7 kB     00:00     

epel/primary_db                                                                                                             | 6.0 MB     00:00     

extras                                                                                                                      | 3.4 kB     00:00     

updates                                                                                                                     | 3.4 kB     00:00     

Resolving Dependencies

--> Running transaction check

---> Package iptraf.x86_64 0:3.0.1-14.el6 will be installed

--> Finished Dependency Resolution


Dependencies Resolved


===================================================================================================================================================

 Package                           Arch                              Version                                 Repository                       Size

===================================================================================================================================================

Installing:

 iptraf                            x86_64                            3.0.1-14.el6                            base                            316 k


Transaction Summary

===================================================================================================================================================

Install       1 Package(s)


Total download size: 316 k

Installed size: 681 k

Downloading Packages:

iptraf-3.0.1-14.el6.x86_64.rpm                                                                                              | 316 kB     00:00     

Running rpm_check_debug

Running Transaction Test

Transaction Test Succeeded

Running Transaction

  Installing : iptraf-3.0.1-14.el6.x86_64                                                                                                      1/1 

  Verifying  : iptraf-3.0.1-14.el6.x86_64                                                                                                      1/1 


Installed:

  iptraf.x86_64 0:3.0.1-14.el6                                                                                                                     


Complete!


用法:

# iptraf


隨便按一個鍵繼續,進入下圖內容:




引數解釋:

Ip 流量監控

簡單的介面統計資訊,根據連線檢視網路流量

詳細的介面統計資訊,檢視每個網路卡上的流量,包括內網和外網

統計分析

Lan統計,根據mac地址統計


具體用法可以參考:

https://www.landui.com/help/show-5067.html


二.nload

安裝方法:

# yum install -y nload

Loaded plugins: fastestmirror

Setting up Install Process

Loading mirror speeds from cached hostfile

 * base: mirrors.163.com

 * epel: mirror01.idc.hinet.net

 * extras: mirrors.aliyun.com

 * updates: centos.ustc.edu.cn

Resolving Dependencies

--> Running transaction check

---> Package nload.x86_64 0:0.7.4-1.el6 will be installed

--> Finished Dependency Resolution


Dependencies Resolved


===================================================================================================================================================

 Package                          Arch                              Version                                  Repository                       Size

===================================================================================================================================================

Installing:

 nload                            x86_64                            0.7.4-1.el6                              epel                             63 k


Transaction Summary

===================================================================================================================================================

Install       1 Package(s)


Total download size: 63 k

Installed size: 155 k

Downloading Packages:

nload-0.7.4-1.el6.x86_64.rpm                                                                                                |  63 kB     00:00     

Running rpm_check_debug

Running Transaction Test

Transaction Test Succeeded

Running Transaction

  Installing : nload-0.7.4-1.el6.x86_64                                                                                                        1/1 

  Verifying  : nload-0.7.4-1.el6.x86_64                                                                                                        1/1 


Installed:

  nload.x86_64 0:0.7.4-1.el6                                                                                                                       


Complete!


# nload


三:iftop

安裝方法:

# yum install gcc flex byacc libpcap libpcap-devel ncurses ncurses-devel -y


#  wget http://www.ex-parrot.com/pdw/iftop/download/iftop-0.17.tar.gz


# tar zxvf iftop-0.17.tar.gz

#cd iftop-0.17

#./configure && make && make install


# iftop


相關引數及說明

1、iftop介面相關說明

  介面上面顯示的是類似刻度尺的刻度範圍,為顯示流量圖形的長條作標尺用的。中間的<= =>這兩個左右箭頭,表示的是流量的方向。

TX:傳送流量

RX:接收流量

TOTAL:總流量

Cumm:執行iftop到目前時間的總流量

peak:流量峰值

rates:分別表示過去 2s 10s 40s 的平均流量

2、iftop相關引數

  常用的引數

-i設定監測的網路卡,如:# iftop -i eth1

-B 以bytes為單位顯示流量(預設是bits),如:# iftop -B

-n使host資訊預設直接都顯示IP,如:# iftop -n

-N使埠資訊預設直接都顯示埠號,如: # iftop -N

-F顯示特定網段的進出流量,如# iftop -F 10.10.1.0/24或# iftop -F 10.10.1.0/255.255.255.0

-h(display this message),幫助,顯示引數資訊

-p使用這個引數後,中間的列表顯示的本地主機資訊,出現了本機以外的IP資訊;

-b使流量圖形條預設就顯示;

-f這個暫時還不太會用,過濾計算包用的;

-P使host資訊及埠資訊預設就都顯示;

-m設定介面最上邊的刻度的最大值,刻度分五個大段顯示,例:# iftop -m 100M

  

  進入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切換是否固定只顯示當前的連線;

按f可以編輯過濾程式碼

按!可以使用Shell命令

按q退出監控。



四.sar命令

# sar -n DEV 1 4

Linux 2.6.32-696.el6.x86_64 (test2)     05/14/2019      _x86_64_        (4 CPU)


03:30:35 PM     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s

03:30:36 PM        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00

03:30:36 PM      eth1     32.00      2.00      1.44      0.30      0.00      0.00      0.00


03:30:36 PM     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s

03:30:37 PM        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00

03:30:37 PM      eth1     15.15      3.03      0.69      0.56      0.00      0.00      0.00


03:30:37 PM     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s

03:30:38 PM        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00

03:30:38 PM      eth1     30.69      1.98      1.38      0.50      0.00      0.00      0.00


03:30:38 PM     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s

03:30:39 PM        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00

03:30:39 PM      eth1     28.00      2.00      1.26      0.50      0.00      0.00      0.00


Average:        IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s

Average:           lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00

Average:         eth1     26.50      2.25      1.19      0.47      0.00      0.00      0.00


備註:命令後面1 4的意思是每一秒鐘取1次值,共取4次。

引數解釋:

IFACE:LAN介面

rxpck/s:每秒鐘接收的資料包

txpck/s:每秒鐘傳送的資料包

rxkB/s:每秒鐘接收的kB數

txkB/s:每秒鐘傳送的kB數

rxcmp/s:每秒鐘接收的壓縮資料包

txcmp/s:每秒鐘傳送的壓縮資料包

rxmcst/s:每秒鐘接收的多播資料包


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15498/viewspace-2644312/,如需轉載,請註明出處,否則將追究法律責任。

相關文章