How to use the command traceroute (with examples)

How to use the command traceroute (with examples)

Traceroute is a command-line tool that allows you to trace the route that packets take from your computer to a specified destination on the internet. It is commonly used to diagnose network connectivity issues and to analyze the performance of network connections.

Use case 1: Traceroute to a host

Code:

traceroute example.com

Motivation: You want to see the route that packets take from your computer to the host “example.com”. Traceroute shows you each hop along the way, including the IP addresses and the round-trip time for each hop.

Explanation: The command “traceroute example.com” sends packets with increasing TTL (Time To Live) values to the destination. Each router along the path decrements the TTL value by 1 and if it reaches 0, the router sends an ICMP “Time Exceeded” message back to the source. This allows traceroute to determine each hop along the route.

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) 34.805 ms  37.488 ms  40.284 ms
 2  10.0.0.1 (10.0.0.1) 48.705 ms  50.320 ms  52.104 ms
 3  203.0.113.1 (203.0.113.1) 61.912 ms  65.789 ms  68.369 ms
 ...

Use case 2: Disable IP address and host name mapping

Code:

traceroute -n example.com

Motivation: By default, traceroute performs reverse DNS lookups to map IP addresses to hostnames. Disabling this mapping with the “-n” option can speed up the traceroute process, especially when some routers along the path have slow DNS servers or no reverse DNS entries.

Explanation: The “-n” option tells traceroute not to perform IP-to-hostname mappings. Instead of showing hostnames, it displays the IP addresses of each hop.

Example Output:

traceroute to example.com (93.184.216.34), 30 hops max, 60 byte packets
 1  192.168.1.1  34.805 ms  37.488 ms  40.284 ms
 2  10.0.0.1  48.705 ms  50.320 ms  52.104 ms
 3  203.0.113.1  61.912 ms  65.789 ms  68.369 ms
 ...

Use case 3: Specify wait time in seconds for response

Code:

traceroute --wait=0.5 example.com

Motivation: By default, traceroute waits for 3 seconds for a response from each hop. Specifying a shorter wait time can reduce the total execution time of the traceroute command when network hops are not responding quickly.

Explanation: The “–wait” option allows you to specify the time in seconds to wait for a response from each hop. In the example above, we set the wait time to 0.5 seconds.

Example Output:

traceroute to example.com (93.184.216.34), 30 hops max, 60 byte packets
 1  192.168.1.1  34.805 ms  37.488 ms  40.284 ms
 2  10.0.0.1  48.705 ms  50.320 ms  52.104 ms
 3  203.0.113.1  61.912 ms  65.789 ms  68.369 ms
 ...

Use case 4: Specify number of queries per hop

Code:

traceroute --queries=5 example.com

Motivation: By default, traceroute sends three probes to each hop. Specifying a larger number of queries can help provide a more accurate measurement of round-trip times and detect intermittent packet loss.

Explanation: The “–queries” option allows you to specify the number of probes to send to each hop. In the example above, we set the number of queries to 5.

Example Output:

traceroute to example.com (93.184.216.34), 30 hops max, 60 byte packets
 1  192.168.1.1  34.805 ms  37.488 ms  40.284 ms
 2  10.0.0.1  48.705 ms  50.320 ms  52.104 ms
 3  203.0.113.1  61.912 ms  65.789 ms  68.369 ms
 ...

Use case 5: Specify size in bytes of probing packet

Code:

traceroute example.com 42

Motivation: By default, traceroute sends packets of size 60 bytes. Specifying a different packet size can help identify issues related to MTU (Maximum Transmission Unit) size on the network path.

Explanation: In this use case, we specified a packet size of 42 bytes for the probing packets.

Example Output:

traceroute to example.com (93.184.216.34), 30 hops max, 42 byte packets
 1  192.168.1.1  34.805 ms  37.488 ms  40.284 ms
 2  10.0.0.1  48.705 ms  50.320 ms  52.104 ms
 3  203.0.113.1  61.912 ms  65.789 ms  68.369 ms
 ...

Use case 6: Determine the MTU to the destination

Code:

traceroute --mtu example.com

Motivation: The MTU (Maximum Transmission Unit) represents the largest packet size that can be sent over a network. Determining the MTU to a destination can help identify issues related to packet fragmentation and reduce network latency.

Explanation: The “–mtu” option tells traceroute to determine the MTU to the specified destination.

Example Output:

traceroute to example.com (93.184.216.34), 30 hops max, 60 byte packets
 1  192.168.1.1  34.805 ms  37.488 ms  40.284 ms
 2  10.0.0.1  48.705 ms  50.320 ms  52.104 ms
 3  203.0.113.1  61.912 ms  65.789 ms  68.369 ms
 ...

Use case 7: Use ICMP instead of UDP for tracerouting

Code:

traceroute --icmp example.com

Motivation: By default, traceroute uses UDP packets to perform the tracerouting. Using ICMP packets instead can help in situations where UDP tracerouting is not allowed or blocked by firewalls.

Explanation: The “–icmp” option tells traceroute to use ICMP (Internet Control Message Protocol) packets for the tracerouting instead of UDP.

Example Output:

traceroute to example.com (93.184.216.34), 30 hops max, 60 byte packets
 1  192.168.1.1  34.805 ms  37.488 ms  40.284 ms
 2  10.0.0.1  48.705 ms  50.320 ms  52.104 ms
 3  203.0.113.1  61.912 ms  65.789 ms  68.369 ms
 ...

Conclusion:

The traceroute command is a powerful tool for diagnosing network issues and analyzing the performance of network connections. By understanding and utilizing its various options, you can gain valuable insights into the routing and performance characteristics of your network.

Related Posts

How to use the command 'tty' (with examples)

How to use the command 'tty' (with examples)

The tty command is used to return the name of the terminal.

Read More
How to use the command dolt merge (with examples)

How to use the command dolt merge (with examples)

Dolt is a version control system (VCS) that allows users to track changes made to a database and collaborate with others.

Read More
How to use the command 'systemd-machine-id-setup' (with examples)

How to use the command 'systemd-machine-id-setup' (with examples)

The command systemd-machine-id-setup is used to initialize the machine ID stored in /etc/machine-id with a provisioned or randomly generated ID.

Read More