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 www.golinuxcloud.com
.
$ traceroute www.golinuxcloud.com
Sample Output:
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
The -4
option enables only IPv4 tracerouting to a network host.
$ traceroute -4 www.golinuxcloud.com
Sample Output:
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:
~]# 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 www.golinuxcloud.com
Sample Output:
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 www.golinuxcloud.com
Sample Output:
6. Specify the interface
With -i
flag, you can specify the interface you want to use to send packets to a host.
$ traceroute -i interface google.com
Sample Output:
7. Do not fragment packets
The -F
option tells traceroute not to fragment probe packets.
$ traceroute -F www.golinuxcloud.com
Sample Output:
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 www.golinuxcloud.com
Sample Output:
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.
$ traceroute -q num www.golinuxcloud.com
Sample Output:
The following example sends two packets in each hop to a host.
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 www.golinuxcloud.com
Sample Output:
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 www.golinuxcloud.com
Sample Output:
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 www.golinuxcloud.com packetlen
Sample Output:
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