Open In App

Traceroute Command in Linux with Examples

Last Updated : 01 Jul, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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.



Next Article

Similar Reads

Article Tags :
three90RightbarBannerImg
  翻译: