In networking, understanding the path that data packets take from one point to another is crucial for diagnosing and troubleshooting connectivity issues. One of the most valuable tools for this purpose is the traceroute
command in Linux. Traceroute is a command-line tool used in Linux or other operating systems to track the path that data takes from your computer to a specified destination, such as a website.
When you enter traceroute
a command followed by a destination address, it shows you each “hop” that the data packet makes along its journey. This includes the different servers or devices it passes through and how long each step takes. In this article, we will delve into the intricacies of the traceroute
command, exploring its functionality and options and providing comprehensive examples to illustrate its usage.
What is Traceroute?
The `traceroute`
command is a network diagnostic tool used to trace the route taken by packets from a source to a destination over an IP network. It provides valuable insights into the network path, including the number of hops (routers) between the source and destination and the round-trip time (RTT) for each hop.
Basic Syntax of Traceroute
The basic syntax of the `traceroute`
he command is as follows:
traceroute [options] destination
Options: Various options can be used to customize the behavior of the traceroute command, allowing users to specify parameters such as the maximum number of hops, the number of probes per hop, and the timeout for each probe.
How To Run a Traceroute in Linux?
- Open Terminal on your computer.
- Type “traceroute [hostname]” (replace “[hostname]” with the website or address you want to trace).
- Press Enter.
What is the Difference Between Ping and Traceroute?
The main difference between ping and traceroute is:
- Ping checks if a server is reachable and shows how long it takes to send and receive data.
- Traceroute shows the exact path data takes to reach the server, listing each stop (router) along the way and how long each stop takes.
Troubleshooting With Traceroute
What Factors Impact Hop Times?
The physical distance between your computer and its destination affects how long each hop takes. The further away it is, the longer the hop time. This is important to remember when fixing network issues. Also, the type of connection matters. Computers with faster connections, like Gigabit Ethernet (GE), usually have quicker hop times than those with slower connections.
Additionally, how the data is delivered can make a difference. For example, if data goes through a wireless router shared with several devices, it can be slower than if it’s sent through a dedicated connection like Ethernet or fiber-optic.
When Does High Latency Matter?
High latency is important when data needs to arrive quickly to work properly. For example, sending still images isn’t affected much by latency. But for Voice over Internet Protocol (VoIP) calls or videoconferences, high latency can greatly impact the quality and experience.
Understanding Traceroute Output
When executed, the traceroute
command provides a detailed output that reveals the path taken by packets to reach the destination. Each line in the output represents a hop along the route, displaying the IP address of the router, its hostname (if available), and the round-trip time (RTT) for the probe.
Options Available in Traceroute
Option
|
Description
|
-4
|
Use IPv4
|
-6
|
Use IPv6
|
-F
|
Do not fragment packet
|
-f first_ttl
|
Start from the first TTL hop
|
-g gate
|
Route the packet through gate
|
-m max_ttl
|
Set the max number of hops
|
-n
|
Do not resolve IP addresses to domain names
|
-p port
|
Set the destination port |
-q nqueries
|
Set the number of probes per each hop
|
packetlen
|
The full packet length
|
–help
|
Display help messages and exit
|
Traceroute Command in Linux With Examples
Here in this upcomming section we will giude you through the Traceroute ommand in Linux with examples so if you want to learn about Traceroute command then deep down the below content.
Note: Traceroute is not installed by default in many Linux distributions, but you can easily install it. To use Traceroute, you need to install the Traceroute package. Here’s how you can do it:
sudo apt install traceroute
1. Basic Traceroute Usage
To perform a basic traceroute operation to a destination, simply execute the following command:
traceroute google.com

This command traces the route to the google.com
domain, displaying the IP addresses and round-trip times for each hop along the path.
2. Using IPv4 With Traceroute
The -4
option allows users to specify the use of IPv4 when performing a traceroute operation. This is particularly useful when troubleshooting connectivity or network issues related to IPv4 addresses.
Syntax:
traceroute -4 google.com

Explanation: By using the `-4`
option, traceroute exclusively employs IPv4 addresses to trace the route to the destination `google.com`
3. Using IPv6 With Traceroute
Conversely, the `-6`
option instructs traceroute to use IPv6 addresses for the traceroute operation. This option is essential when dealing with networks that primarily utilize IPv6 addressing.
Syntax:
traceroute -6 google.com

Explanation: By specifying the `-6`
option, traceroute utilizes IPv6 addresses to trace the route to the destination `google.com`
.
4. Do Not Fragment Packet
The `-F`
option prevents packet fragmentation during the traceroute operation. This can be beneficial when troubleshooting network connectivity issues related to packet fragmentation.
Syntax:
traceroute -F google.com

Explanation: By using the `-F`
option, traceroute ensures that packets are not fragmented during the traceroute process to the destination `google.com`
.
5. Starting From a Specific TTL (Time To Live)
The `-f`
option allows users to specify the starting TTL (Time To Live) value for the traceroute operation. This option is helpful when you want to start tracing the route from a specific hop rather than the default starting point.
Syntax:
traceroute -f 10 google.com

Explanation: By providing the `-f`
option followed by the TTL value (e.g., 10), traceroute initiates the traceroute operation from the specified hop to the destination `google.com`
.
6. Routing the Packet Through a Gate
The -g
option enables users to route the packet through a specific gateway during the traceroute operation. This is useful for directing traffic through a specific network path for diagnostic purposes.
Syntax:
traceroute -g 192.168.43.45 google.com

Explanation: By using the `-g`
option followed by the gateway IP address, traceroute routes the packet through the specified gateway to reach the destination `google.com`
.
7. Setting Maximum Number of Hops
The -m
option allows users to set the maximum number of hops for the packet to reach the destination. By default, the maximum Timt to Live (TTL) value is set to 30.
Syntax:
traceroute -m 5 google.com

Explanation: By specifying the `-m`
option followed by the desired TTL value (e.g., 5), traceroute limits the traceroute operation to a maximum of 5 hops to the destination `google.com`
.
8. Disabling IP Address Resolution
The `-n`
option instructs traceroute not to resolve IP addresses to their corresponding domain names. This can speed up the traceroute operation by skipping the Domain Name Server (DNS) resolution process.
Syntax:
traceroute -n google.com

Explanation: By using the `-n`
option, traceroute displays IP addresses instead of resolving them to domain names during the traceroute operation to the destination `google.com`
.
9. Setting Destination Port
The -p
option allows users to specify the destination port to use during the traceroute operation. By default, the destination port is set to 33434. Syntax:
traceroute -p 20292 google.com

Explanation: By providing the `-p`
option followed by the desired port number (e.g., 20292), traceroute uses the specified port for the traceroute operation to the destination `google.com`
.
10. Setting Number of Probes per Hop
The -q
option enables users to set the number of probes sent to each hop during the traceroute operation. By default, three probes are sent per hop.
Syntax:
traceroute -q 1 google.com

Explanation: By using the `-q`
option followed by the desired number of probes (e.g., 1), traceroute sends the specified number of probes per hop during the traceroute operation to the destination `google.com`
.
11. Setting Packet Length
Users can specify the full packet length using the `packetlen`
option. By default, traceroute uses 60-byte packets.
Syntax:
traceroute google.com 100

Explanation: By providing the packet length value (e.g., 100), traceroute utilizes packets with the specified length during the traceroute operation to the destination `google.com`
.
12. Displaying Help Messages
The --help
option displays help messages and exits, providing users with information about the usage and available options of the traceroute command.
Syntax:
traceroute --help

displaying help of traceroute
Explanation: By executing the `traceroute --help`
command, traceroute displays help messages that detail the usage and available options of the traceroute command.
Conclusion
The traceroute
command in Linux offers a wide range of options for tracing the route of packets to a destination. By understanding these options and their syntax, users can effectively diagnose network connectivity issues and troubleshoot routing problems. Whether it’s specifying Internet Protocol versions, controlling packet behavior, or customizing the traceroute operation, the traceroute command provides comprehensive functionality for network analysis and troubleshooting.
Similar Reads
tac command in Linux with Examples
tac command in Linux is used to concatenate and print files in reverse. This command will write each FILE to standard output, the last line first. When no file is specified then this command will read the standard input. Here, we will look deeper into the tac command, exploring its syntax, various o
3 min read
Tail command in Linux with examples
It is the complementary of head command. The tail command, as the name implies, prints the last N number of data of the given input. By default, it prints the last 10 lines of the specified files. If more than one file name is provided then data from each file is preceded by its file name. Syntax of
7 min read
How to Compress Files in Linux | Tar Command
File compression is a fundamental task in managing and transferring data efficiently on a Linux system. The Tar command, short for Tape Archive, is a powerful tool that allows users to create compressed and archived files. In this comprehensive guide, we will explore the various options and examples
11 min read
tee command in Linux with examples
tee command reads the standard input and writes it to both the standard output and one or more files. The command is named after the T-splitter used in plumbing. It basically breaks the output of a program so that it can be both displayed and saved in a file. It does both the tasks simultaneously, c
2 min read
time command in Linux with examples
'time' command in Linux is used to execute a command and prints a summary of real-time, user CPU time and system CPU time spent by executing a command when it terminates. 'real' time is the time elapsed wall clock time taken by a command to get executed, while 'user' and 'sys' time are the number of
6 min read
How to Monitor System Activity in Linux | top Command
top command is used to show the Linux processes. It provides a dynamic real-time view of the running system. Usually, this command shows the summary information of the system and the list of processes or threads which are currently managed by the Linux Kernel. As soon as you will run this command it
10 min read
How to Create an Empty File in Linux | Touch Command
The touch command is a standard command used in the UNIX/Linux operating system which is used to create, change and modify the timestamps of a file. Basically, there are two different commands to create a file in the Linux system which are as follows: touch command: It is used to create a file witho
8 min read
tr command in Unix/Linux with examples
The tr command is a UNIX command-line utility for translating or deleting characters. It supports a range of transformations including uppercase to lowercase, squeezing repeating characters, deleting specific characters, and basic find and replace. It can be used with UNIX pipes to support more comp
4 min read
tracepath command in Linux with Examples
The 'tracepath' command in Linux is a network diagnostic tool used to trace the path packets take to reach a destination, discovering the Maximum Transmission Unit (MTU) along the way. It operates similarly to the traceroute command but does not require superuser privileges and offers a simpler set
2 min read
Traceroute Command in Linux with Examples
In networking, understanding the path that data packets take from one point to another is crucial for diagnosing and troubleshooting connectivity issues. One of the most valuable tools for this purpose is the traceroute command in Linux. Traceroute is a command-line tool used in Linux or other opera
8 min read