How to Use traceroute Command in Linux

Employing the traceroute command in Linux can help you investigate various routes of network packets. From identifying the limiting factor packet to troubleshooting all sorts of sluggish connections, the tool is helpful in many ways.

When we talk about traceroute as a tool, it simply works by scouting data packets to the target, system, website, or server. Once done, it tends to record any steps that pave the way for the packets to travel. 

The traceroute command in Linux outputs the IP addresses and the domain names every time. It is those entities through which the concerned packets pass. In this article, we’ll look at the best possible ways of using traceroute.

Installing traceroute in Linux

Before you start using traceroute commands, it is evident that you’ll need to install the tool first. Traceroute is available for every Linux distros and takes different commands for installation. To help you with that, here are the codes that will let you install traceroute on your Linux.

Debian or Ubuntu and derivatives

Run the following command:

$ sudo apt install traceroute -y
Installing traceroute in Linux

openSUSE, SUSE Linux and derivatives

Run the following command:

$ sudo zypper in traceroute

Fedora and derivatives

Run the following command:

$ sudo dnf install traceroute

Arch Linux and derivatives

Run the following command:

$ sudo pacman -S traceroute

Assigning IPv4 or IPv6 to Traceroute in Linux

After installing traceroute in Linux, assigning a protocol to the tool is crucial. You need to keep in mind that the tool uses the default internet protocol. In other words, if your system is configured with IPv4, traceroute will use it, and the same goes for IPv6.

However, you can always use the manual approach and set the desired IP version. For instructing traceroute to use IPv4, run the following command:

$ traceroute -4 distroid.net
traceroute command in linux

And run the following command for making traceroute use IPv6 instead:

$ traceroute -6 distroid.net
traceroute command in linux

Using traceroute in Linux

Now that we’re done talking about the process of installing traceroute in your Linux system and setting up the protocols, let us now walk through its usage. As already mentioned, traceroute is a robust tool for managing and mastering network diagnostics and features several promising utilities.

The usage of traceroute in Linux is pretty straightforward. The most essential thing that the tool requires is indeed a destination. Whether you decide to use a domain or an IP address, a traceroute will use the destination to perform probing.

For Example:

Domain:

$ traceroute distroid.net

IP Address:

$ traceroute 123.123.123.123
using traceroute command in linux

traceroute in Linux for Testing Ports

There are instances when you might need to test a specific port. In that case, traceroute commands play a significant role. Using the -p flag alongside the traceroute command will help you try a port.

In case you’re after the ICMP tracing, the value attained will simply determine the sequence of the ICMP at the initial level. The same for UDP is, however, different. UPD tracing initiates with a given value and then gradually increases with each probe.

$ traceroute -p <port> 192.178.1.1

As you can see from the output, traceroute commands feature device names as well. If it feels a bit messy, you can hide the device names using the -n flag.

$ traceroute -n distroid.net

traceroute Command Probing Methods

Probing remote addresses with traceroute command involves several methods. To direct the tool for using ICMP echo, you’ll need to run the command alongside the -I flag. However, to specify TCP SYN, use the -T flag instead.

ICMP echo

$ sudo traceroute -I distroid.net
traceroute I command

TCP SYN

$ sudo traceroute -T distroid.net
traceroute command TCP SYN

Increasing the Timeout Limit for traceroute Command in Linux

Usually, the traceroute is designed to wait until 5 seconds for a user to input any response. Luckily the same can be increased using the -w flag. In other words, you can desirably choose the timeout period for traceroute to receive a response. 

For Example:

$ sudo traceroute -w 8.0 distoird.net
increasing traceroute timeout

Specifying the Interface for Sending Packets

Wherever there is a situation when a number of network interfaces are connected to a system, specifying network interfaces for sending packets becomes vital. For that, all you need to do is run the traceroute command together with the -i flag.

For Example:

$ sudo traceroute -i enp0s3 distroid.net
specifying interface in traceroute

Setting Hop Volume for traceroute

In case you’re wondering if it is possible to set the volume of hops that the traceroute can track, then the answer is a straightforward yes. Talking about the default scenario, the traceroute is optimized to track 30 hops. However, the value can be manually altered using the -m flag.

For Example:

$ traceroute -I -m 15 distroid.net

Defining Number of Queries Per Hop

To use traceroute in Linux, it is essential to clearly define the number of queries for a hop. Defining the value is pretty easy, and all you need to do is use the command together with the -q flag.

For Example:

$ traceroute -I -q 6 distroid.net

Routing Packets in Linux

For routing packets in Linux through a gateway, you’ll have to use traceroute command with -g flag. Also, the desired gateway must follow the command.

For Example:

$ traceroute -I -g 192.178.1.1 distroid.net

Other Essential traceroute Commands

-f : It is used to set the initial time-to-live, which is employed in the first outgoing probe packet.

-F : The command is used to set the “don’t fragment” bit.

-d : Using this enables the socket level debugging.

-v : Defined for the Verbose output.

-z : Helps in setting the time that pauses between consecutive probes.

-x : This flag is used to toggle IP checksums.

-r Flag: If you’re after bypassing the normal routing tables and then sending them directly to any desired host on a network, use the -r flag.

The commands, as mentioned earlier, form a part of the traceroute usages. If you wish to get a comprehensive overview of the features, the best approach is scouting to the help center.

To get quick help, run the following command:

$ traceroute --help

For an in-depth guide, use the man command instead. 

$ man traceroute

This is everything about the traceroute command in Linux and how to work with it most efficiently. The tool requires some time and practice to master, and this guide is definitely going to help you employ the methods.

If this guide helped you, please share it.

Leave a Reply
Related Posts