LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   What exactly does traceroute do? (http://www.linuxquestions.org/questions/linux-newbie-8/what-exactly-does-traceroute-do-4175424809/)

linuxvstheworld 08-30-2012 12:13 PM

What exactly does traceroute do?
 
I'm reading an instructional Linux book and I came across a command named 'traceroute'. From what the book says it seems that it might be the same command as ping. Is it? Or does it do something different?

rknichols 08-30-2012 01:11 PM

traceroute does a lot more than ping. traceroute attempts to elicit a response from each of the routers in the path to a destination. It does this by sending packets with a limited TTL (Time To Live), starting with a limit of 1 (by default -- can be overridden) and then successively larger by an increment of 1. Each router in the path decrements the TTL by 1 and returns an ICMP type 11 ("TTL equals zero") error if the result is zero. The source IP address of each of the returned ICMP packets reveals the addresses of the routers involved.

You don't always get a response from every router in the path. Constructing and returning those ICMP TTL limit messages is often made a low-priority job, so you might not get a response if the router is busy, or the router might be configured to rate-limit such responses, or not to send them at all. Even if a given router does not send a response itself, you can still get responses from routers further down the path.

MensaWater 08-30-2012 01:19 PM

ping simply checks to see if it can reach the given IP and get an ICMP packet returned.

traceroute tries to show you all the intermediate hops that were taken to get to the IP (or alternatively the last hop it got to if it can NOT get to the IP. It is often used for debugging connections that are broken. (That is if you can't ping it then doing a traceroute might help identify where in the chain it is stopping.)

So for example:

$ ping linuxquestions.com
PING linuxquestions.com (174.137.125.65): 56 data bytes
64 bytes from 174.137.125.65: icmp_seq=0 ttl=241 time=78.808 ms
64 bytes from 174.137.125.65: icmp_seq=1 ttl=241 time=79.752 ms
^C
----linuxquestions.com PING Statistics----
2 packets transmitted, 2 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 78.808/79.280/79.752/0.668 ms


$ traceroute linuxquestions.com
traceroute to linuxquestions.com (174.137.125.65), 64 hops max, 52 byte packets
1 vl160-d2.acc.sea2.hopone.net (192.94.73.3) 0.362 ms 0.367 ms 0.250 ms
2 ge4-2.core2.sea2.hopone.net (209.160.60.221) 0.215 ms 0.242 ms 0.249 ms
3 ge4-3.core1.sea1.hopone.net (66.36.224.26) 0.950 ms 1.124 ms 0.996 ms
4 ae0-2.sea20.ip4.tinet.net (77.67.68.81) 0.632 ms 0.667 ms 0.686 ms
5 xe-1-0-0.nyc32.ip4.tinet.net (89.149.184.186) 79.378 ms xe-0-1-0.nyc32.ip4.tinet.net (89.149.181.114) 78.704 ms xe-0-0-1.nyc32.ip4.tinet.net (89.149.184.194) 79.482 ms
6 internap-gw.ip4.tinet.net (216.221.159.206) 78.648 ms 78.148 ms 78.081 ms
7 border4.po1-20g-bbnet1.nym008.pnap.net (216.52.95.5) 78.389 ms 79.030 ms 78.312 ms
8 mpr1.te2-0-0.phi-nym008.phi.pnap.net (216.52.93.94) 80.240 ms 80.335 ms 80.329 ms
9 mpr2-bbnet2.phi.pnap.net (216.52.64.66) 79.727 ms 79.785 ms 80.660 ms
10 voicestar-1.mpr2.phi.pnap.net (216.52.66.122) 80.439 ms 77.527 ms 77.619 ms
11 mdnh-seg36.phl.marchex.com (174.137.125.65) 78.462 ms 78.908 ms 79.022 ms

Both end up showing 174.137.125.65 as the IP for linuxquestions.com (even though they don't resolve to that name in the end) but with traceroute you can see every device it went through to get there.

P.S.
On UNIX/Linux you can find manual pages for most commands so if you type "man traceroute" you can get more detail for it and "man ping" will give you more detail for it. Additionally on Linux there are info pages that may give even more information.

linuxvstheworld 08-30-2012 07:50 PM

Wow, great explanations, thanks!


All times are GMT -5. The time now is 02:52 PM.