How to Use the Command 'traceroute' (with Examples)

How to Use the Command 'traceroute' (with Examples)

The traceroute command is a network utility in Unix-like operating systems that is used to track the pathway of data packets as they travel through various nodes between the source and destination over an IP network. By sending packets with incrementally increasing Time-to-Live (TTL) values and recording the IP address time of each hop, traceroute can identify the route, delays, and any potential bottlenecks or issues in the network pathway, enabling network administrators to troubleshoot connectivity problems effectively.

Traceroute to a Host

Code:

traceroute example.com

Motivation:

This basic usage of the traceroute command is essential for diagnosing network issues by simply revealing the route taken by packets to reach the host example.com. It’s the starting point for understanding where latency or a break in the connection might occur, providing a clear picture of every hop along the path to the destination.

Explanation:

  • traceroute: The main command used to track the route that data packets take to reach a specified host.

Example Output:

traceroute to example.com (93.184.216.34), 30 hops max, 60 byte packets
1  192.168.1.1 (192.168.1.1)  1.118 ms  1.117 ms  1.114 ms
2  10.0.0.1 (10.0.0.1)  2.482 ms  2.480 ms  2.478 ms
3  192.0.2.1 (192.0.2.1)  3.953 ms  3.951 ms  3.948 ms
...

Disable IP Address and Host Name Mapping

Code:

traceroute -n example.com

Motivation:

Disabling IP address and host name mapping is particularly useful when speed is of the essence. By bypassing the DNS resolution stage, which can slow down the process, network administrators can quickly receive raw IP addresses, which is ideal when the primary goal is to discern the network path without the additional layer of DNS translation mechanics.

Explanation:

  • -n: This flag instructs the traceroute command to not attempt to resolve IP addresses to their hostnames, effectively speeding up the command’s output as it eliminates additional DNS lookup time.

Example Output:

traceroute to example.com (93.184.216.34), 30 hops max, 60 byte packets
1  192.168.1.1  1.118 ms  1.117 ms  1.114 ms
2  10.0.0.1  2.482 ms  2.480 ms  2.478 ms
3  192.0.2.1  3.953 ms  3.951 ms  3.948 ms
...

Specify Wait Time in Seconds for Response

Code:

traceroute --wait=0.5 example.com

Motivation:

By specifying a wait time, network administrators can manage how long the traceroute command should wait for a response from each hop. In cases where network latency varies, or when testing a connection over volatile networks, adjusting this wait time allows for capturing data that respects network conditions and personal thresholds for acceptable wait times.

Explanation:

  • --wait=0.5: This option sets the wait time to 0.5 seconds, meaning the command waits this specified time for a response from each hop before considering the attempt as failed and moving onto the next TTL increment.

Example Output:

traceroute to example.com (93.184.216.34), 30 hops max, 60 byte packets
1  192.168.1.1  1.118 ms  1.117 ms  1.114 ms
2  10.0.0.1  2.482 ms  2.480 ms  2.478 ms
3  * * *
4  192.0.2.1  3.953 ms  3.951 ms  3.948 ms
...

Specify Number of Queries per Hop

Code:

traceroute --queries=5 example.com

Motivation:

Increasing the number of queries per hop can give a more accurate statistical representation of the delay and reliability at each step of the route. This becomes particularly important when diagnosing intermittent issues, where network pathways can be inconsistent or unstable, thus requiring a more thorough examination per hop.

Explanation:

  • --queries=5: This flag sets the number of probe packets sent per hop to 5, increasing from the default of 3, to gain more data points per hop which aids in analyzing and diagnosing network stability and congestion issues.

Example Output:

traceroute to example.com (93.184.216.34), 30 hops max, 60 byte packets
1  192.168.1.1  1.118 ms  1.117 ms  1.114 ms  1.112 ms  1.110 ms
2  10.0.0.1  2.482 ms  2.480 ms  2.478 ms  2.476 ms  2.474 ms
3  192.0.2.1  3.953 ms  3.951 ms  3.948 ms  3.946 ms  3.944 ms
...

Specify Size in Bytes of Probing Packet

Code:

traceroute example.com 42

Motivation:

Altering the packet size can help simulate real-world data traffic and detect issues that may occur only under certain conditions of data size. By probing with larger packets, it helps identify problems such as MTU mismatches and fragmented data packets which might not be evident using default sizes.

Explanation:

  • 42: The number at the end specifies the packet size in bytes. This parameter probes with packets of 42 bytes, instead of the default size, allowing for customized tests suitable to particular network analysis needs.

Example Output:

traceroute to example.com (93.184.216.34), 30 hops max, 42 byte packets
1  192.168.1.1  1.118 ms  1.117 ms  1.114 ms
2  10.0.0.1  2.482 ms  2.480 ms  2.478 ms
3  192.0.2.1  3.953 ms  3.951 ms  3.948 ms
...

Determine the MTU to the Destination

Code:

traceroute --mtu example.com

Motivation:

Understanding the Maximum Transmission Unit (MTU) size for the path to a destination helps manage and prevent issues related to packet fragmentation. This is vital when optimizing network performance and ensuring data packets reach their destination without being split into smaller packets due to MTU restrictions by intermediate network devices.

Explanation:

  • --mtu: This flag instructs the traceroute command to discover the MTU along the path. The command will provide the MTU per hop and identify the smallest MTU value, aiding in the identification of the optimal packet sizes for transmission.

Example Output:

traceroute to example.com (93.184.216.34), 30 hops max, 60 byte packets, MTU discovery
1  192.168.1.1 (MTU=1500)  1.118 ms  1.117 ms  1.114 ms
2  10.0.0.1 (MTU=1400)  2.482 ms  2.480 ms  2.478 ms
3  192.0.2.1 (MTU=1300)  3.953 ms  3.951 ms  3.948 ms
...

Use ICMP Instead of UDP for Tracerouting

Code:

traceroute --icmp example.com

Motivation:

Switching to use ICMP (Internet Control Message Protocol) is beneficial in environments where UDP packets are filtered or blocked by firewalls. ICMP packets often have higher success rates for getting through strict network security layers, allowing traceroute to function properly even in controlled network environments.

Explanation:

  • --icmp: This option instructs traceroute to use ICMP ECHO for probes instead of the default UDP. ICMP echoes are similar to the messages used by ping, and are less likely to be blocked in certain network setups.

Example Output:

traceroute to example.com (93.184.216.34), 30 hops max, 60 byte packets using ICMP
1  192.168.1.1  1.118 ms  1.117 ms  1.114 ms
2  10.0.0.1  2.482 ms  2.480 ms  2.478 ms
3  192.0.2.1  3.953 ms  3.951 ms  3.948 ms
...

Conclusion:

The traceroute command serves as a versatile tool for network diagnostics, allowing users to explore various customization options to effectively analyze and resolve connectivity issues. By exploiting these functionalities and comprehending their outputs, network administrators can ensure optimal network performance and connectivity.

Related Posts

How to Use the Command 'cargo vendor' (with Examples)

How to Use the Command 'cargo vendor' (with Examples)

The cargo vendor command is part of Rust’s Cargo package manager, and it plays a crucial role in managing project dependencies.

Read More
How to Use the Command 'pulumi version' (with examples)

How to Use the Command 'pulumi version' (with examples)

The pulumi version command is a simple but essential part of using Pulumiā€”a modern infrastructure as code platform.

Read More
How to Utilize the Get-Content Command in PowerShell (with examples)

How to Utilize the Get-Content Command in PowerShell (with examples)

The Get-Content command in PowerShell is a versatile tool designed to retrieve the content from a specified item, typically a file.

Read More