WCC logo

CIS120Linux Fundementals

ping and tracroute Commands

The ping and traceroute commands are essential network diagnostic tools in Linux. These commands help users test connectivity and trace the path packets take to reach a destination, respectively. Understanding how to use these commands and interpret their outputs is crucial for troubleshooting network issues.

The ping Command

The ping command checks the connectivity between your computer and another host. It sends Internet Control Message Protocol (ICMP) Echo Request packets to the target host and waits for Echo Reply packets. This helps determine if the target host is reachable and measures the round-trip time for messages sent.

Basic usage of ping:

ping [options] destination

Commonly Used ping Options:

Option Description
-c Specify the number of packets to send
-i Specify the interval between sending each packet
-t Set the Time to Live (TTL) for packets
-q Quiet output, showing summary only at the end
-s Specify the number of data bytes to be sent
-w Specify a timeout, in seconds, before the command exits

Examples:

To ping a host:

ping google.com

Output:

PING google.com (172.217.16.206) 56(84) bytes of data.
64 bytes from dfw25s14-in-f14.1e100.net (172.217.16.206): icmp_seq=1 ttl=53 time=11.6 ms
64 bytes from dfw25s14-in-f14.1e100.net (172.217.16.206): icmp_seq=2 ttl=53 time=10.8 ms
64 bytes from dfw25s14-in-f14.1e100.net (172.217.16.206): icmp_seq=3 ttl=53 time=10.9 ms
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 10.805/11.113/11.590/0.347 ms

To ping a host with a specific number of packets:

ping -c 4 google.com

Output:

PING google.com (172.217.16.206) 56(84) bytes of data.
64 bytes from dfw25s14-in-f14.1e100.net (172.217.16.206): icmp_seq=1 ttl=53 time=11.6 ms
64 bytes from dfw25s14-in-f14.1e100.net (172.217.16.206): icmp_seq=2 ttl=53 time=10.8 ms
64 bytes from dfw25s14-in-f14.1e100.net (172.217.16.206): icmp_seq=3 ttl=53 time=10.9 ms
64 bytes from dfw25s14-in-f14.1e100.net (172.217.16.206): icmp_seq=4 ttl=53 time=10.7 ms
--- google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3002ms
rtt min/avg/max/mdev = 10.708/11.005/11.586/0.321 ms

The traceroute Command

The traceroute command shows the path that packets take to reach a destination. It sends packets with incrementally increasing Time to Live (TTL) values, causing routers along the path to return ICMP Time Exceeded messages. This helps identify each hop along the route to the destination.

Basic usage of traceroute:

traceroute [options] destination

Commonly Used traceroute Options:

Option Description
-m Set the maximum TTL for packets
-p Set the destination port
-q Set the number of queries per hop
-w Set the time to wait for a response, in seconds
-n Print hop addresses numerically rather than resolving hostnames

Examples:

To trace the route to a host:

traceroute google.com

Output:

traceroute to google.com (172.217.16.206), 30 hops max, 60 byte packets
 1  192.168.1.1 (192.168.1.1)  2.232 ms  2.089 ms  2.055 ms
 2  * * *
 3  10.0.0.1 (10.0.0.1)  11.133 ms  11.052 ms  10.939 ms
 4  172.217.16.206 (172.217.16.206)  10.714 ms  10.544 ms  10.362 ms

The *** in the output indicates that the router at that hop did not respond to the traceroute request within the expected time frame. This can happen due to network congestion, firewalls, or routers configured not to send ICMP Time Exceeded messages.

To trace the route with a maximum of 10 hops:

traceroute -m 10 google.com

Output:

traceroute to google.com (172.217.16.206), 10 hops max, 60 byte packets
 1  192.168.1.1 (192.168.1.1)  2.232 ms  2.089 ms  2.055 ms
 2  * * *
 3  10.0.0.1 (10.0.0.1)  11.133 ms  11.052 ms  10.939 ms
 4  172.217.16.206 (172.217.16.206)  10.714 ms  10.544 ms  10.362 ms

Summary

The ping and traceroute commands are indispensable for network troubleshooting in Linux. The ping command checks connectivity and measures round-trip time between your computer and a host, while the traceroute command traces the path packets take to reach a destination, providing insights into the route and potential points of failure. The *** in the traceroute output indicates non-responsive routers, which can be due to various reasons such as network congestion or firewall settings. By mastering these commands and understanding their outputs, you can effectively diagnose and resolve network issues.