Home » 2014 » September » 26 » Traceroute command in Linux

6:56 PM
Traceroute command in Linux

Share on Google+

The command is used to get all the hops through which the packet is passing.


DESCRIPTION
       traceroute  tracks  the  route  packets take across a TCP/IP network on their way to a given host.

See the same command TRACERT in windows command line

How it works

  • Tracert utility uses the ttl field of ip packet header to accomplish its goal. TTL field(usually set to 32 or 64) tells us the number of hops a packet will have travel to reach to its destination host.
  • Each time a packet passes a hop, the ttl value is decreased by one and when the TTL value at an intermediate hop (router) become s 1, the packet is discarded.
  • Traceroute requires the same and it incrementally gives the ip addresses of the hops through which the packet passes.
  • It utilizes the IP protocol's time to live (TTL) field and attempts to elicit an ICMP TIME_EXCEEDED response from each gateway along the path to the host.
  • We have to supply only name or IP address of the destination host. This paremeter can be followed by the size of the probing packet [packetlen] sent to that host (40 by default).
  • By default this command  will use first  ttl as 1, maximum 30 hops. port no. as 33434 and packates of length 40 byte  using UDP protocol

usage: traceroute [-nFV] [-f first_ttl] [-m max_hops] [-p port]
           [-S source_addr] [-I interface] [-g gateway]
           [-t tos] [-w timeout] [-q nqueries] host [packetlen]

 


-m max_hops
              Specifies the maximum number of hops traceroute will probe. The default value is 30.

-f first_ttl
              Specifies with what TTL to start. Defaults to 1.

-w sec Wait for sec seconds before sending the next probe packet.


Lets us see below example to understand it properly.

We are trying to reach the ip address 172.31.52.65. We will see what all hops the packets go through to reach this ip and how much time it takes to pass from one hop to another.

localhost:/home/shanky/:>traceroute 172.31.52.65
traceroute to 172.31.52.65 (172.31.52.65), 30 hops max, 40 byte packets using UDP
 1  160.46.147.2 (160.46.147.2)  0.470 ms   0.506 ms   0.256 ms
 2  192.168.40.53 (192.168.40.53)  0.248 ms 192.168.40.65 (192.168.40.65)  0.246 ms   0.214 ms
 3  10.100.70.14 (10.100.70.14)  1.627 ms   0.900 ms 10.100.70.18 (10.100.70.18)  0.851 ms
 4  192.168.42.150 (192.168.42.150)  0.237 ms   0.243 ms   0.239 ms
 5  10.5.84.37 (10.5.84.37)  0.460 ms   0.468 ms   0.444 ms
 6  10.5.82.229 (10.5.82.229)  6.751 ms   6.528 ms   6.563 ms
 7  10.5.82.230 (10.5.82.230)  9.773 ms   10.092 ms   9.653 ms
 8  172.26.130.38 (172.26.130.38)  9.927 ms   9.825 ms   9.920 ms
 9  * * *
10  * * *
11  * * *
12  pf02801.f.nlde (172.31.52.65)  9.894 ms   10.060 ms   10.057 ms

From the above example we can see that the packets are going through below IPs to reach to 172.31.52.65.

Hops | IP Address              |             Min     |           Max       |     Average 


1       160.46.147.2 (160.46.147.2)  28.230 ms   25.596 ms   21.790 ms


 2       192.168.40.53 (192.168.40.53)  0.238 ms 192.168.40.65 (192.168.40.65)  0.253 ms   0.218 ms


 3       10.100.70.14 (10.100.70.14)  0.878 ms   0.724 ms 10.100.70.18 (10.100.70.18)  0.749 ms


 4       192.168.42.150 (192.168.42.150)  0.247 ms   0.252 ms   0.246 ms


 5       10.5.84.37 (10.5.84.37)  0.447 ms   0.426 ms   0.427 ms


 6       10.5.82.229 (10.5.82.229)  6.719 ms   6.573 ms   6.526 ms


 7       10.5.82.230 (10.5.82.230)  9.706 ms   9.584 ms   9.640 ms


 8       172.26.130.38 (172.26.130.38)  9.957 ms   9.896 ms   9.947 ms
 

  • Here, if I select any ip address which is in between the system and the host I am tracing and I try to do a traceroute on that:

localhost:/home/shanky:>traceroute 10.100.70.14
traceroute to 10.100.70.14 (10.100.70.14), 30 hops max, 40 byte packets using UDP
 1  160.46.147.2 (160.46.147.2)  0.326 ms   0.235 ms   0.317 ms
 2  192.168.40.53 (192.168.40.53)  0.234 ms   0.224 ms   0.216 ms
 3  10.100.70.14 (10.100.70.14)  0.777 ms * *

Here we can see that we are getting only two hops  160.46.147.2 & 192.168.40.53 because the ip packet is going through only these two hops to reach 10.100.70.14


  • If you want to disable to display  the hostname or ip name for the hops you can use -n option. See below example:

shanky@localhost:/home/shanky:> traceroute siapp14.muc
traceroute to siapp14.muc (160.46.161.114), 30 hops max, 40 byte packets
 1  160.50.76.3 (160.50.76.3)  0.404 ms   0.350 ms   0.376 ms
 2  192.168.44.22 (192.168.44.22)  0.259 ms   0.237 ms   0.218 ms
 3  siapp14c1.muc (160.46.161.114)  0.566 ms   0.474 ms   0.912 ms


shanky@localhost:/home/shanky:> traceroute siapp14.muc -n
traceroute to siapp14.muc (160.46.161.114), 30 hops max, 40 byte packets
 1  160.50.76.3 (160.50.76.3)  0.441 ms   0.344 ms   0.442 ms
 2  192.168.44.22 (192.168.44.22)  0.206 ms   0.205 ms   0.171 ms
 3  160.46.161.114 (160.46.161.114)  0.535 ms   0.442 ms   0.425 ms

 
 

Category: Open System-Linux | Views: 1656 | Added by: shanky | Tags: tracert, shanky's portal, traceroute, count number of hops in linux, trace ip packets in linux, traceroute command in unix | Rating: 0.6/7

Related blogs


You may also like to see:


[2014-02-19][Open System-Linux]
Shift Key is not working!! Mapping keyboard keys from one to another
[2017-08-13][Open System-Linux]
Perl trick to remove Ctrl - M charater from a file
[2014-10-04][Open System-Linux]
SYSCTL : A command to configure kernel parameters at runtime in linux
[2015-03-23][Open System-Linux]
FSCK : Checking and reparing filesystems in Linux
[2015-04-23][Open System-Linux]
15 Great DATE command examples

Total comments: 0
avatar