美文网首页already网络
【traceroute】关于traceroute(路由追踪)的原

【traceroute】关于traceroute(路由追踪)的原

作者: 放纵不基 | 来源:发表于2022-06-04 00:20 被阅读0次

traceroute 主要利用 IP 数据包的 TTL 字段值 + ICMP 来实现,它发送的用于探测网络路径的数据包的 IP 之上的协议可以是 UDP、TCP或ICMP。

# traceroute  --help

Usage:
  traceroute [ -46dFITnreAUDV ] [ -f first_ttl ] [ -g gate,... ] [ -i device ] [ -m max_ttl ] [ -N squeries ] [ -p port ] [ -t tos ] [ -l flow_label ] [                                   -w waittime ] [ -q nqueries ] [ -s src_addr ] [ -z sendwait ] [ --fwmark=num ] host [ packetlen ]
Options:
  -4                          Use IPv4
  -6                          Use IPv6
  -d  --debug                 Enable socket level debugging
  -F  --dont-fragment         Do not fragment packets
  -f first_ttl  --first=first_ttl
                              Start from the first_ttl hop (instead from 1)
  -g gate,...  --gateway=gate,...
                              Route packets through the specified gateway
                              (maximum 8 for IPv4 and 127 for IPv6)
  -I  --icmp                  Use ICMP ECHO for tracerouting
  -T  --tcp                   Use TCP SYN for tracerouting (default port is 80)
  -i device  --interface=device
                              Specify a network interface to operate with
  -m max_ttl  --max-hops=max_ttl
                              Set the max number of hops (max TTL to be
                              reached). Default is 30
  -N squeries  --sim-queries=squeries
                              Set the number of probes to be tried
                              simultaneously (default is 16)
  -n                          Do not resolve IP addresses to their domain names
  -p port  --port=port        Set the destination port to use. It is either
                              initial udp port value for "default" method
                              (incremented by each probe, default is 33434), or
                              initial seq for "icmp" (incremented as well,
                              default from 1), or some constant destination
                              port for other methods (with default of 80 for
                              "tcp", 53 for "udp", etc.)
  -t tos  --tos=tos           Set the TOS (IPv4 type of service) or TC (IPv6
                              traffic class) value for outgoing packets
  -l flow_label  --flowlabel=flow_label
                              Use specified flow_label for IPv6 packets
  -w waittime  --wait=waittime
                              Set the number of seconds to wait for response to
                              a probe (default is 5.0). Non-integer (float
                              point) values allowed too
  -q nqueries  --queries=nqueries
                              Set the number of probes per each hop. Default is
                              3
  -r                          Bypass the normal routing and send directly to a
                              host on an attached network
  -s src_addr  --source=src_addr
                              Use source src_addr for outgoing packets
  -z sendwait  --sendwait=sendwait
                              Minimal time interval between probes (default 0).
                              If the value is more than 10, then it specifies a
                              number in milliseconds, else it is a number of
                              seconds (float point values allowed too)
  -e  --extensions            Show ICMP extensions (if present), including MPLS
  -A  --as-path-lookups       Perform AS path lookups in routing registries and
                              print results directly after the corresponding
                              addresses
  -M name  --module=name      Use specified module (either builtin or external)
                              for traceroute operations. Most methods have
                              their shortcuts (`-I' means `-M icmp' etc.)
  -O OPTS,...  --options=OPTS,...
                              Use module-specific option OPTS for the
                              traceroute module. Several OPTS allowed,
                              separated by comma. If OPTS is "help", print info
                              about available options
  --sport=num                 Use source port num for outgoing packets. Implies
                              `-N 1'
  --fwmark=num                Set firewall mark for outgoing packets
  -U  --udp                   Use UDP to particular port for tracerouting
                              (instead of increasing the port per each probe),
                              default port is 53
  -UL                         Use UDPLITE for tracerouting (default dest port
                              is 53)
  -D  --dccp                  Use DCCP Request for tracerouting (default port
                              is 33434)
  -P prot  --protocol=prot    Use raw packet of protocol prot for tracerouting
  --mtu                       Discover MTU along the path being traced. Implies
                              `-F -N 1'
  --back                      Guess the number of hops in the backward path and
                              print if it differs
  -V  --version               Print version info and exit
  --help                      Read this help and exit

Arguments:
+     host          The host to traceroute to
      packetlen     The full packet length (default is the length of an IP
                    header plus 40). Can be ignored or increased to a minimal
                    allowed value

image.png image.png

协议表示该数据报文所携带的数据所使用的协议类型,占 8 位。
该字段可以方便目的主机的 IP 层知道按照什么协议来处理数据部分。不同的协议有专门不同的协议号。
例如,TCP 的协议号为 6,UDP 的协议号为 17,ICMP 的协议号为 1。

image.png image.png

不同模式下,探测过程中设计的数据包如下:

UDP 模式

UDP 探测数据包(目标端口大于 30000) + 中间网关发回 ICMP TTL 超时数据包 + 目标主机发回 ICMP Destination Unreachable 数据包

image.png

TCP 模式

TCP [SYN] 探测数据包(默认目标端口为 80) + 中间网关发回 ICMP TTL 超时数据包 + 目标主机发回 TCP [SYN ACK] 数据包

ICMP 模式

ICMP Echo (ping) Request 探测数据包 + 中间网关发回 ICMP TTL 超时数据包 + 目标主机发回 ICMP Echo (ping) reply 数据包

image.png

UDP 端口扫描比较麻烦,它同TCP不一样,因为它不需要建立连接。
我们向 目标主机 的固定端口发送UDP数据包,可以得到 两种结果:

  1. 端口开了,UDP 不会给我们任何回复,没办法,谁叫人家是面向无连接的
  2. 端口没开,目标主机端口会给我们回复ICMP的port-unreachable 响应。

在运营商的路由器上,UDP 与 ICMP 的待遇大不相同。
为了利于 troubleshooting,ICMP ECHO Request/Reply 是不会封的,而 UDP 则不同。
UDP 常被用来做网络攻击,因为 UDP 无需连接,因而没有任何状态约束它,比较方便攻击者伪造源 IP、伪造目的端口发送任意多的 UDP 包,长度自定义。
所以运营商为安全考虑,对于 UDP 端口常常采用白名单 ACL,就是只有 ACL 允许的端口才可以通过,没有明确允许的则统统丢弃。比如允许 DNS/DHCP/SNMP 等。

当网络工程师用Ping时,Ping在偷摸做啥事儿?
ping命令是依托于 ICMP协议的, ICMP协议的存在就是为了更高效的转发 IP数据报和提高交付成功的机会。
ping命令除了依托于 ICMP,在局域网下还要借助于 ARP协议, ARP协议能根据 IP地址反查出计算机的 MAC地址。
另外 ARP是有缓存的,为了保证 ARP的准确性,计算机会更新ARP缓存。

image.png

有时我们traceroute 一台主机时,会看到有一些行是以星号表示的。
出现这样的情况,可能是防火墙封掉了ICMP的返回信息,所以我们得不到什么相关的数据包返回数据。
有些路由器会隐藏的自己的位置,不让ICMP Timeout的消息通过,结果就是在那一跳上始终会显示星号。此外服务器也可以伪造traceroute路径的,不过一般应用服务器也没有理由这么做,所以Traceroute的结果还是能够为网络分析提供一些参考的。

Linux下traceroute程序默认发送的探测包为UDP协议,windows下tracert、mtr,以及Linux下mtr默认都发送的是icmp的数据包,并不是所有网关都会如实返回 ICMP 超时报文。处于安全性考虑,大多数防火墙以及启用了防火墙功能的路由器缺省配置为不返回各种 ICMP 报文,其余路由器或交换机也可能被管理员主动修改配置变为不返回 ICMP 报文。因此 Traceroute 程序不一定能拿到所有的沿途网关地址。所以,当某个 TTL 值的数据包得不到响应时,并不能停止这一追踪过程,程序仍然会把 TTL 递增而发出下一个数据包。这个过程将一直持续到数据包发送到目标主机,或者达到默认或用参数指定的追踪限制(maximum_hops 默认最大为30)才结束追踪

如果在局域网中的不同网段之间,我们可以通过traceroute 来排查问题所在,是主机的问题还是网关的问题。
如果我们通过远程来访问某台服务器遇到问题时,我们用到traceroute 追踪数据包所经过的网关,提交IDC服务商,也有助于解决问题;但目前看来在国内解决这样的问题是比较困难的,就是我们发现问题所在,IDC服务商也不可能帮助我们解决。

参考

动态图解traceroute(路由追踪)的原理与实现
https://zhuanlan.zhihu.com/p/404043710

IP数据报格式详解
http://c.biancheng.net/view/6411.html

解析为何traceroute探测的时候中间有些节点探测不到?
https://zhuanlan.zhihu.com/p/122465496

traceroute使用与实现原理分析
https://zhuanlan.zhihu.com/p/36811672

traceroute(路由追踪)的原理及实现
https://www.jianshu.com/p/75a5822d0eec

为什么目标地址ping能通,但是tracetoute不通?
https://cloud.tencent.com/developer/article/1642331

只会用ping测试网络通不通?高级网工还会这么用
https://zhuanlan.zhihu.com/p/458358961

当网络工程师用Ping时,Ping在偷摸做啥事儿?
https://zhuanlan.zhihu.com/p/513184441

traceroute原理
https://www.cnblogs.com/zyd112/p/7196341.html

TCP/UDP/ICMP Traceroute的原理及区别
https://zhuanlan.zhihu.com/p/101810847

相关文章

  • 【traceroute】关于traceroute(路由追踪)的原

    traceroute 主要利用 IP 数据包的 TTL 字段值 + ICMP 来实现,它发送的用于探测网络路径的数...

  • 网络命令原理自我汇总

    常用判断网络是否中断的方法: 1.Traceroute,Tracert traceroute命令用于追踪数据包在网...

  • 【Linux基础】网络故障排除

    网络故障排除 相关命令 ping。检测当前主机和目标主机的联通状况 traceroute。追踪路由。 mtr。检查...

  • Traceroute

    Traceroute是用来侦测主机到目的主机之间所经路由情况的重要工具,也是最便利的工具。 Traceroute的...

  • linux网络相关命令

    traceroute可以让我们看到从源主机到目的主机经过的所有路由traceroute主要利用IP首部的TTL(每...

  • Traceroute 程序

    Traceroute 程序可以让我们看到 IP 数据报从一台主机传到另一台主机所经过的路由。Traceroute ...

  • Traceroute程序

    traceroute程序用来打印出IP数据从一台主机传到另一台主机所经过的路由。 traceroute和IP记录路...

  • TCP/IP详解008Traceroute程序

    Traceroute程序可以让我们看到IP数据报从一台主机传到另一台主机所经过的路由。Traceroute程序还可...

  • 通过Wireshark重新认识Traceroute

    初识Traceroute Traceroute是一种常见的网络分析工具,用于探测数据包从源地址到目的地址经过的路由...

  • TCP-IP详解卷1:协议读书笔记_8

    Traceroute程序 Traceroute程序可以让我们看到IP数据报从一台主机传到另一台主机所经过的路由。T...

网友评论

    本文标题:【traceroute】关于traceroute(路由追踪)的原

    本文链接:https://www.haomeiwen.com/subject/vcshmrtx.html