Linux tracepath Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to use the Linux tracepath command to trace the path taken by packets from the local host to a remote host, and to identify any network issues along the way. The lab covers the purpose of the tracepath command, how to use it to trace the path to a remote host, and how to troubleshoot network issues using the command. You will learn to interpret the output of the tracepath command and use it to identify potential network problems, such as high latency, packet loss, or MTU issues.

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-422964{{"`Linux tracepath Command with Practical Examples`"}} linux/ping -.-> lab-422964{{"`Linux tracepath Command with Practical Examples`"}} end

Understand the Purpose of tracepath Command

In this step, you will learn about the purpose and usage of the tracepath command in Linux. The tracepath command is a network diagnostic tool that is used to trace the path taken by packets from the local host to a remote host, and to identify any intermediate hops or network issues along the way.

The tracepath command is similar to the traceroute command, but it uses the Path MTU Discovery (PMTUD) mechanism to determine the maximum transmission unit (MTU) along the path, which can help identify network issues related to packet fragmentation.

Let's start by running the tracepath command to a remote host:

$ sudo tracepath google.com
 1?: [LOCALHOST]                                         pmtu 1500
 1:  192.168.1.1                                           0.161ms
 1:  192.168.1.1                                           0.158ms
 2:  10.0.0.1                                              1.694ms
 3:  203.0.113.1                                           9.717ms
 4:  142.250.209.174                                      10.843ms
 5:  142.250.209.174                                      10.518ms
     Resume: pmtu 1500 hops 5 back 5

Example output:

The output shows the path taken by the packets from the local host to the remote host google.com. Each line represents a hop in the path, and the output includes the following information:

  • The hop number
  • The IP address of the intermediate router or network device
  • The round-trip time (RTT) for the packet to reach that hop and return to the local host

The tracepath command also reports the maximum transmission unit (MTU) along the path, which is 1500 bytes in this case.

By running the tracepath command, you can identify any network issues or bottlenecks along the path, such as high latency, packet loss, or MTU issues.

Trace the Path to a Remote Host Using tracepath

In this step, you will learn how to use the tracepath command to trace the path to a remote host and identify any network issues along the way.

Let's start by tracing the path to a remote host, such as google.com:

$ sudo tracepath google.com
 1?: [LOCALHOST]                                         pmtu 1500
 1:  192.168.1.1                                           0.161ms
 1:  192.168.1.1                                           0.158ms
 2:  10.0.0.1                                              1.694ms
 3:  203.0.113.1                                           9.717ms
 4:  142.250.209.174                                      10.843ms
 5:  142.250.209.174                                      10.518ms
     Resume: pmtu 1500 hops 5 back 5

Example output:

The output shows the path taken by the packets from the local host to the remote host google.com. Each line represents a hop in the path, and the output includes the following information:

  • The hop number
  • The IP address of the intermediate router or network device
  • The round-trip time (RTT) for the packet to reach that hop and return to the local host

The tracepath command also reports the maximum transmission unit (MTU) along the path, which is 1500 bytes in this case.

You can also use the tracepath command to trace the path to a different remote host, such as example.com:

$ sudo tracepath example.com
 1?: [LOCALHOST]                                         pmtu 1500
 1:  192.168.1.1                                           0.161ms
 1:  192.168.1.1                                           0.158ms
 2:  10.0.0.1                                              1.694ms
 3:  203.0.113.1                                           9.717ms
 4:  93.184.216.34                                        10.843ms
 5:  93.184.216.34                                        10.518ms
     Resume: pmtu 1500 hops 5 back 5

By running the tracepath command to different remote hosts, you can identify any network issues or bottlenecks along the path, such as high latency, packet loss, or MTU issues.

Troubleshoot Network Issues with tracepath

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

Let's start by simulating a network issue by blocking the connection to a remote host using the iptables firewall:

$ sudo iptables -A OUTPUT -d 8.8.8.8 -j DROP

This command will block all outgoing traffic to the IP address 8.8.8.8, which is one of Google's public DNS servers.

Now, let's try to trace the path to 8.8.8.8 using the tracepath command:

$ sudo tracepath 8.8.8.8
 1?: [LOCALHOST]                                         pmtu 1500
 1:  192.168.1.1                                           0.161ms
 1:  192.168.1.1                                           0.158ms
 2:  10.0.0.1                                              1.694ms
 3:  no reply
 4:  no reply
 5:  no reply
     Resume: pmtu 1500 hops 5 back 2

Example output:

The output shows that the tracepath command was able to trace the path up to the third hop, but then encountered a "no reply" message, indicating that the connection was blocked or the remote host was not responding.

To troubleshoot this issue, you can try the following:

  1. Check the firewall rules to ensure that the connection is being blocked as expected:

    $ sudo iptables -L
    Chain OUTPUT (policy ACCEPT)
    target     prot opt source               destination
    DROP       all  --  anywhere             8.8.8.8
  2. Try pinging the remote host to see if the connection is actually blocked:

    $ ping 8.8.8.8
    PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
    ^C
    --- 8.8.8.8 ping statistics ---
    3 packets transmitted, 0 received, 100% packet loss, time 2023ms

    The output shows that the connection is being blocked, as indicated by the 100% packet loss.

  3. Remove the firewall rule to restore the connection:

    $ sudo iptables -D OUTPUT -d 8.8.8.8 -j DROP

By using the tracepath command to identify the point where the connection is being blocked, you can quickly troubleshoot network issues and identify the root cause.

Summary

In this lab, you will learn about the purpose and usage of the tracepath command in Linux, which is a network diagnostic tool used to trace the path taken by packets from the local host to a remote host and identify any intermediate hops or network issues along the way. You will also learn how to use the tracepath command to trace the path to a remote host and troubleshoot network issues using the command's output.

The tracepath command is similar to the traceroute command, but it uses the Path MTU Discovery (PMTUD) mechanism to determine the maximum transmission unit (MTU) along the path, which can help identify network issues related to packet fragmentation. By running the tracepath command, you can identify any network issues or bottlenecks along the path, such as high latency, packet loss, or MTU issues.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like