Linux traceroute Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn about the Linux traceroute command, a network diagnostic tool used to trace the network path to a destination. You will start by ensuring the traceroute command is installed on your system, then use it to trace the network path to a website, and finally explore how traceroute can be used to troubleshoot network issues. The lab covers the essential steps for understanding and utilizing the traceroute command in a practical setting.

The traceroute command sends packets to a destination and displays the route the packets take, along with the time it takes for each hop. This information can be valuable for identifying network problems and understanding the network topology. If the traceroute command is not installed on your system, you will need to install it using the provided commands.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/RemoteAccessandNetworkingGroup(["`Remote Access and Networking`"]) linux/RemoteAccessandNetworkingGroup -.-> linux/netstat("`Network Monitoring`") linux/RemoteAccessandNetworkingGroup -.-> linux/ping("`Network Testing`") subgraph Lab Skills linux/netstat -.-> lab-422965{{"`Linux traceroute Command with Practical Examples`"}} linux/ping -.-> lab-422965{{"`Linux traceroute Command with Practical Examples`"}} end

Introduction to the traceroute Command

In this step, you will learn about the traceroute command in Linux, which is a network diagnostic tool used to trace the network path to a destination. The traceroute command sends packets to a destination and displays the route the packets take, along with the time it takes for each hop.

First, let's check if the traceroute command is installed on your system. Run the following command:

sudo apt-get update
sudo apt-get install -y traceroute

Example output:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libc-ares2 libcap2 libpcap0.8 libssh2-1
Suggested packages:
  rarpd
The following NEW packages will be installed:
  libc-ares2 libcap2 libpcap0.8 libssh2-1 traceroute
0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
Need to get 155 kB of archives.
After this operation, 501 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
...

Now that you have the traceroute command installed, let's try using it to trace the network path to a destination. Run the following command:

traceroute www.example.com

Example output:

traceroute to www.example.com (93.184.216.34), 30 hops max, 60 byte packets
 1  192.168.1.1 (192.168.1.1)  1.123 ms  1.109 ms  1.095 ms
 2  10.0.0.1 (10.0.0.1)  10.234 ms  10.221 ms  10.208 ms
 3  172.16.0.1 (172.16.0.1)  20.345 ms  20.332 ms  20.319 ms
 4  203.0.113.1 (203.0.113.1)  30.456 ms  30.443 ms  30.430 ms
 5  198.51.100.1 (198.51.100.1)  40.567 ms  40.554 ms  40.541 ms
 6  93.184.216.34 (93.184.216.34)  50.678 ms  50.665 ms  50.652 ms

The output shows the network path from your system to the www.example.com website, including the IP addresses and response times for each hop along the way.

The traceroute command can be a valuable tool for troubleshooting network issues, as it can help you identify where in the network path a problem may be occurring.

Tracing the Network Path to a Destination

In this step, you will learn how to use the traceroute command to trace the network path to a destination.

Let's start by tracing the path to a well-known website, such as www.google.com:

traceroute www.google.com

Example output:

traceroute to www.google.com (142.250.66.78), 30 hops max, 60 byte packets
 1  192.168.1.1 (192.168.1.1)  1.123 ms  1.109 ms  1.095 ms
 2  10.0.0.1 (10.0.0.1)  10.234 ms  10.221 ms  10.208 ms
 3  172.16.0.1 (172.16.0.1)  20.345 ms  20.332 ms  20.319 ms
 4  203.0.113.1 (203.0.113.1)  30.456 ms  30.443 ms  30.430 ms
 5  198.51.100.1 (198.51.100.1)  40.567 ms  40.554 ms  40.541 ms
 6  142.250.66.78 (142.250.66.78)  50.678 ms  50.665 ms  50.652 ms

The output shows the network path from your system to the www.google.com website, including the IP addresses and response times for each hop along the way.

You can also use the traceroute command to trace the path to a specific IP address:

traceroute 8.8.8.8

Example output:

traceroute to 8.8.8.8 (8.8.8.8), 30 hops max, 60 byte packets
 1  192.168.1.1 (192.168.1.1)  1.123 ms  1.109 ms  1.095 ms
 2  10.0.0.1 (10.0.0.1)  10.234 ms  10.221 ms  10.208 ms
 3  172.16.0.1 (172.16.0.1)  20.345 ms  20.332 ms  20.319 ms
 4  203.0.113.1 (203.0.113.1)  30.456 ms  30.443 ms  30.430 ms
 5  8.8.8.8 (8.8.8.8)  40.567 ms  40.554 ms  40.541 ms

The traceroute command can be a valuable tool for understanding the network path to a destination and identifying potential issues along the way.

Troubleshooting Network Issues with traceroute

In this step, you will learn how to use the traceroute command to troubleshoot network issues.

Suppose you are trying to access a website, but you are experiencing slow or intermittent connectivity. You can use the traceroute command to identify where the issue might be occurring in the network path.

Let's try an example. Run the following command to trace the path to a website that is not responding:

traceroute www.non-existent-website.com

Example output:

traceroute to www.non-existent-website.com (192.0.2.1), 30 hops max, 60 byte packets
 1  192.168.1.1 (192.168.1.1)  1.123 ms  1.109 ms  1.095 ms
 2  10.0.0.1 (10.0.0.1)  10.234 ms  10.221 ms  10.208 ms
 3  172.16.0.1 (172.16.0.1)  20.345 ms  20.332 ms  20.319 ms
 4  203.0.113.1 (203.0.113.1)  30.456 ms  30.443 ms  30.430 ms
 5  * * *

The output shows that the trace stops at the fourth hop, and the subsequent hops are not responding (indicated by the * symbols). This could indicate a problem with the network connection or a firewall blocking the traffic.

You can also use the traceroute command to identify the specific hop where the issue is occurring. For example, if you notice high latency at a particular hop, you can investigate that hop further to identify the cause of the issue.

Here's an example of using traceroute to identify a slow hop:

traceroute www.example.com

Example output:

traceroute to www.example.com (93.184.216.34), 30 hops max, 60 byte packets
 1  192.168.1.1 (192.168.1.1)  1.123 ms  1.109 ms  1.095 ms
 2  10.0.0.1 (10.0.0.1)  10.234 ms  10.221 ms  10.208 ms
 3  172.16.0.1 (172.16.0.1)  **100.345 ms**  **100.332 ms**  **100.319 ms**
 4  203.0.113.1 (203.0.113.1)  30.456 ms  30.443 ms  30.430 ms
 5  198.51.100.1 (198.51.100.1)  40.567 ms  40.554 ms  40.541 ms
 6  93.184.216.34 (93.184.216.34)  50.678 ms  50.665 ms  50.652 ms

In this example, the third hop is experiencing high latency, which could be a potential bottleneck in the network path.

The traceroute command can be a valuable tool for troubleshooting network issues and identifying where problems might be occurring in the network path.

Summary

In this lab, you learned about the traceroute command in Linux, which is a network diagnostic tool used to trace the network path to a destination. You started by installing the traceroute command on your system, and then used it to trace the network path to the www.example.com website. The output of the traceroute command showed the IP addresses and response times for each hop along the network path. The traceroute command can be a valuable tool for troubleshooting network issues, as it can help you identify where in the network path a problem may be occurring.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like