Find Number of Hops Using Ping

In the computer networking field, traceroute is a diagnostic tool for displaying the hops and the round-trip time for each hop. Ping, on the other hand, computes round-trip times only from the destination point. But if you are just interested in finding out the number of hops to a destination and not the round-trip times, ping is an alternative utility to traceroute.

To determine the number of hops, we will need to specify the TTL (Time-to-Live) in the ping command using the ‘-t’ option on Unix and Linux. On Windows, the option is ‘-i’ instead. We will need to increase the TTL value till ping does not return any ICMP related error. The smallest TTL value with no errors, is the number of hops required to reach the destination.

With a TTL value of 11, ping gives a “Time to live exceeded” message as well as a 100% packet loss in the statistics. This means that the hop count needs to be increased towards the destination.

ibrahim@anfield:~$ ping -c 2 -t 11 www.apache.org
PING www.apache.org (192.87.106.229) 56(84) bytes of data.
From V1131.sw4.amsterdam1.surf.net (145.145.19.170) icmp_seq=1 Time to live exceeded
From V1131.sw4.amsterdam1.surf.net (145.145.19.170) icmp_seq=2 Time to live exceeded

--- www.apache.org ping statistics ---
2 packets transmitted, 0 received, +2 errors, 100% packet loss, time 999ms

Once the TTL is set to 12, ping gives the normal output result with round-trip times.

ibrahim@anfield:~$ ping -c 2 -t 12 www.apache.org
PING www.apache.org (192.87.106.229) 56(84) bytes of data.
64 bytes from aurora-2012.apache.org (192.87.106.229): icmp_req=1 ttl=53 time=286 ms
64 bytes from aurora-2012.apache.org (192.87.106.229): icmp_req=2 ttl=53 time=289 ms

--- www.apache.org ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 286.954/288.225/289.496/1.271 ms

This means that there are 12 hops to reach the destination. In IPv6, the TTL field has been renamed to Hop Limit.

ibrahim = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, php, python, java, javascript, nodejs, react); plays_on(xbox, ps4); linux_desktop_user(true); }