In Linux, the traceroute command allows for tracking the network data paths by providing different control options to manage the network data transfer. Network system administrators must provide the continued data to the user that will go through multiple network-related tests to ensure data continuity. The continuous data is provided with the help of real-time checks by the system network administrators.
This guide will discuss options and uses related to the traceroute command with this flow:
- Prerequisites: Install Traceroute Utility
- What is Traceroute Command in Linux?
- How to Use the Traceroute Command in Linux?
Let’s start the guide!
Prerequisites: Install Traceroute Utility
This command utility is not installed in most Linux distributions, but it can be installed using the following commands:
$ sudo apt install traceroute #for Debian-based Distros. $ sudo yum install traceroute #for CentOS/RHEL. $ sudo pacman -S traceroute #for Arch/Manjaro. $ sudo dnf install traceroute #for Fedora.
Before using traceroute, getting the traceroute utility for your respective distribution is recommended.
What is Traceroute Command in Linux?
The traceroute command utility displays the path details a data packet takes to reach the destination. It traces the path taken by the local machines to connect to a specific website or server. The traceroute command is beneficial for displaying the path of the packets and the number of hops taken by the packets to fetch information for a specific host.
The traceroute provides detailed information about the packet’s path, including the destination name & ip address, the number of hops the packet takes to fetch the data from the host, and the length of the data packet for every hop. The traceroute command utility workflow is given below:
Let’s discuss its syntax and options with the users.
The general syntax of the “traceroute” command is written below:
$ traceroute [options] <host-name or ip-address> [packet-length]
- options: Replace with traceroute command options (includes ipV4 and ipV6).
- hostname: The destination hostname.
- ip-address: Host IP address.
- packet-length: The length of the packet.
The traceroute command comes with these built-in options:
|-d||Prevent traceroute from resolving IP addresses to their respective hostnames for each hop. This typically allows the system to show trace results faster.|
|-h||Specify the highest number of hops included in the traceroute process. If you don’t change the maximum_hops value, it will follow the default maximum of 30 hops.|
|-w||Specify how long the maximum reply time for each hop is before it is considered a timeout. This option is measured in milliseconds.|
|-6||Force the traceroute command to use IPv6.|
|-4||Force the traceroute command to use IPv4.|
Let’s get into the usage of the traceroute command.
How to Use the Traceroute Command in Linux?
As discussed earlier, the traceroute tells the information about the packet path to reach the destination.
Let’s exercise the practical examples of traceroute command:
Example 1: Traceroute for a Website Domain
The traceroute command can be used to track the route of a specific website. The command to trace the route of the system and destination website (in this case: yahoo) is shown below:
$ traceroute www.yahoo.com
The output shows the below properties:
- Destination ip address.
- The maximum number of hops the command will attempt (The above picture shows 20 hops between the computer and the yahoo website).
- The size of the sent data packet.
Example 2: Traceroute a Website for ipV4 Network Interface
A website can be tracked by specifying its supporting network interface with the traceroute command. To track the path of “yahoo” with the option “4” indicating the ipV4 network interface, use this command:
$ traceroute -4 yahoo.com
Example 3: Traceroute a Website for ipV6 Network Interface
We can specify the option “6” for using the ipV6 with the traceroute command for tracing the path of yahoo with the help of the following command:
$ traceroute -6 yahoo.com
The output shows “yahoo” does not support the ipV6 interface.
Example 4: Traceroute for ip Address
We can specify the ip address of the server/machine with the traceroute command to track the path for that ip address. For tracing the path of ip address “18.104.22.168”, execute this command:
$ traceroute 22.214.171.124
Example 5: Traceroute Without Fragment of the Data Packet
The fragment data allows you to manage the stored data packet at different places like Cache, Backups, etc. Suppose you don’t want to fragment data and want to send data directly without saving it. In that case, the “F” option of the traceroute command is utilized as shown below (using yahoo):
$ traceroute -F yahoo.com
Example 6: Traceroute Data Path from Specific Hop
The traceroute command normally traces the path from the first hop to the maximum number of hops. But if you want to follow the specific hops for a data path, the “f” option is utilized. For instance; to trace the hop from 5 to maximum hops for yahoo, run this command:
$ traceroute -f 5 yahoo.com
Example 7: Traceroute Data with Specific Maximum Hops
The system makes hops to fetch the path data for a specific number of hops (by default 30 hops). After the maximum number of hops, the system prevents tracking the path. We can set the maximum number of hops for the traceroute command with the “m” option. For example: to make a maximum of 10 hops for yahoo, the below command is executed:
$ traceroute -m 10 yahoo.com
Example 8: Traceroute Data Path from Specific Gateway
We can route the data packets through a specific gateway utilizing the “g” option. For instance: to route the yahoo from the “192.168.227.128”, run the following command:
$ traceroute -g 192.168.227.128 yahoo.com
Example 9: Traceroute Data Path with Hiding the Destination Name
The “n” option allows you to hide the name of the device (displays ip address) while printing the data paths details. The data paths can be confidential or sometimes clutters the output. To avoid this for yahoo, use this command:
$ traceroute -n yahoo.com
Example 10: Traceroute Data Path from Specific Destination Port
We can track the data of a specific destination port for a system using the “p” option. The default port for the traceroute command is “33434”, but if you want to use a specific port (for instance: “20292”) for yahoo, run this command in the terminal:
$ traceroute -p 20292 yahoo.com
Example 11: Traceroute Path for Specific Number of Probes
The data is generated for a specific number of probes for every hop (by default; 3). We can increase and decrease the number of probes using the “q” options. For example: to set the data probes to “5”, use this command:
$ traceroute -q 5 yahoo.com
Example 12: Traceroute Data Path from Specific Packet Length
The data path is tracked in hops and the specific packet length (in Bytes) for a system. The full packet length is displayed at the output (by default: 60 bytes) for every traceroute command. For instance: to reduce the data packet length to 40 bytes/hop for the yahoo domain, use this command:
Note: The increase in data packet will result in fewer hops with more data.
$ traceroute yahoo.com 40
Example 13: Traceroute Data for Specific Wait Time
The “w” option allows you to set the response wait time for the traceroute command for every display of data hops on the output. The default wait time is 5 minutes, which can be changed accordingly. For instance: to increase the wait time to 10 seconds for yahoo, execute this command:
Note: The increase in response time will get you more data after every response.
$ traceroute -w 10 yahoo.com
Example 14: Traceroute Data Path for ICMP Probe Packets
The ICMP is a messaging protocol used to end the system response checking by the system administrators. If you want the system to end and continue checking for the responses for yahoo, use this command:
Note: ICMP displays the message with details for data paths, which also displays the failed responses.
$ traceroute -I yahoo.com
That’s all from this post!
The traceroute command tracks the path for the data packet to reach the destination; it is used to manage the data packets & hops accordingly. The traceroute command is used to traceroute a specific domain, ip address, specific number of hops, and maximum number of hops for the data packets.
Moreover, we can control the destination port for data packets, the length of each packet, and the specific wait time between the probes. In this article, we have shown you how you can apply the traceroute command in multiple ways.