Table of Contents
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.
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
$ traceroute golinuxcloud.com
The traceroute command displays the IP addresses through which the packets pass and the time taken by packets to reach the destination.
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
-4 option enables only IPv4 tracerouting to a network host.
$ traceroute -4 golinuxcloud.com
3. Trace the route using IPv6
-6 option allows you to use IPv6 protocol to trace the route to a network host.
$ traceroute -6 gtraolinuxcloud.com
~]# 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
$ traceroute -I golinuxcloud.com
5. Specify the maximum number of hops
The default maximum hops number is 30. You can change its value using the
$ traceroute -m hop_num golinuxcloud.com
6. Specify the interface
-i flag, you can specify the interface you want to use to send packets to a host.
$ traceroute -i interface google.com
7. Do not fragment packets
-F option tells traceroute not to fragment probe packets.
$ traceroute -F golinuxcloud.com
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
9. Set the number of probe packets per hop
-q option lets you specify the number of probe packets for a hop. The default is 3.
$ traceroute -q num golinuxcloud.com
The following example sends two packets in each hop to a host.
10. Do not resolve IP addresses to their domain names
-n option forces the traceroute command not to map IP addresses to their domain names when displaying them.
$ traceroute -n golinuxcloud.com
11. Specify the destination port
-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
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
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.