Install and Use Traceroute Command in Linux

This guide intends to teach you to Install and Use Traceroute Command in Linux.

Traceroute is a simple yet clever command-line tool for tracing an IP packet’s path across one or many networks.

Traceroute is used primarily for diagnostic purposes, but it can be a fun tool to learn about networking or satisfy some nerdy curiosity. System administrators and network engineers can use traceroute to see how traffic flows within an organization and identify any irregular or sub-optimal paths.

Externally, a traceroute can display the path of a packet as it traverses many different networks, and in some cases even reveal the different cities or geographic regions traffic flows through.

Steps To Install and Use Traceroute Command in Linux

To complete this guide, log in to your Linux distro and follow the steps below.

Traceroute Installation in Linux

First of all, let’s see how to install Traceroute on Linux.

Install Traceroute on AlmaLinux / Rocky Linux:

dnf install traceroute -y

Install Traceroute on Debian / Ubuntu:

apt-get install traceroute -y

And Install Traceroute on Centos 7 / RHEL 7:

yum install traceroute -y

Syntax of Traceroute Command

The syntax of the traceroute command is mentioned below:

traceroute [options] host_address [path_length]

At this point, let’s see how to use it.

How To Use Traceroute Command in Linux

To get complete usage of Traceroute in Linux, you can simply type the following command in your terminal:

traceroute
Output
Usage:
  traceroute [ -46dFITnreAUDV ] [ -f first_ttl ] [ -g gate,... ] [ -i device ] [ -m max_ttl ] [ -N squeries ] [ -p port ] [ -t tos ] [ -l flow_label ] [ -w MAX,HERE,NEAR ] [ -q nqueries ] [ -s src_addr ] [ -z sendwait ] [ --fwmark=num ] host [ packetlen ]
Options:
  -4                          Use IPv4
  -6                          Use IPv6
  -d  --debug                 Enable socket level debugging
  -F  --dont-fragment         Do not fragment packets
  -f first_ttl  --first=first_ttl
                              Start from the first_ttl hop (instead from 1)
  -g gate,...  --gateway=gate,...
                              Route packets through the specified gateway
                              (maximum 8 for IPv4 and 127 for IPv6)
  -I  --icmp                  Use ICMP ECHO for tracerouting
  -T  --tcp                   Use TCP SYN for tracerouting (default port is 80)
  -i device  --interface=device
                              Specify a network interface to operate with
  -m max_ttl  --max-hops=max_ttl
                              Set the max number of hops (max TTL to be
                              reached). Default is 30
  -N squeries  --sim-queries=squeries
                              Set the number of probes to be tried
                              simultaneously (default is 16)
  -n                          Do not resolve IP addresses to their domain names
  -p port  --port=port        Set the destination port to use. It is either
                              initial udp port value for "default" method
                              (incremented by each probe, default is 33434), or
                              initial seq for "icmp" (incremented as well,
                              default from 1), or some constant destination
                              port for other methods (with default of 80 for
                              "tcp", 53 for "udp", etc.)
  -t tos  --tos=tos           Set the TOS (IPv4 type of service) or TC (IPv6
                              traffic class) value for outgoing packets
  -l flow_label  --flowlabel=flow_label
                              Use specified flow_label for IPv6 packets
  -w MAX,HERE,NEAR  --wait=MAX,HERE,NEAR
                              Wait for a probe no more than HERE (default 3)
                              times longer than a response from the same hop,
                              or no more than NEAR (default 10) times than some
                              next hop, or MAX (default 5.0) seconds (float
                              point values allowed too)
  -q nqueries  --queries=nqueries
                              Set the number of probes per each hop. Default is
                              3
  -r                          Bypass the normal routing and send directly to a
                              host on an attached network
  -s src_addr  --source=src_addr
                              Use source src_addr for outgoing packets

...

Traceroute Usage

For example, you can find the network path from your server to google.com by using the Traceroute command in Linux:

traceroute www.google.com
Example Output
traceroute to www.google.com (172.217.17.100), 30 hops max, 60 byte packets
 1  ... (...)  13.215 ms  13.055 ms  12.828 ms
 2  * * *
 3  * * *
 4  * * *
 5  * * *
 ...

There are a few values on the first line of the output that is described below:

  • The IP address of the destination
  • Number of Hops: it is a numeric value and shows how much time the traceroute will try to reach the destination (the default value is 30)
  • Number of Probes you are sending per Hop or number of packets per Hop (default value is 3)
  • The last central point concerns the size of the packets you send. (its default value is 60bytes)

Limit the Number of Hops with a Traceroute

By default, there are 30 Hops; but you can set your own value by using the “-m” option in the Traceroute command. For example:

traceroute -m 4 google.com
Example output
traceroute to google.com (216.58.214.142), 4 hops max, 60 byte packets
1.* * *
2.* * *
3.* * *
4.* * *

Limit the Number of Probes with a Traceroute

You can set a number of probes using the “-q” flag with traceroute, by default, three probes are displayed at every Hop. For example:

traceroute -q 2 google.com
Example Output
traceroute to google.com (142.250.184.142), 30 hops max, 60 byte packets
 1  * *
...

Set the size of the packet with Traceroute

You can adjust the size of packets being sent per Hop; the default size is 60 bytes. For example:

traceroute google.com 50
Example Output
traceroute to google.com (172.217.20.78), 30 hops max, 50 byte packets
...

Traceroute is a wonderful command for diagnosing and troubleshooting networks. It lets you know the state of your Internet connection. It’s used to determine if the network is working properly and to see how long it takes to reach a remote site.

Conclusion

At this point, you have learned to Install and Use Traceroute Command in Linux.

Hope you enjoy it. Also, you may be like these articles:

Test Network Throughput with Iperf Tool on Linux

How To Install mtr Command on Linux

Manage Networking with Netplan on Debian / Ubuntu

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Stay informed and not overwhelmed, subscribe now!