網絡測量工具及其使用

1:網絡連通性測量:ping

ping ip/domain_name

2:網絡地址轉換:nslookup

nslookup www.tsinghua.edu.cn

3:網絡傳輸路徑追蹤:traceroute

traceroute www.tsinghua.edu.cn

追蹤路徑顯示如下:

traceroute to www.tsinghua.edu.cn (166.111.4.100), 30 hops max, 60 byte packets
 1  192.168.15.1 (192.168.15.1)  2.473 ms  2.921 ms  3.402 ms
 2  * * *
 3  * * *
 4  202.112.61.253 (202.112.61.253)  3.578 ms  6.619 ms  6.684 ms
 5  101.4.116.173 (101.4.116.173)  3.643 ms  3.710 ms  3.779 ms
 6  101.4.113.234 (101.4.113.234)  4.202 ms  2.545 ms  2.394 ms
 7  * * *
 8  * * *
 9  * * *
10  * * *
11  * * *
12  * * *
13  * * *
14  * * *
15  * * *
16  * * *
17  * * *
18  * * *
19  * * *
20  * * *
21  * * *
22  * * *
23  * * *
24  * * *
25  * * *
26  * * *
27  * * *
28  * * *
29  * * *
30  * * *

4:網絡傳輸性能測量:iperf

iperf可以用來測量帶寬,功能比較豐富,包括測量UDP,TCP等一些連接署性等。最長用的是測量網絡的帶寬,其中可包括兩個部分,分別爲服務器以及客戶端

4.1: 服務器端:運行server監聽程序:

iperf -s -p 12345

4.2: 客戶端:運行client連接程序:

iperf -c 12.12.10.12 -i 2 -P 10 -p 12345 -t 60

其中:

  • -i用於指定顯示間隔,以秒爲單位
  • -p用於指定連接的端口,默認爲 5001
  • -P用於指定併發連接數,默認爲1
  • -t用於指定測試的時間,默認10秒

4.3: 客戶端輸出結果:

~$ iperf -c 12.12.10.12 -i 2 -P 10 -p 12345
------------------------------------------------------------
Client connecting to 12.12.10.12, TCP port 12345
TCP window size: 85.0 KByte (default)
------------------------------------------------------------
[  3] local 12.12.10.11 port 50286 connected with 12.12.10.12 port 12345
[  6] local 12.12.10.11 port 50272 connected with 12.12.10.12 port 12345
[  5] local 12.12.10.11 port 50270 connected with 12.12.10.12 port 12345
[  7] local 12.12.10.11 port 50274 connected with 12.12.10.12 port 12345
[  4] local 12.12.10.11 port 50268 connected with 12.12.10.12 port 12345
[  8] local 12.12.10.11 port 50276 connected with 12.12.10.12 port 12345
[  9] local 12.12.10.11 port 50278 connected with 12.12.10.12 port 12345
[ 10] local 12.12.10.11 port 50280 connected with 12.12.10.12 port 12345
[ 11] local 12.12.10.11 port 50282 connected with 12.12.10.12 port 12345
[ 12] local 12.12.10.11 port 50284 connected with 12.12.10.12 port 12345

4.4: 服務端輸出結果:

$ iperf -s -p 12345
------------------------------------------------------------
Server listening on TCP port 12345
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
[  4] local 12.12.10.12 port 12345 connected with 12.12.10.11 port 50268
[  5] local 12.12.10.12 port 12345 connected with 12.12.10.11 port 50272
[  6] local 12.12.10.12 port 12345 connected with 12.12.10.11 port 50270
[  7] local 12.12.10.12 port 12345 connected with 12.12.10.11 port 50274
[  8] local 12.12.10.12 port 12345 connected with 12.12.10.11 port 50276
[  9] local 12.12.10.12 port 12345 connected with 12.12.10.11 port 50278
[ 10] local 12.12.10.12 port 12345 connected with 12.12.10.11 port 50280
[ 11] local 12.12.10.12 port 12345 connected with 12.12.10.11 port 50284
[ 12] local 12.12.10.12 port 12345 connected with 12.12.10.11 port 50282
[ 13] local 12.12.10.12 port 12345 connected with 12.12.10.11 port 50286
[ ID] Interval       Transfer     Bandwidth
[  8]  0.0-10.0 sec  1.40 GBytes  1.21 Gbits/sec
[  9]  0.0-10.0 sec  1.41 GBytes  1.21 Gbits/sec
[  5]  0.0-10.0 sec   362 MBytes   303 Mbits/sec
[ 10]  0.0-10.0 sec  1.41 GBytes  1.21 Gbits/sec
[  4]  0.0-10.0 sec   358 MBytes   299 Mbits/sec
[  6]  0.0-10.0 sec   361 MBytes   302 Mbits/sec
[  7]  0.0-10.0 sec   361 MBytes   302 Mbits/sec
[ 13]  0.0-11.0 sec  1.78 GBytes  1.39 Gbits/sec
[ 11]  0.0-11.0 sec  1.77 GBytes  1.38 Gbits/sec
[ 12]  0.0-11.0 sec  1.77 GBytes  1.38 Gbits/sec
[SUM]  0.0-11.0 sec  11.0 GBytes  8.54 Gbits/sec

5:網絡整流和限速:tc

1:限制發送速率

tc qdisc add dev eth2 root tbf rate 1mbit burst 10kb latency 70ms peakrate 2mbit minburst 1540

或者tc qdisc add dev eth2 root tbf rate 10000mbit burst 10000kb latency 70ms
2:解除限速

tc qdisc del dev eth2 root

6:抓包工具:tcpdump

1: 命令

tcpdump [ -DenNqvX ] [ -c count ] [ -F file ] [ -i interface ] [ -r file ]
        [ -s snaplen ] [ -w file ] [ expression ]

2:參數解析
抓包選項

  • -c:指定要抓取的包數量。
  • -iinterface:指定tcpdump需要監聽的接口。默認會抓取第一個網絡接口
  • -n:對地址以數字方式顯式,否則顯式爲主機名,也就是說-n選項不做主機名解析。
  • -nn:除了-n的作用外,還把端口顯示爲數值,否則顯示端口服務名。
  • -P:指定要抓取的包是流入還是流出的包。可以給定的值爲"in"、“out"和"inout”,默認爲"inout"。
  • -s len:設置tcpdump的數據包抓取長度爲len,如果不設置默認將會是65535字節。對於要抓取的數據包較大時,長度設置不夠可能會產生包截斷,若出現包截斷,
    :輸出行中會出現"[|proto]"的標誌(proto實際會顯示爲協議名)。但是抓取len越長,包的處理時間越長,並且會減少tcpdump可緩存的數據包的數量,
    :從而會導致數據包的丟失,所以在能抓取我們想要的包的前提下,抓取長度越小越好。

輸出選項

  • -e:輸出的每行中都將包括數據鏈路層頭部信息,例如源MAC和目標MAC。
  • -q:快速打印輸出。即打印很少的協議相關信息,從而輸出行都比較簡短。
  • -X:輸出包的頭部數據,會以16進制和ASCII兩種方式同時輸出。
  • -XX:輸出包的頭部數據,會以16進制和ASCII兩種方式同時輸出,更詳細。
  • -v:當分析和打印的時候,產生詳細的輸出。
  • -vv:產生比-v更詳細的輸出。
  • -vvv:產生比-vv更詳細的輸出。

其他功能性選項

  • -D:列出可用於抓包的接口。將會列出接口的數值編號和接口名,它們都可以用於"-i"後。
  • -F:從文件中讀取抓包的表達式。若使用該選項,則命令行中給定的其他表達式都將失效。
  • -w:將抓包數據輸出到文件中而不是標準輸出。可以同時配合"-G
    time"選項使得輸出文件每time秒就自動切換到另一個文件。可通過"-r"選項載入這些文件以進行分析和打印。
  • -r:從給定的數據包文件中讀取數據。使用"-"表示從標準輸入中讀取。

參考資料:

發佈了108 篇原創文章 · 獲贊 95 · 訪問量 125萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章