Maison  >  Article  >  Tutoriel système  >  Outil de test TCP sous Linux

Outil de test TCP sous Linux

WBOY
WBOYavant
2024-02-11 23:48:28734parcourir

Comment installer tcpping sur Linux

Une façon courante de mesurer la latence du réseau sur un hôte distant consiste à utiliser une application ping应用程序。该ping工具依赖 ICMP ECHO 请求和回复数据包来测量远程主机的往返延迟。但是,在某些情况下,ICMP 流量可能会被防火墙阻止,这使得该ping inutile pour les hôtes derrière des pare-feu restreints. Dans ce cas, vous devrez vous appuyer sur des outils de mesure de couche 3 qui utilisent des paquets TCP/UDP, car ces paquets de couche 3 sont plus susceptibles de contourner les règles de pare-feu courantes.

Outil de test TCP sous Linux

L'un de ces outils de mesure de couche 3 est tcpping. 为了测量延迟,tcpping利用所谓的半开放连接技术,基于 TCP 三路握手。也就是说,它通过端口号(默认为 80)向远程主机发送 TCP SYN 数据包。如果远程主机正在侦听该端口,它将以 TCP ACK 数据包响应。否则,它将以 TCP RST 数据包响应。无论哪种方式,tcppingqui peut mesurer la latence du temps d'aller-retour (RTT) d'un hôte distant en chronométrant les paquets SYN sortants et les paquets ACK (ou RST) entrants.

Installation sous Linuxtcpping

tcpping作为 shell 脚本实现,该脚本响应外部工具来执行和报告 RTT 测量。因此,为了安装tcpping, vous devez d'abord installer ces prérequis.

Installer les dépendances tcptraceroute

Pour installer sur Ubuntu ou Debiantcptraceroute :

$ sudo apt-get install tcptraceroute

Pour installer tcptraceroute sur CentOS ou RHEL, configurez d'abord RepoForge sur votre système, puis exécutez :

$ sudo yum install tcptraceroute 

安装依赖 bc

使用的另一个工具tcpping是GNUbc,它预装在所有主要的 Linux 发行版上。但是,如果你tcpping在最小 Linux 运行时环境(例如Docker容器、AWS 最小映像 AMI)中运行,则bc可能不会预先安装。在这种情况下,你需要bc自己安装。

在Debian 的 Linux 上安装:

$ sudo apt-get install bc  

在 Red Hat 的 Linux 上安装:

$ sudo yum install bc

安装 tcpping

安装这些必备工具后,最后继续tcpping从官方源下载。

$ wget http://www.vdberg.org/~richard/tcpping   
$ cp tcpping /usr/bin   
$ chmod 755 tcpping

使用tcpping来衡量延迟

要使用 测量网络延迟tcpping,你可以使用以下格式。

tcpping [-d] [-c] [-r sec] [-x count] ipaddress [端口]  
  • -d: 在每个结果之前打印时间戳。
  • -c: 使用分列输出以便于解析。
  • -r:连续探测之间的间隔(以秒为单位)(默认为 1 秒)。
  • -x: 重复 n 次(默认无限制)。
  • [port]: 目标端口(默认为 80)。

请注意,你需要 root 权限才能运行,tcpping因为它需要调用特权tcptraceroute命令。

对于任何开放 80 端口的目标 Web 服务器,你可以使用以下方法测量其 RTT 延迟tcpping

tcpping www.rumenz.com  
seq 0: tcp response from 42.194.162.109 (42.194.162.109)   33.822 ms  
traceroute to rumenz.com (42.194.162.109), 255 hops max, 60 byte packets  
seq 1: tcp response from 42.194.162.109 (42.194.162.109)   33.975 ms  
traceroute to rumenz.com (42.194.162.109), 255 hops max, 60 byte packets  
seq 2: tcp response from 42.194.162.109 (42.194.162.109)   32.010 ms  
traceroute to rumenz.com (42.194.162.109), 255 hops max, 60 byte packets  
seq 3: tcp response from 42.194.162.109 (42.194.162.109)   32.209 ms  
traceroute to rumenz.com (42.194.162.109), 255 hops max, 60 byte packets  
seq 4: tcp response from 42.194.162.109 (42.194.162.109)   30.866 ms  
traceroute to rumenz.com (42.194.162.109), 255 hops max, 60 byte packets  
seq 5: tcp response from 42.194.162.109 (42.194.162.109)   34.866 ms  
traceroute to rumenz.com (42.194.162.109), 255 hops max, 60 byte packets  
seq 6: tcp response from 42.194.162.109 (42.194.162.109)   32.604 ms  
traceroute to rumenz.com (42.194.162.109), 255 hops max, 60 byte packets  
seq 7: tcp response from 42.194.162.109 (42.194.162.109)   30.495 ms  

对于任意远程主机,在运行tcpping. 要检查远程 TCP 端口是否打开,你可以使用nc如下命令。

$ nc -vn   

-t: 连续 TCPing ,直到使用 Ctrl+C 键停止

tcping -t 1.1.1.1 80 

-n 5: TCPing 5次后停止

tcping -i 5 1.1.1.1 80

-w 0.5: 设置超时时间为 0.5秒(1秒=1000毫秒),单位 秒

tcping -w 0.5 1.1.1.1 80  

-d:在每行返回信息中加入时间信息

tcping -d 1.1.1.1 80

-s: 当 TCPing 测试成功后(在超时时间以内返回 TCPing 延迟数据)自动停止 TCPing

tcping -s 1.1.1.1 80

-4: 优先 IPv4(如果一个域名有 IPv4 和 IPv6 解析,那么走 IPv4)

tcping -s 1.1.1.1 80 

-6:优先 IPv6(如果一个域名有 IPv4 和 IPv6 解析,那么走 IPv6)

tcping -6 www.rumenz.com 80

--file: TCPing 将逐行循环遍历文件内的 服务器IP/域名 信息(一行一个,支持端口,例如:1.1.1.1 443)

tcping --file rumenz.txt

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Déclaration:
Cet article est reproduit dans:. en cas de violation, veuillez contacter admin@php.cn Supprimer