溫馨提示×

如何用Linux Sniffer檢測網絡延遲

小樊
49
2025-09-28 06:37:41
欄目: 智能運維

使用Linux Sniffer檢測網絡延遲可以通過多種工具和方法來實現。以下是一些常用的方法和步驟:

1. 使用 ping 命令

ping 是最簡單和常用的網絡診斷工具之一,用于測量數據包從源主機到目標主機的往返時間(RTT)。

ping -c 4 www.example.com
  • -c 4 表示發送4個數據包。
  • www.example.com 是目標主機的域名或IP地址。

輸出示例:

PING www.example.com (93.184.216.34) 56(84) bytes of data.
64 bytes from 93.184.216.34: icmp_seq=1 ttl=56 time=14.5 ms
64 bytes from 93.184.216.34: icmp_seq=2 ttl=56 time=15.2 ms
64 bytes from 93.184.216.34: icmp_seq=3 ttl=56 time=14.8 ms
64 bytes from 93.184.216.34: icmp_seq=4 ttl=56 time=14.2 ms

--- www.example.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3003ms
rtt min/avg/max/mdev = 14.234/14.689/15.276/0.421 ms

2. 使用 traceroute 命令

traceroute 可以顯示數據包從源主機到目標主機經過的路由節點及其延遲。

traceroute www.example.com

輸出示例:

traceroute to www.example.com (93.184.216.34), 30 hops max, 60 byte packets
 1  router.local (192.168.1.1)  1.123 ms  1.024 ms  0.925 ms
 2  isp-gateway.example.com (10.0.0.1)  2.345 ms  2.234 ms  2.123 ms
 3  core-router.example.com (203.0.113.1)  3.456 ms  3.345 ms  3.234 ms
 4  www.example.com (93.184.216.34)  4.567 ms  4.456 ms  4.345 ms

3. 使用 mtr 命令

mtrpingtraceroute 的結合體,可以實時顯示每個路由節點的延遲和丟包情況。

首先需要安裝 mtr

sudo apt-get install mtr  # Debian/Ubuntu
sudo yum install mtr      # CentOS/RHEL

然后運行 mtr

mtr www.example.com

輸出示例:

Start: Mon Mar  1 12:34:56 2021
HOST: router.local         Loss%   Snt   Last   Avg  Best  Wrst StDev
  1.|-- router.local        0.0%    10    1.1    1.2    1.0    1.3   0.1
  2.|-- isp-gateway.example.com 0.0%    10    2.3    2.2    2.1    2.4   0.1
  3.|-- core-router.example.com 0.0%    10    3.5    3.4    3.3    3.6   0.1
  4.|-- www.example.com     0.0%    10    4.6    4.5    4.4    4.7   0.1

4. 使用 iperf 命令

iperf 是一個用于測量網絡帶寬和延遲的工具。

首先在兩臺主機上安裝 iperf

sudo apt-get install iperf3  # Debian/Ubuntu
sudo yum install iperf3      # CentOS/RHEL

在一臺主機上啟動 iperf3 服務器:

iperf3 -s

在另一臺主機上運行 iperf3 客戶端并連接到服務器:

iperf3 -c <服務器IP地址>

輸出示例:

Connecting to host <服務器IP地址>, port 5201
[  4] local <客戶端IP地址> port 54321 connected to <服務器IP地址> port 5201
[ ID] Interval           Transfer     Bandwidth
[  4]   0.00-1.00   sec  1.23 GBytes  1.06 Gbits/sec                  sender
[  4]   1.00-2.00   sec  1.23 GBytes  1.06 Gbits/sec                  sender
[  4]   2.00-3.00   sec  1.23 GBytes  1.06 Gbits/sec                  sender
...

通過這些工具和方法,你可以有效地檢測和分析網絡延遲。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女