Traceroute (tracert) implementation principle 2008.11.4
The implementation of the traceroute program mainly involves the use of the time to live (TTL) field of the IP header.
The TTL field is set to prevent endless flow of data in the network due to incorrect routing or other software and hardware reasons. The TTL field specifies the TTL of the data. The initial value of TTL is set by the source host. When a data packet passes through the router, the router that processes the data packet must subtract the TTL value from the number of seconds that the data packet stays in the router. But in fact, most routers simply reduce the TTL value by 1, so the TTL field is eventually implemented as a hop counter. When the value of the TTL field is reduced to 0, the router will not forward the datagram, but discard it and generate an ICMP timeout error message sent to the source host to notify the occurrence of the error. The key to the traceroute program is that the source address of the returned ICMP timeout error message is the IP address passing through the router. By increasing the value of the TTL field in turn, you can obtain the route information of a datagram on its transmission path.
The traceroute program sendsEcho Request)Message, And the IP header TTL field value is increased repeatedly. At the beginning, TTL is equal to 1. In this way, when the first vro arrives, the TTL value is reduced to 0, resulting in a timeout error. Therefore, the vro generates a copy.ICMP timeout error messageReturn to the source host. Then, the host sendsThe TTL value increases by 1.So that IP packets can be transmitted to the next vro. The next vro will generate an ICMP timeout error message and return it to the source host. Repeat this process until the datagram arrives at the final destination host. At this time, the destination host will returnEcho Replay)Message. In this way, the source host only needs to parse each returned ICMP packet, and can grasp the routing information of the datagram on the way from the source host to the target host.