The Wayback Machine - https://web.archive.org/web/20240717043827/https://www.geeksforgeeks.org/traceroute-command-in-linux-with-examples/
Open In App

Traceroute Command in Linux with Examples

Last Updated : 01 Jul, 2024
Improve
Suggest changes
Post a comment
Like Article
Like
Save
Share
Report

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 the traceroute a command followed by a destination address 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` the 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?

For Mac or Linux

  • Open Terminal on your computer.
  • Type “traceroute [hostname]” (replace “[hostname]” with the website or address you want to trace).
  • Press Enter.

For Windows

  • Go to the Start menu.
  • Select Run.
  • Type in “cmd” and then click “OK.” Command Prompt will open.
  • Type in “tracert [hostname]” and 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

1. Basic Traceroute Usage

To perform a basic traceroute operation to a destination, simply execute the following command:

traceroute google.com

Basic Traceroute Usage

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

Using IPv4 With Traceroute

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

Using IPv6 With Traceroute

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

 Do Not Fragment Packet

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

Starting From a Specific TTL (Time To Live)

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

Routing the Packet Through a Gate

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

 Setting Maximum Number of Hops

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

Disabling IP Address Resolution

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

Setting Destination Port

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

Setting Number of Probes per Hop

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

Setting Packet Length

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

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.

Frequently Asked Questions on Traceroute – FAQs

What does traceroute do?

A traceroute works by sending special messages called Internet Control Message Protocol (ICMP) packets. Each router that helps pass the data along receives these packets. These messages help check if the routers are working properly and can successfully transfer the data.

Are traceroute and tracert the same?

Traceroute and tracert do the same thing. The only difference is that you use the command “traceroute” on Mac and Linux systems, and “tracert” on a Windows system.

What information does Traceroute provide?

Traceroute provides a list of all the routers (hops) your data passes through to reach its destination, along with the time it takes for each hop.

Can Traceroute be used on any operating system?

Yes, Traceroute can be used on most operating systems. The command is traceroute on Mac and Linux, and tracert on Windows.



Previous Article
Next Article

Similar Reads

Traceroute Implementation on Python
In Network information discovery, the traceroute tool is a fundamental utility in a Linux environment. Although the tool is already developed for the command line utility, we can still make our own Traceroute tool using Python language. We will explore the fundamentals of ICMP (Internet Control Message Protocol) and utilize Python's socket programm
9 min read
Ccat – Colorize Cat Command Output command in Linux with Examples
ccat is a command-line tool for Linux and OSX, which is similar to the cat command in Linux. But the difference between cat and ccat is that the ccat shows the content of the file with the syntax highlighted. Currently, ccat supports the following programming languages. JavaScriptJavaRubyPythonGoCJSONInstallation of Ccat First, we are going to see
2 min read
How to Display Command History in Linux | history Command
The command-line interface in Linux provides powerful tools for users, and mastering command history is essential for efficient navigation and retrieval of previously executed commands. The history command is a valuable utility that allows users to view and search through their command history. In this comprehensive guide, we will explore the vario
4 min read
select command in Linux with examples
select command in Linux is used to create a numbered menu from which a user can select an option. If the user enters a valid option then it executes the set of command written in select block and then ask again to enter a number, if a wrong option is entered it does nothing. If user enters nothing and simply press 'enter' the option menu gets print
1 min read
atrm command in Linux with examples
atrm command is used to remove the specified jobs. To remove a job, its job number is passed in the command. A user can only delete jobs that belong to him. Only superuser can delete any job even if that belongs to another user. Syntax: atrm [-V] job [job...] Options: -V : Used to print the version number atrm -V job : Job number of the job which i
1 min read
comm command in Linux with examples
comm compare two sorted files line by line and write to standard output; the lines that are common and the lines that are unique. Suppose you have two lists of people and you are asked to find out the names available in one and not in the other, or even those common to both. comm is the command that will help you to achieve this. It requires two so
5 min read
cmp Command in Linux with examples
cmp command in Linux/UNIX is used to compare the two files byte by byte and helps you to find out whether the two files are identical or not. When cmp is used for comparison between two files, it reports the location of the first mismatch to the screen if difference is found and if no difference is found i.e the files compared are identical.cmp dis
5 min read
expand Command in LINUX with examples
Whenever you work with files in LINUX there can be a situation when you are stuck with a file containing many tabs and whatever you need to do with a file requires that file with no tabs but with spaces. In this situation, the task looks quite simple if you are dealing with a small file but what if the file you are dealing with is very big or you n
3 min read
df Command in Linux with examples
There might come a situation while using Linux when you want to know the amount of space consumed by a particular file system on your LINUX system or how much space is available on a particular file system. LINUX being command friendly provides a command line utility for this i.e df command that displays the amount of disk space available on the fi
8 min read
help Command in Linux with examples
If you are new to LINUX operating system and having trouble dealing with the command-line utilities provided by LINUX then you really need to know first of all about the help command which as its name says help you to learn about any built-in command. help command as told before just displays information about shell built-in commands. Here's the sy
3 min read
Article Tags :