Install and Use traceroute Command in linux

Install and Use traceroute Command in Ubuntu,CentOS,Fedora

Providing an uninterrupted service in the network and getting optimal performance from the network is a desire that all managers are trying to fulfill. To achieve this goal, a network manager must continuously monitor network performance and use network diagnostic tools to detect connection problems, delays, and possible network performance problems and troubleshooting.

Traceroute is a network diagnostic tool for tracing and understanding the routing of data packets from the origin to the destination, which is used to understand the network path, map the journey of data packets, troubleshoot and diagnose network performance problems (such as network lag and issues connecting to a particular server or website). This guide will introduce you to the valuable Traceroute network diagnostic tool and teach you how to install and use the traceroute command in Ubuntu, CentOS, and Fedora. This article is helpful to become a professional in network management and improve network performance; do not neglect to read it.

Introduction to traceroute

Traceroute is a network diagnostic command-line tool that traces the path of data packets from source to destination over the Internet. When you connect to a remote device in the network, data packets from the source pass through a path consisting of nodes, routers, and network devices to the destination. The traceroute command provides valuable information about IP addresses and domain names of routers and network devices by routing data packets. Also, the traceroute command plays an important role in diagnosing network performance problems by measuring RTT (round-trip time for each hop) and evaluating the delay in the network.

In addition, traceroute is a useful tool for identifying bottlenecks, diagnosing problems connecting to a specific server or website, and specifying where the problem occurs in the network. Therefore, every network administrator needs a powerful and efficient tool like Traceroute for optimal network management; in the following, we will teach how to install traceroute in popular Linux distributions such as Ubuntu, CentOS, and Fedora.

How to install traceroute in Linux Ubuntu, CentOS and Fedora

Fortunately, modern Linux distributions support the valuable Traceroute tool by default, so after purchasing a Linux VPS with your desired distribution through the package manager of your Linux distribution, you can easily install the Traceroute tool from the official Linux repository. To install traceroute on different Linux distributions, you must have sudo privileges and then run the following commands depending on your distribution.

Note: Before running the Traceroute installation command, update your system packages through the package manager of your Linux distribution.

  • Installing traceroute in Ubuntu:
sudo apt install traceroute
  • Installing traceroute in Fedora:
sudo dnf install traceroute
  • Installing traceroute in CentOS/RHEL:
sudo yum install traceroute

After installing the Traceroute network diagnostic tool, make sure that Traceroute is installed on your Linux system by running the following command:

traceroute --version

By displaying the version information of the traceroute, you can verify the successful installation of the traceroute in your Linux system.

Quick tutorial on using traceroute in Linux

Like other Linux command line tools, the traceroute command supports advanced and additional options to expand its functionality in tracing the path of packets and network troubleshooting. As you have already learned how to use Traceroute in Mikrotik, in this part of the article, you will learn the basic usage of the Traceroute command in modern Linux distributions such as Ubuntu, CentOS, and Fedora. To run traceroute and trace the path of packets through the network, enter the following command in the Linux terminal:

traceroute

By typing the target IP address or domain name in the continuation of the traceroute command, a list of routers with IPs that are in the path of the data packet to reach the destination is displayed. For example, to track example.com, run the following command:

traceroute target_ip_or_domain

For example:

traceroute example.com

Or

traceroute www.example.com

When you press Enter after running the previous command, traceroute starts tracing the route to the specified destination and information about hops (routers or network devices) between the specified source and destination along with IP addresses or domain names and round-trip times (latency) for each hop is displayed as the following output:

Sample Output:

traceroute to example.com (93.184.216.34), 30 hops max, 60 byte packets
1  router1 (192.168.1.1)  1.234 ms  2.345 ms  3.456 ms
2  isp-router (203.0.113.1)  10.123 ms  15.678 ms  12.345 ms
3  example-provider (198.51.100.1)  20.456 ms  22.789 ms  18.234 ms
...

The output provides useful information until reaching the final hop, which you can terminate by pressing the “Ctrl+C” buttons from the keyboard.

Basic syntax of the traceroute command

To use the traceroute command to understand packet routing, you must first know the basic syntax of traceroute, which is as follows:

traceroute [options] host_address [path_length]

You can benefit from the Traceroute feature by replacing the desired host address for tracing and the desired packet length in the form of a numeric value in the previous command. It should be noted that the default value of packet size is 60 bytes.

Traceroute options

As we mentioned before, traceroute offers different options and flags for different purposes. The various options for customizing the Traceroute are as follows:

  • -d: debugs the network.
  • -i: specifies the interface of probes.
  • -p: Specifies the specific destination port.
  • -w: Sets the timeout for each probe.
  • -n: displays numerical IP addresses instead of resolving hostnames.
  • -m: specifies the maximum number of hops to trace.
  • -g: sets the route of the gateway.
  • -I: Uses ICMP Echo Request packets for tracing (default).
  • -T: Uses for TCP tracing.

Customizing the number of Probes to trace

By default, the traceroute command sends three probes for each hop. To change the default behavior of traceroute in sending the number of probes per hop, the “-q” option is used. For example, to customize the number of probs to 4 per hope to trace the example.com hostname, run the following command:

traceroute -q 4 example.com

Enabling numerical IP address mapping while tracerouting

Since Traceroute, by default, resolves each hop’s IP address to the hostname and results in a delay in displaying the output, using the “-n” option to disable the resolution of IP addresses to the hostname is useful. So, if, for any reason, you want to get numeric IP addresses while tracing a packet route instead of resolving hostnames, run the following command:

traceroute -n target_ip_or_domain

For example, to trace to example.com without hostname resolution, you can use the following command:

traceroute -n example.com

Setting the number of hops while tracerouting

By default, Traceroute starts from a TTL value of 1 and increments it with each probe packet. TTL or Time-to-Live is a value limiting the number of hops a packet can traverse in the network, which can be changed. The” -f ” flag in the traceroute command customizes and sets the TTL start value for tracing. How to use the -f option is as follows:

traceroute -f ttl_value target_ip_or_domain

For example, if you want to start tracing to example.com with a starting TTL of 3, use the following command:

traceroute -f 3 example.com

In the previous command’s output, the result is displayed from hop number 3, as if the packet has already traveled the first two hops, and tracing starts from the third hop in the network.

Specifying the maximum number of hops to traceroute

The Traceroute will continue tracing until it reaches the destination unless you stop it manually (by pressing Ctrl+C). By default, the number of hops for Query in traceroute is 30, but you can set the maximum number of hops or the TTL value for tracing before stopping route exploration using the “-m” option, whose main syntax is as follows:

traceroute -m max_ttl_value target_ip_or_domain

For example, to trace the route to example.com while limiting the trace to 20hops, run the following command:

traceroute -m 20 example.com

As a result, using the “-m” option, the traceroute command stops tracing after reaching 20 hops, and thus you can prevent the route from continuing indefinitely and check a specific part of the route.

Specifying the maximum waiting time to receive a response from each hop

The “-w” option in the traceroute command configures the maximum time in seconds that you should wait for a response from each hop in the network. The “-w” option is helpful for changing the default time of the traceroute command, which is 3 seconds, and setting the waiting period for a response from any intermediate router. Its main syntax is as follows:

traceroute -w timeout_value target_ip_or_domain

Replace the maximum waiting time for each hop’s response in the “timeout-value“. For example, to trace to example.com with 5 seconds waiting time for each hop, run the following command:

traceroute -w 5 example.com

Specifying the destination port while tracerouting

You can specify the destination port for probe packets sent during tracerouting using the “-p” option. Run the following command to set the custom destination port number:

traceroute -p port_number target_ip_or_domain

For example, to run a traceroute to example.com using port 80, enter the following command:

traceroute -p 80 example.com

Setting the gateway address for routing packets

The “-g” option in the linux traceroute command allows you to specify the loose source routing option to specify the gateway address and series of intermediate routers through which the packet must pass on its path to its destination. The main syntax for specifying the gateway address in packet routing is as follows:

traceroute -g <gateway> <destination>

Replace <gateway> with a list of intermediate router hostnames or router hostnames or IP addresses, and replace <destination> with the IP address or hostname of the final destination to trace the route.

For example, for your packets to first pass through the router with the IP address 192.168.1.1 and then reach the destination 8.8.8.8, run the following command:

traceroute -g 192.168.1.1 8.8.8.8

Specifying the source IP address for the traceroute packets

If you want to send packets from a specific network interface or IP address in your local device during traceroute, you can use the “-s” option in the traceroute command. Using the “-s” option, you can specify the IP address of the source of packets sent during traceroute. How to use the “-s” option in the traceroute command is as follows:

traceroute -s <source_ip> <destination>

For example, to trace the route to the destination 8.8.8.8 and send packets from the source address 192.168.1.100, use the following command:

traceroute -s 192.168.1.100 8.8.8.8

Uninstalling traceroute in Ubuntu, CentOS and Fedora

To uninstall Traceroute in popular Linux distributions such as Ubuntu, CentOS, and Fedora, get help from the package manager for each distribution. It should be noted that you need sudo privileges to uninstall traceroute on Linux distributions. Here are the commands to uninstall Traceroute in Ubuntu, CentOS and Fedora:

  • Uninstall Traceroute in Debian/Ubuntu via apt package manager:
sudo apt remove traceroute
  • Uninstall Traceroute in RHEL/CentOS through the yum package manager:
sudo yum remove traceroute
  • Uninstall Traceroute in Fedora through the dnf package manager:
sudo dnf remove traceroute

After running the uninstall Traceroute commands suitable for the specific Linux distribution, the Traceroute package and its dependencies will be removed from your Linux system.

Conclusion

Traceroute is a valuable network diagnostic tool that plays a useful role in network management, and all network administrators need it. We hope that by reading this article, you have become an expert in using Traceroute and can easily install Traceroute, an efficient network management tool, in a specific distribution of Linux and benefit from its features. The “man traceroute” command will help you in the advanced use of Traceroute by providing the Traceroute help page and displaying the available options and their descriptions. If you have any questions or need help with the Traceroute command, ask us in the comments section, and we will respond as soon as possible.

Leave a Reply

Your email address will not be published. Required fields are marked.