CIS120 Linux Fundamentals by Scott Shaper

ping and traceroute Commands

Think of the internet as a vast network of roads connecting different locations. The ping command is like sending a small paper airplane to a destination and seeing if it comes back - it tells you if a connection exists and how long the round trip takes. The traceroute command is like tracking a delivery truck's entire journey, showing you each stop (router) along the way from your computer to the destination. These tools help you understand if your network is working and where problems might be happening.

Quick Reference

Command What It Does Common Use
ping hostname Tests if a host is reachable Checking if a website or server is online
ping -c 5 hostname Sends exactly 5 ping packets Testing connection without running indefinitely
traceroute hostname Shows the path to a destination Finding where network problems occur
traceroute -n hostname Shows path with IP addresses only Getting faster results without DNS lookups

When to Use These Commands

The ping Command

Think of ping like sonar on a submarine - it sends out a signal and listens for the echo coming back. The ping command sends small data packets to a specific address and measures how long it takes to get a response (if any). It's named after the sound of sonar because it works on the same principle: send a signal, wait for it to bounce back, and measure the time.

When you ping a website or server, your computer sends an "ICMP Echo Request" packet (think of it as asking "Are you there?"), and if the destination is reachable, it sends back an "ICMP Echo Reply" (essentially saying "Yes, I'm here!"). Your computer measures the time between sending and receiving to calculate how long the round trip took.

Option What It Does When to Use
-c count Limits the number of packets sent When you want ping to stop automatically after a certain number of attempts
-i seconds Sets the interval between packets When you want to space out ping requests (default is 1 second)
-s size Changes the packet size When testing how different packet sizes affect performance
-q Shows only summary results When you only need the final statistics, not each ping result
-w timeout Sets how long to wait before exiting When you need ping to give up after a specific time period

Practical Examples

# Basic ping to check if Google is reachable
ping google.com
# Will ping continuously until you press Ctrl+C

# Send exactly 4 pings and then stop
ping -c 4 google.com
# Useful for quick connection checks

# Send larger packets (default is 56 bytes)
ping -s 1000 google.com
# Tests how network handles larger packets

# Ping with 5-second intervals between packets
ping -i 5 google.com
# Reduces network load while still testing connectivity

# Show only summary results
ping -c 10 -q google.com
# Gets quick statistics without detailed output

Understanding ping Output

Sample Output Explained

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

Let's break down what this means:

  • PING google.com (172.217.16.206) 56(84) bytes of data: Shows the hostname, its IP address, and that you're sending 56 bytes of data (84 bytes including headers)
  • 64 bytes from dfw25s14-in-f14.1e100.net (172.217.16.206): icmp_seq=1 ttl=53 time=11.6 ms:
    • You received 64 bytes back (the response)
    • It came from Google's server (with its domain name and IP)
    • icmp_seq=1: This is the first ping packet
    • ttl=53: Time To Live value, showing how many more network hops the packet could travel
    • time=11.6 ms: The round-trip took 11.6 milliseconds
  • The statistics at the end summarize:
    • 4 packets transmitted, 4 received: All pings were successful
    • 0% packet loss: No packets were lost (good connection)
    • time 3002ms: Total time for all tests
    • rtt min/avg/max/mdev = 10.708/11.005/11.586/0.321 ms: Round-trip times - minimum, average, maximum, and standard deviation

The traceroute Command

Think of traceroute like a GPS tracking system that shows every stop on a journey. When you send data across the internet, it doesn't travel directly from your computer to the destination - it passes through several routers (like relay stations). The traceroute command reveals this path, showing each "hop" and how long each step takes.

It works by sending packets with gradually increasing "Time To Live" (TTL) values. The first packet can only go one hop before expiring, the second can go two hops, and so on. Each router that receives an expired packet sends back a message, allowing traceroute to map the entire path step by step.

Option What It Does When to Use
-m maxhops Sets the maximum number of hops When tracing routes to distant servers or limiting trace length
-n Shows IP addresses only (no DNS lookup) When you want faster results or numeric addresses only
-q queries Sets packets to send per hop When you want more accurate measurements for each hop
-w seconds Sets wait time for responses When dealing with slow networks or wanting to timeout faster
-p port Specifies port number to use When testing connectivity to a specific service

Practical Examples

# Basic traceroute to a website
traceroute google.com
# Shows every hop between you and Google

# Use numeric addresses only (faster)
traceroute -n google.com
# Skips DNS lookups for each router

# Limit trace to 10 hops maximum
traceroute -m 10 github.com
# Stops after 10 routers even if destination isn't reached

# Send 2 packets per hop instead of 3
traceroute -q 2 yahoo.com
# Gets slightly less accurate but faster results

# Set wait time to 2 seconds
traceroute -w 2 microsoft.com
# Gives up more quickly on unresponsive routers

Understanding traceroute Output

Sample Output Explained

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

Let's break down what this means:

  • traceroute to google.com (172.217.16.206), 30 hops max, 60 byte packets: Shows the destination, its IP, maximum number of hops to try, and packet size
  • 1 192.168.1.1 (192.168.1.1) 2.232 ms 2.089 ms 2.055 ms:
    • Hop #1 is your router at 192.168.1.1
    • The three times (2.232 ms, 2.089 ms, 2.055 ms) are from three separate test packets
    • This shows how long it takes to reach your router (very fast!)
  • 2 * * *:
    • The asterisks mean the router at hop #2 didn't respond
    • This is common and doesn't necessarily indicate a problem
    • Some routers are configured not to respond to traceroute packets for security reasons
  • 4 172.217.16.206 (172.217.16.206) 10.714 ms 10.544 ms 10.362 ms:
    • This is the destination (Google's server)
    • It took about 10.5 milliseconds to reach Google from your router

Tips for Success

Common Mistakes to Avoid

Best Practices

Practical Troubleshooting Scenarios

Diagnosing Slow Internet

# First, test ping to your router
ping -c 5 192.168.1.1
# If times are high (>10ms), problem might be on your local network

# Then test ping to a reliable site like Google
ping -c 5 google.com
# Compare these times to your normal baseline

# If ping times are normal but internet feels slow:
ping -c 20 google.com | grep time=
# Check for inconsistent ping times (high variance indicates instability)

# If some sites work but others don't:
traceroute problematic-site.com
# Look for where the path breaks down or slows significantly

Understanding Common Results

# Good Connection:
# - Ping times under 50ms to popular websites
# - 0% packet loss
# - Consistent times between pings
# - Traceroute shows complete path

# Local Network Issues:
# - High ping times to your router (>10ms)
# - Packet loss to local devices
# - First few hops in traceroute show high latency

# ISP Issues:
# - Normal pings to router but high times to internet
# - Packet loss starting at hops 2-5
# - Traceroute shows slowdown at ISP routers

# Remote Server Issues:
# - Ping/traceroute work fine to most sites but not one
# - Last hop shows high latency or no response
# - Only specific websites or services affected