10+ traceroute command in Linux [Cheat Sheet]

Introduction to traceroute command

traceroute is a command-line tool that displays the routes taken by network packets to reach the given host. It also helps to find slow traffic between source and destination. traceroute can come in handy when troubleshooting connectivity issues.

How to install traceroute

traceroute command is not available by default on most Linux distributions. You can use the following commands to install traceroute on your system.

Advertisement

Install traceroute on CentOS, RHEL, Fedora

$ sudo dnf install traceroute

Install traceroute on Ubuntu and Debian

$ sudo apt install traceroute

 

Syntax to use traceroute command

The syntax for the traceroute command is as follows:

$ traceroute [option] host

host indicates the name or IP address of the destination host.

 

Different examples to use traceroute command

1. Trace the route to a network host

You can specify the domain name or IP address to trace the route to a network host.

The following example prints the route taken by packets to reach the host golinuxcloud.com.

$ traceroute golinuxcloud.com

Sample Output:

trace the route to a network host

The traceroute command displays the IP addresses through which the packets pass and the time taken by packets to reach the destination.

Advertisement

There are three instances of time in milliseconds as traceroute sends three packets in each hop.

If the destination is not reached, it prints asterisks like in hop 9. It can be caused due to a firewall blocking the network.

 

2. Trace the route using IPv4

The -4 option enables only IPv4 tracerouting to a network host.

$ traceroute -4 golinuxcloud.com

Sample Output:

traceroute using ipv4 protocol

 

3. Trace the route using IPv6

The -6 option allows you to use IPv6 protocol to trace the route to a network host.

$ traceroute -6 gtraolinuxcloud.com

Sample Output:

Advertisement
~]# traceroute -6 2a00:8a00:4000:293::1e0
traceroute to 2a00:8a00:4000:293::1e0 (2a00:8a00:4000:293::1e0), 30 hops max, 80 byte packets
 1  2a00:8a00:4000:293::1e0 (2a00:8a00:4000:293::1e0)  0.074 ms  0.019 ms  0.016 ms

Or alternatively we can also use traceroute6 as shown below:

~]# traceroute6 2a00:8a00:4000:293::1e0
traceroute to 2a00:8a00:4000:293::1e0 (2a00:8a00:4000:293::1e0), 30 hops max, 80 byte packets
 1  2a00:8a00:4000:293::1e0 (2a00:8a00:4000:293::1e0)  0.063 ms  0.017 ms  0.016 ms

 

4. Use ICMP ECHO

By default, the traceroute command uses the UDP ports for tracerouting. To use ICMP ECHO instead of UDP, run the command with -I option.

$ traceroute -I golinuxcloud.com

Sample Output:

traceroute using ICMP ECHO

 

5. Specify the maximum number of hops

The default maximum hops number is 30. You can change its value using the -m option.

$ traceroute -m hop_num golinuxcloud.com

Sample Output:

specify max hops in traceroute

 

6. Specify the interface

With -i flag, you can specify the interface you want to use to send packets to a host.

Advertisement
$ traceroute -i interface google.com

Sample Output:

specify interface in traceroute

 

7. Do not fragment packets

The -F option tells traceroute not to fragment probe packets.

$ traceroute -F golinuxcloud.com

Sample Output:

traceroute command to not fragment packets

 

8. Set the wait time

You can use the -w option to define time in seconds to wait for a response to the next hop. The default value is 5.0 seconds. The float point value is also allowed.

$ traceroute -w time golinuxcloud.com

Sample Output:

set wait time for a response

 

 

9. Set the number of probe packets per hop

The -q option lets you specify the number of probe packets for a hop. The default is 3.

Advertisement
$ traceroute -q num golinuxcloud.com

Sample Output:

The following example sends two packets in each hop to a host.

set number of probe packets per hop

 

10. Do not resolve IP addresses to their domain names

The -n option forces the traceroute command not to map IP addresses to their domain names when displaying them.

$ traceroute -n golinuxcloud.com

Sample Output:

do not resolve ip addresses to their domain names

 

11. Specify the destination port

The -p option is used to specify the destination port number for UDP tracing. The default port value is 33434.

$ traceroute -p port_num golinuxcloud.com

Sample Output:

Advertisement

specify the destination port

 

12. Set the full packet length

The default value of the full packet length is equal to the length of an IP header plus 40. You can change it by passing a new length to the traceroute command.

$ traceroute golinuxcloud.com packetlen

Sample Output:

change full packet length in traceroute

 

Conclusion

Now you should have understood how to use traceroute command to track the packet's route to a network host. We have discussed the most common options used in traceroute commands. We hope you find this tutorial helpful.

If you have any confusion, let us know in the comment section.

 

What’s Next

How to Trace IP Addresses Using Wireshark [Tutorial]
15+ ping command examples in Linux [Cheat Sheet]

 

Further Reading

man page for traceroute command

Advertisement

 

Didn't find what you were looking for? Perform a quick search across GoLinuxCloud

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can either use the comments section or contact me form.

Thank You for your support!!

Leave a Comment

X