ABC of using Traceroute command in Linux
Traceroute command is well known networking utility using which we can determine the number of hops between source & destination of a network packet. Not only does it show the number of hops, we will also get the information regarding the path/servers it goes through.
Traceroute command is well known networking utility using which we can determine the number of hops between source & destination of a network packet.Usually the traceroute command in Linux is used to determine the data loss occurring in the network, as each hop shows the network address of the router or server it passes, we can know at which server or router our packet was lost.
Recommended Read : Monitoring network bandwidth with iftop command
Also Read : Let’s discuss some examples of SED command
In this tutorial, we are going to discuss how we can install traceroute command in Linux & also how to use it to troubleshoot the network.
Install Traceroute command in Linux
Traceroute command comes pre-installed on many Linux distributions but if that’s not the case with you, you can install it using one of the following commands,
CentOS/RHEL/Oracle Linux/Amazon Linux
# yum install traceroute
# apt-get install traceroute
# dnf install traceroute
If using sudo user, than add sudo before the installation command. Now let’s discuss the syntax for using traceroute command in Linux,
# traceroute [option] destination
Now let’s discuss some examples for using traceroute command in Linux.
Examples of traceroute command in Linux
1- Check route for a server
To simply get the route taken by a network packet to get to a certain server or website (for example google), run the following command from the terminal,
$ traceroute google.com
We can run the traceroute against an IP address of a server or website,
$ traceroute 18.104.22.168
As output we will get the following result,
Now output shows the following info,
– First line after the command shows the destination IP address (blacked out in the screenshot),
– Next line after that & all the rest lines shows the hops, their IP address, response time etc.
By default, traceroute command in linux sends 3 packets for each hop, hence we get three response time on each line.
– Sometimes we might get a ‘*’ in place of response time, that shows that we were unable to get a response for that request.
Both examples mentioned above uses IPV4, but to send a query for IPv6 we can use following example as reference,
$ traceroute -6 ipv6.google.com
This example itself is sufficient enough for network troubleshooting but we can also change the default values of traceroute command to satisfy our requirements.
2- Configure TTL for traceroute
By default the TTL value for traceroute command is 1, but we can configure it to some other value using option ‘f’, for example
$ traceroute -f 5 google.com
3- Configure the response wait time
The response wait time can also be changed to a value other than the default value using the option ‘w’,
$ traceroute -w 0.5 google.com
4- Configure number of queries
Per hop, traceroute sends 3 queries/packets & provide 3 round trip time. Now let’s suppose we want to send 4 packets per hop, we can do it using option ‘q’,
$ traceroute -q 4 google.com
5- Disable IP, Hostname mapping
Option ‘n’ can be used with traceroute command to disable IP address & hostname mapping,
$ traceroute -n google.com
6- Configure network interface for traceroute
If using multiple network interfaces on Linux system, we can also configure traceroute to use only a particular interface using option ‘i’,
$ traceroute -i enp2s0 google.com
We now end this tutorial on using traceroute command in Linux, we have only discussed some of the commonly used options of traceroute. There are many more options that can be used with traceroute command, refer to MAN pages for all the available options for traceroute command in Linux.