Traceroute is a tool in Linux that allows you to investigate the routes of network packets. It can help you in identifying the limiting factor of network packet journeys. Traceroute is also useful for troubleshooting sluggish network connections. This guide shows you how to run traceroute in Linux.

About traceroute

Traceroute works by sending packets of data to the target computer, server, or website and recording any intermediate steps through which the packets travel. The output of a traceroute command will be the IP addresses and domain names through which the packets pass. These entries also show how long it takes for the packets to reach each destination. This may explain why some websites may take longer to load than others, as the number of traffic hops can vary.

Traceroute is also useful for mapping local networks. Insight into the topology and connections of the local network is found when running the tool.

Note that while using traceroute, some devices may not interact well. This could be due to routers being bugged, ISPs rate-limiting ICMP messages, devices configured not to send ICMP packets (to prevent distributed DoS attacks), etc. Some networks are also configured to block traceroute requests.

Installing traceroute

Traceroute is a powerful tool that is available for all Linux distros. Provided below is a short list of the commands to install traceroute on various distributions.

For Debian/Ubuntu and derivatives:

$ sudo apt install traceroute -y

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image1-2.png" data-lazy- height="288" src="data:image/svg xml,” width=”1295″>

For Fedora and derivatives:

$ sudo dnf install traceroute

For openSUSE, SUSE Linux, and derivatives:

$ sudo zypper in traceroute

For Arch Linux and derivatives:

$ sudo pacman -S traceroute

Using traceroute

The following sections show you how to use traceroute on your Linux system.

Basic Usage

The primary method for using traceroute is quite simple. All traceroute requires is the destination to perform the probing. The destination can be either a domain or an IP address.

$ traceroute linuxhint.com

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image3-2.png" data-lazy- height="190" src="data:image/svg xml,” width=”1295″>

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image2-2.png" data-lazy- height="188" src="data:image/svg xml,” width=”1294″>

If a network is configured to block the traceroute signal, then this probe will be denoted with asterisks.

IPv4 or IPv6

By default, traceroute will use the default Internet Protocol with which your system is configured. To manually set the IP version, follow the procedure below.

To tell traceroute to use IPv4, use the “-4” flag:

$ traceroute -4 linuxhint.com

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image5-2.png" data-lazy- height="191" src="data:image/svg xml,” width=”1295″>

To tell traceroute to use IPv6, use the “-6” flag:

$ traceroute -6 linuxhint.com

Testing Ports

If there is a need to test a specific port, the port can be specified using the “-p” flag. For UDP tracing, traceroute will start with the given value and increase with each probe. For ICMP tracing, the value will determine the initial ICMP sequence value. For TCP and others, this will be the constant destination port to connect.

$ traceroute -p <port> 192.168.0.1

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image4-2.png" data-lazy- height="194" src="data:image/svg xml,” width=”1293″>

Hiding Device Names

In some situations, the device names in the output may make the output look messy. For more clarity, you can hide the device names from the output. To do so, use the “-n” (no mapping) flag:

$ traceroute -n linuxhint.com

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image7-2.png" data-lazy- height="183" src="data:image/svg xml,” width=”1293″>

Traceroute Timeout Limit

By default, traceroute waits for 5 seconds to receive a response. In certain situations, you may want to change the waiting time to be greater or less than 5 seconds. To do so, use the “-w” flag. Note that the time value is a floating-point number.

$ traceroute -w 6.0 linuxhint.com

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image6-2.png" data-lazy- height="187" src="data:image/svg xml,” width=”1294″>

Probing Methods

There are multiple methods that you can use to probe the remote address. To specify traceroute to use ICMP echo, use the “-I” flag:

$ traceroute -I linuxhint.com

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image9-2.png" data-lazy- height="577" src="data:image/svg xml,” width=”1294″>

To use TCP SYN for probing, use the “-T” flag:

$ sudo traceroute -T linuxhint.com

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image8-2.png" data-lazy- height="190" src="data:image/svg xml,” width=”1296″>

Setting the Maximum Number of Hops

By default, traceroute will track 30 hops. Traceroute offers the ability to manually set the number of hops to track.

Use the “-m” flag with the number of hops:

$ traceroute -I -m 10 linuxhint.com

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image12.png" data-lazy- height="398" src="data:image/svg xml,” width=”1293″>

Specifying the Interface

If there are multiple network interfaces connected to the computer, then it may help to specify the network interface to use for sending packets. To specify the network interface, use the “-i” flag:

$ sudo traceroute -i enp0s3 linuxhint.com

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image10-1.png" data-lazy- height="181" src="data:image/svg xml,” width=”1294″>

Defining the Number of Queries for a Hop

To define the number of queries for a hop, specify this number using the “-q” flag:

$ traceroute -I -q 4 linuxhint.com

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image11.png" data-lazy- height="599" src="data:image/svg xml,” width=”1295″>

Routing Packets through a Gateway

To route packets through a certain gateway, use the “-g” option, followed by the gateway:

$ traceroute -I -g 192.168.0.1 linuxhint.com

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image13.png" data-lazy- height="184" src="data:image/svg xml,” width=”1296″>

Traceroute Help Page

The above demonstrations are just some of the common usages of traceroute, and there are even more features for you to use. To get quick help, open the traceroute help page with the following command:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image14.png" data-lazy- height="620" src="data:image/svg xml,” width=”1295″>

For a fuller, more in-depth guide on all the available traceroute options, check out the man page with the following command:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image15.png" data-lazy- height="622" src="data:image/svg xml,” width=”1293″>

Conclusion

Traceroute is a powerful tool used for network diagnostics, and there are tons of options it supports. Mastering traceroute may require some time and practice. When using this tool, you will often employ the methods described in this article.

There are more tools like traceroute out there. If you are looking to work with a similar tool in GUI, then check out Zenmap to scan a network. Zenmap is a GUI front-end for another popular network scanner called Nmap.

Happy computing!

About the author

<img alt="Sidratul Muntaha" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/profile-photo-1-150×150.jpg" height="112" src="data:image/svg xml,” width=”112″>

Sidratul Muntaha

Student of CSE. I love Linux and playing with tech and gadgets. I use both Ubuntu and Linux Mint.