The traceroute Command in LINUX


Introduction

The “traceroute” command is a network diagnostic tool that allows users to track the route that a packet takes from the source computer to the destination. This tool is widely used by network administrators and engineers to troubleshoot network issues such as high latency, packet loss, and connectivity problems.

Traceroute works by sending packets with gradually increasing Time-To-Live (TTL) values to the destination. As each packet reaches a router, the router decrements the TTL value by 1 and discards the packet if the TTL value becomes zero. The traceroute command listens for error messages sent back by the routers and records the IP address of each router that handles the packets.

The traceroute command is available on a variety of operating systems, including Linux. In this article, we will discuss the traceroute command in Linux in depth, including its syntax, options, and examples of how it can be used.

Traceroute Command Syntax

The basic syntax of the traceroute command in Linux is as follows −

$ traceroute [options] destination

The destination can be a hostname or an IP address. Some common options that can be used with the traceroute command include −

  • -I − Use ICMP echo instead of UDP packets

  • -T − Use TCP SYN packets instead of UDP or ICMP

  • -m max_ttl − Specify the maximum number of hops to search for the destination

  • -q nqueries − Specify the number of probes per hop

  • -w waittime − Specify the time (in seconds) to wait for a response

Using the -I option

The traceroute command uses UDP packets by default. However, in some cases, the router or firewall may be blocking UDP packets, which can cause the traceroute command to fail. In such cases, the -I option can be used to use ICMP echo instead of UDP packets.

$ traceroute -I www.google.com

Using the -T option

The traceroute command can also be used to trace the route using TCP SYN packets instead of UDP or ICMP. This can be useful when a firewall is blocking UDP or ICMP packets.

$ traceroute -T www.google.com

Using the -m option

The traceroute command uses a default maximum number of hops (30) to reach the destination. However, in some cases, the destination may not be reachable within the default number of hops. In such cases, the “-m” option can be used to specify the maximum number of hops to search for the destination.

$ traceroute -m 15 www.google.com

Using the -q option

By default, the traceroute command sends only one probe per hop. However, in some cases, more information is needed about a specific hop. In such cases, the “-q” option can be used to specify the number of probes per hop.

$ traceroute -q 15 www.google.com

Example usage of traceroute command

Let's take a look at some examples of how the traceroute command can be used in practice.

Example 1 

Tracing the route to a website

$ traceroute www.google.com
traceroute to www.google.com (142.251.46.228), 30 hops max, 60 byte packets
 1  * * *
 2  10.88.3.230 (10.88.3.230)  1.396 ms 10.88.3.228 (10.88.3.228)  1.459 ms 10.88.3.222 (10.88.3.222)  1.410 ms
…………
 9  66.249.94.29 (66.249.94.29)  3.020 ms 209.85.250.83 (209.85.250.83)  2.457 ms sfo03s27-in-f4.1e100.net (142.251.46.228)  1.309 ms

In this example, the traceroute command is used to trace the route to the "www.google.com" website. The output shows the IP addresses and hostnames of the routers that handle the packets, as well as the time (in milliseconds) taken for each probe to reach the hop and return. We can see that it took 13 hops to reach the destination, starting from the source IP “192.168.1.1”. The last hop is the IP address “142.251.46.228”, which is the IP address of the "www.google.com" website.

Example 2 

Tracing the route to an IP address

$ traceroute 8.8.8.8
traceroute to 8.8.8.8 (8.8.8.8), 30 hops max, 60 byte packets
 1  * * *
…………
 5  138.68.33.9 (138.68.33.9)  4.040 ms  4.034 ms  4.020 ms
 6  * * *
 7  142.251.70.106 (142.251.70.106)  5.344 ms dns.google (8.8.8.8)  2.114 ms  2.051 ms

In this example, the traceroute command is used to trace the route to the IP address “8.8.8.8”, which is one of Google's public DNS servers. The output shows the same information as the previous example, with the IP addresses and hostnames of the routers that handle the packets, as well as the time (in milliseconds) taken for each probe to reach the hop and return. We can see that it took 7 hops to reach the destination, starting from the source IP “192.168.1.1”. The last hop is the IP address “8.8.8.8”, which is the destination IP address.

Conclusion

The traceroute command is a powerful network diagnostic tool that allows users to track the route of a packet from the source to the destination. It can be used to troubleshoot network issues such as high latency, packet loss, and connectivity problems by identifying the specific hop or router where the problem is occurring. Understanding the traceroute command, its options and examples discussed in this article can help network administrators and engineers to diagnose and solve network problems more effectively in Linux.

Updated on: 26-Feb-2024

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements