共計 6500 個字符,預計需要花費 17 分鐘才能閱讀完成。
自動寫代碼機器人,免費開通
這篇文章將為大家詳細講解有關 Linux 如何查看網卡流量,丸趣 TV 小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
一.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 eth2
-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 eth2 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 eth2 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 eth2 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 eth2 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: eth2 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:每秒鐘接收的多播數據包
關于“Linux 如何查看網卡流量”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
向 AI 問一下細節
丸趣 TV 網 – 提供最優質的資源集合!