liunx禁ping 详解traceroute的不同用法

      最后更新:2022-07-05 23:24:47 手机定位技术交流文章

      在Linux虚拟机上,Ping可以访问目的地地址,但不能追踪路径,只能到关口。

      原因: windows'tracert预配置正在运行ICMP协议,Linux的跟踪路径预先配置为运行UDP协议,如果两个端点之间的UDP连接被任何防火墙封锁,跟踪路径将无法运行。

      解决方案:traceroute-I Add I Parameter Replace ICMP Protocol

      在这里插入图片描述
      在这里插入图片描述
      Linux系统 ping命令是一个常用的网络命令,它通常用于测试与目标主机的连接,我们经常说,"打机器。当你不能打开网页时,你会说,"你先尝试关闭 ping地址。"它向网络主机发送ICMP ECHO_REQUEST包。并显示响应情况,这允许我们根据它输出的信息确定目标主机是否可访问(但这不是绝对)。一些服务器通过 ping来防止检测,禁止通过防火墙或禁止在内核参数中设置,因此,不能通过 ping 确定主机是否仍然开放。

      在Linux下进行的 ping与在Windows下进行的 ping略有不同,并且在Linux下进行的 ping不会以 ctrl+c或-c参数指定的请求完成的响应数自动终止。

      1.命令格式:

      ping [参数] [主机名称或IP地址]

      2.命令功能:

      ping 命令用于: 确定网络和外部主机的状态; 跟踪和隔离硬件和软件问题; 测试、评估和管理网络.如果主机运行并连接到网络上,它响应返回信号。每个继电器信号请求包含一个IP和ICMP头,背部很接近一个时间结构,并且填满这个包中足够的空间。默认是继续发送返回信号请求,直到它接收中断信号(Ctrl-C)。

      ping 命令每秒发送一个数据消息,并为每个接收的响应打印出一个输出线。 ping 命令计算信号返回时间和数据丢失的统计信息。完成后,将简要的总结显示出来.当程序被超时或当SIGINT信号被接收时, ping命令终止。主机参数是有效的主机名称或互联网地址。

      3.命令参数:

      -d使用Socket SO_DEBUG函数。

      -f 限度检测:将一个大、快速的网络包发送到机器,并查看其响应。

      -n 只输出数值。

      -q不显示传输包信息,只显示最终结果。

      -r忽略常规的路由表,直接发送数据包到远程主机,通常是查看主机的网络接口是否有问题。

      -R记录路由过程。

      -v详细说明指令的执行过程。

      -c号: 发送指定的目的地包数后停止.

      -i秒:设置发送网络包到机器的秒间隔,预定值为一秒发送一次。

      -I网络接口:使用指定的网络接口发送包。

      -l预装: 在发送请求信息之前,设置要预先发送的数据包。

      -p模型: 设置一个模型来填充数据包.

      -s数据 Sheets:指定发送的数据 Sheets的数目,预定值为56,加上一个8位ICMP头,总共为64位ICMP数据 Sheets。

      -t内存值:设置内存值TTL的大小。

      4.使用实例:

      例1: Ping的传输

      命令:

      ping 192.168.120.205

      输出:

      复制代码
      [root@localhost ~]# ping 192.168.120.205
      PING 192.168.120.205 (192.168.120.205) 56(84) bytes of data.
      64 bytes from 192.168.120.205: icmp_seq=1 ttl=64 time=0.720 ms
      64 bytes from 192.168.120.205: icmp_seq=2 ttl=64 time=0.181 ms
      64 bytes from 192.168.120.205: icmp_seq=3 ttl=64 time=0.191 ms
      64 bytes from 192.168.120.205: icmp_seq=4 ttl=64 time=0.188 ms
      64 bytes from 192.168.120.205: icmp_seq=5 ttl=64 time=0.189 ms

      — 192.168.120.205 ping statistics —
      5 packets transmitted, 5 received, 0% packet loss, time 4000ms
      rtt min/avg/max/mdev = 0.181/0.293/0.720/0.214 ms
      [root@localhost ~]#
      复制代码
      说明:

      例2: Ping失败

      命令:

      ping 192.168.120.202

      输出:

      复制代码
      [root@localhost ~]# ping 192.168.120.202
      PING 192.168.120.202 (192.168.120.202) 56(84) bytes of data.
      From 192.168.120.204 icmp_seq=1 Destination Host Unreachable
      From 192.168.120.204 icmp_seq=2 Destination Host Unreachable
      From 192.168.120.204 icmp_seq=3 Destination Host Unreachable
      From 192.168.120.204 icmp_seq=4 Destination Host Unreachable
      From 192.168.120.204 icmp_seq=5 Destination Host Unreachable
      From 192.168.120.204 icmp_seq=6 Destination Host Unreachable

      — 192.168.120.202 ping statistics —
      8 packets transmitted, 0 received, +6 errors, 100% packet loss, time 7005ms
      , pipe 4
      [root@localhost ~]#
      复制代码
      说明:

      例3: Ping网络交换机

      命令:

      ping -b 192.168.120.1

      输出:

      复制代码
      [root@localhost ~]# route
      Kernel IP routing table
      Destination Gateway Genmask Flags Metric Ref Use Iface
      192.168.120.0 * 255.255.255.0 U 0 0 0 eth0
      192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0
      10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0
      default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0
      [root@localhost ~]# ping -b 192.168.120.1
      PING 192.168.120.1 (192.168.120.1) 56(84) bytes of data.
      64 bytes from 192.168.120.1: icmp_seq=1 ttl=255 time=2.02 ms
      64 bytes from 192.168.120.1: icmp_seq=2 ttl=255 time=1.83 ms
      64 bytes from 192.168.120.1: icmp_seq=3 ttl=255 time=1.68 ms
      64 bytes from 192.168.120.1: icmp_seq=4 ttl=255 time=1.98 ms
      64 bytes from 192.168.120.1: icmp_seq=5 ttl=255 time=1.88 ms

      — 192.168.120.1 ping statistics —
      5 packets transmitted, 5 received, 0% packet loss, time 4000ms
      rtt min/avg/max/mdev = 1.682/1.880/2.020/0.129 ms
      复制代码
      说明:

      例4:指定的 ping 数目

      命令:

      ping -c 10 192.168.120.206

      输出:

      复制代码
      [root@localhost ~]# ping -c 10 192.168.120.206
      PING 192.168.120.206 (192.168.120.206) 56(84) bytes of data.
      64 bytes from 192.168.120.206: icmp_seq=1 ttl=64 time=1.25 ms
      64 bytes from 192.168.120.206: icmp_seq=2 ttl=64 time=0.260 ms
      64 bytes from 192.168.120.206: icmp_seq=3 ttl=64 time=0.242 ms
      64 bytes from 192.168.120.206: icmp_seq=4 ttl=64 time=0.271 ms
      64 bytes from 192.168.120.206: icmp_seq=5 ttl=64 time=0.274 ms
      64 bytes from 192.168.120.206: icmp_seq=6 ttl=64 time=0.295 ms
      64 bytes from 192.168.120.206: icmp_seq=7 ttl=64 time=0.269 ms
      64 bytes from 192.168.120.206: icmp_seq=8 ttl=64 time=0.270 ms
      64 bytes from 192.168.120.206: icmp_seq=9 ttl=64 time=0.253 ms
      64 bytes from 192.168.120.206: icmp_seq=10 ttl=64 time=0.289 ms

      — 192.168.120.206 ping statistics —
      10 packets transmitted, 10 received, 0% packet loss, time 9000ms
      rtt min/avg/max/mdev = 0.242/0.367/1.251/0.295 ms
      [root@localhost ~]#
      复制代码
      说明:

      例5:带时间间隔和数值限制的 Ping

      命令:

      ping -c 10 -i 0.5 192.168.120.206

      输出:

      复制代码
      [root@localhost ~]# ping -c 10 -i 0.5 192.168.120.206
      PING 192.168.120.206 (192.168.120.206) 56(84) bytes of data.
      64 bytes from 192.168.120.206: icmp_seq=1 ttl=64 time=1.24 ms
      64 bytes from 192.168.120.206: icmp_seq=2 ttl=64 time=0.235 ms
      64 bytes from 192.168.120.206: icmp_seq=3 ttl=64 time=0.244 ms
      64 bytes from 192.168.120.206: icmp_seq=4 ttl=64 time=0.300 ms
      64 bytes from 192.168.120.206: icmp_seq=5 ttl=64 time=0.255 ms
      64 bytes from 192.168.120.206: icmp_seq=6 ttl=64 time=0.264 ms
      64 bytes from 192.168.120.206: icmp_seq=7 ttl=64 time=0.263 ms
      64 bytes from 192.168.120.206: icmp_seq=8 ttl=64 time=0.331 ms
      64 bytes from 192.168.120.206: icmp_seq=9 ttl=64 time=0.247 ms
      64 bytes from 192.168.120.206: icmp_seq=10 ttl=64 time=0.244 ms

      — 192.168.120.206 ping statistics —
      10 packets transmitted, 10 received, 0% packet loss, time 4499ms
      rtt min/avg/max/mdev = 0.235/0.362/1.241/0.294 ms
      [root@localhost ~]# ping -c 10 -i 0.01 192.168.120.206
      PING 192.168.120.206 (192.168.120.206) 56(84) bytes of data.
      64 bytes from 192.168.120.206: icmp_seq=1 ttl=64 time=0.244 ms
      64 bytes from 192.168.120.206: icmp_seq=2 ttl=64 time=0.195 ms
      64 bytes from 192.168.120.206: icmp_seq=3 ttl=64 time=0.219 ms
      64 bytes from 192.168.120.206: icmp_seq=4 ttl=64 time=0.204 ms
      64 bytes from 192.168.120.206: icmp_seq=5 ttl=64 time=3.56 ms
      64 bytes from 192.168.120.206: icmp_seq=6 ttl=64 time=1.93 ms
      64 bytes from 192.168.120.206: icmp_seq=7 ttl=64 time=0.193 ms
      64 bytes from 192.168.120.206: icmp_seq=8 ttl=64 time=0.193 ms
      64 bytes from 192.168.120.206: icmp_seq=9 ttl=64 time=0.202 ms
      64 bytes from 192.168.120.206: icmp_seq=10 ttl=64 time=0.211 ms

      — 192.168.120.206 ping statistics —
      10 packets transmitted, 10 received, 0% packet loss, time 90ms
      rtt min/avg/max/mdev = 0.193/0.716/3.564/1.080 ms
      [root@localhost ~]#
      复制代码
      说明:

      例6:通过域名拨号在公共互联网上的网站

      命令:

      ping -c 5 www.58.com

      输出:

      复制代码
      peida-VirtualBox ~ # ping -c 5 www.58.com
      PING www.58.com (211.151.111.30) 56(84) bytes of data.
      64 bytes from 211.151.111.30: icmp_req=1 ttl=49 time=14.7 ms
      64 bytes from 211.151.111.30: icmp_req=2 ttl=49 time=16.4 ms
      64 bytes from 211.151.111.30: icmp_req=3 ttl=49 time=15.2 ms
      64 bytes from 211.151.111.30: icmp_req=4 ttl=49 time=14.6 ms
      64 bytes from 211.151.111.30: icmp_req=5 ttl=49 time=19.9 ms

      — www.58.com ping statistics —
      5 packets transmitted, 5 received, 0% packet loss, time 20101ms
      rtt min/avg/max/mdev = 14.618/16.192/19.917/1.965 ms
      peida-VirtualBox ~ #
      复制代码
      说明:

      实例7:多参数使用

      命令:

      ping -i 3 -s 1024 -t 255 192.168.120.206

      输出:

      复制代码
      [root@localhost ~]# ping -i 3 -s 1024 -t 255 192.168.120.206
      PING 192.168.120.206 (192.168.120.206) 1024(1052) bytes of data.
      1032 bytes from 192.168.120.206: icmp_seq=1 ttl=64 time=1.99 ms
      1032 bytes from 192.168.120.206: icmp_seq=2 ttl=64 time=0.694 ms
      1032 bytes from 192.168.120.206: icmp_seq=3 ttl=64 time=0.300 ms
      1032 bytes from 192.168.120.206: icmp_seq=4 ttl=64 time=0.481 ms
      1032 bytes from 192.168.120.206: icmp_seq=5 ttl=64 time=0.415 ms
      1032 bytes from 192.168.120.206: icmp_seq=6 ttl=64 time=0.600 ms
      1032 bytes from 192.168.120.206: icmp_seq=7 ttl=64 time=0.411 ms
      1032 bytes from 192.168.120.206: icmp_seq=8 ttl=64 time=0.281 ms
      1032 bytes from 192.168.120.206: icmp_seq=9 ttl=64 time=0.318 ms
      1032 bytes from 192.168.120.206: icmp_seq=10 ttl=64 time=0.362 ms
      1032 bytes from 192.168.120.206: icmp_seq=11 ttl=64 time=0.408 ms
      1032 bytes from 192.168.120.206: icmp_seq=12 ttl=64 time=0.445 ms
      1032 bytes from 192.168.120.206: icmp_seq=13 ttl=64 time=0.397 ms
      1032 bytes from 192.168.120.206: icmp_seq=14 ttl=64 time=0.406 ms
      1032 bytes from 192.168.120.206: icmp_seq=15 ttl=64 time=0.458 ms

      — 192.168.120.206 ping statistics —
      15 packets transmitted, 15 received, 0% packet loss, time 41999ms
      rtt min/avg/max/mdev = 0.281/0.531/1.993/0.404 ms
      [root@localhost ~]#
      复制代码
      说明:

      -i 3 发送周期为3秒 -s 设置发送包的大小为 1024 -t 设置TTL值为 255

      在大多数情况下,作为网络工程技术人员或系统管理员,命令行直接在UNIX主机系统下执行:
      Traceroute hostname
      在Windows下执行TRAcert命令:
      Tracert hostname
      例如,北京地区使用 windows NT主机(在与北京163建立点接点后)
      使用NT系统中的Tracert命令:(用户可用:开始->运行,输入"command" 调出command窗口使用此命令)

      C:>tracert www.yahoo.com

      参数说明:

      tracert [-d] [-h maximum_hops] [-j computer-list] [-w timeout] target_name

      参数
      -d
      指定不分析计算机名称的地址.
      -h maximum_hops
      指定找到目标的最大跳数。
      -jcomputer-list
      在计算机列表中指定一个离散源路由。
      -w timeout
      等待每个响应时限指定的毫秒。
      target_name
      目标计算机的名称。

      追踪路径命令参数:

      追踪路径[选项]数据大小

      [选择]内容包括:

      Traceroute的工作原理:
      Traceroute的最简单的基本使用是: Traceroute主机名

      Traceroute程序使用ICMP和IP标题的TTL(Time To Live)字段设计。首先,跟踪路径发送的TTL是IP数据图的1个(事实上,每个40字节的3包,包括源地址,目的地地址和包装的时间标签)到目的地,当路径上的第一个路由器接收这个数据图时,它将TTL减1。此时,TTL变为0了,所以路由器将丢失这个数据图,并返回“IPMP时间超时”消息(包括IP包的源地址,所有IP包的内容及路由器的IP地址),收到此消息后,跟踪路径知道路由器在这个路径上存在,然后跟踪路径发送另一个TTL是数据图的2,找到第二个路由器..追踪路由器每当数据图的TTL发送, 1 被添加,以找到另一个路由器,这个重复的动作持续到数据图到达目的地为止。当数据图到达目的地时,主机不会返回超过ICMP时间的邮件,因为它已经是目的地,那么你怎么知道你的目的地呢?

      当Traceroute向目的地发送UDP数据图时,它选择发送的端口号码是不会被通用应用程序使用的号码(超过30,00),所以当这个UDP数据图到达目的地时,主要的机会是发送回一个“ICMP端口无法到达”消息,当路由接收这个消息时,你知道目的地已经到达了。Sotraceroute 也 没有 服务器 端 的 所谓 的 emon 程序 。

      Traceroute提取ICMP TTL终止消息设备的IP地址并分析域名。 每次,Traceroute打印一系列数据,包括路由设备的域名和IP地址,每次它需要返回三个数据包。

      Traceroute有一个固定的时间等待响应(ICMP TTL终止消息)。如果这个时间过了,它印出一系列*数字,表示:在这个路径上,该设备不能在指定的时间内响应ICMP TTL终止消息.然后,Traceroute将1添加到TTL计数器中,继续进行。

      本文由 在线网速测试 整理编辑,转载请注明出处,原文链接:https://www.wangsu123.cn/news/29379.html

          热门文章

          文章分类