The traceroute command in Linux

Traceroute Command In Linux

traceroute command is a network diagnostic tool that is used to follow the path taken by data packets on their way to the final destination. One of its use is to find the cause of the lag in the connection. It was originally written by Van Jacobson. Almost all the modern operating systems have one or another version of traceroute installed.

How to install traceroute on Linux?

If you don’t have the traceroute package already installed on your system, use your default package manager to install it.

For Ubuntu/Debian based operating systems execute the following apt command with sudo:

sudo apt install traceroute

For CentOS/RedHat based operating systems execute the following yum command with sudo:

sudo yum install traceroute

Once you have the traceroute installed on your system, we can proceed to learn its usage.

Syntax

The syntax for the traceroute command:

traceroute [-46dFITUnreAV] [-f first_ttl] [-g gate,...][-i device] [-m max_ttl] [-p port] [-s src_addr] [-q nqueries] [-N squeries] [-t tos] [-l flow_label] [-w waittime] [-z sendwait] [-UL] [-P proto] [--sport=port] [-M method] [-O mod_options] [--mtu] [--back] host [packet_len]

traceroute6 command is used for IPv6 and is equivalent to the traceroute -6 command.

Using traceroute

A simple traceroute displays the hops from your network to the destination networks and the gateways used in the connection.

traceroute google.com
Traceroute Output
simple traceroute command output

From the output of traceroute in the picture above, we can see that the number of gateways and the hops made in between from our system to google.com

And similarly, for IPv6 use traceroute6 or traceroute -6 command.

Specify the maximum number of the hops that can be made with traceroute

In the traceroute command you can specify the maximum number of hops that can be made in probe using the -m option. The default number of maximum hops is 30.

traceroute -m 4 google.com
Traceroute Command With Maximum Hops Can Be Made
traceroute command with maximum hops that can be made

Setting number of probe packets per hop with traceroute

To set the number of probe packets per hop in traceroute, the -q option is used. The default number of probe packets per hop is 3.

traceroute -q 5 google.com
Traceroute Command With Number Of Probe Packets Per Hop
traceroute command with a number of probe packets per hop

From the output of the traceroute command in the picture above, we can see an asterisk (*) symbol at some places. The asterisk sign signifies no response received in response to the probe packet.

Set size of the probe packets in the traceroute command

To set the size of the probe packets in the traceroute command, specify the size of probe packets after the host in the syntax. The default size of probe packets is 60 bytes.

traceroute google.com 128
Traceroute Command With Specific Probe Packet Size
traceroute command with specific probe packet size

Specify the TTL to start within the traceroute command

traceroute works on TTL (Time-to-Live) to find the destination and the hops in between. The default TTL is set to start with 1. But you can specify the TTL to start with the help of option -f in the traceroute command.

traceroute -f 7 google.com
TTL To Start With In Traceroute Command
TTL to start within traceroute command

To define the port to use in the traceroute command

The -p option is used to define the port in the traceroute command.

traceroute -p 443 google.com
Specify Port In The Traceroute Command 1
Specify port in the traceroute command

traceroute help command

To open traceroute help pages, execute:

traceroute --help
Traceroute Help Command
traceroute help command

Conclusion

traceroute is a handy tool for network diagnostics. It is present in almost all modern operating systems in one or another form. It is available in all popular Linux distributions.

Thank you for reading!