Ping Traceroute Network Testing - ryzendew/Linux-Tips-and-Tricks GitHub Wiki

Ping & Traceroute Network Testing for Beginners

Table of Contents

  1. :pencil: What are ping and traceroute?
  2. :zap: PING Commands
  3. :mag: TRACEROUTE Commands
  4. :bulb: Common Troubleshooting Scenarios
  1. :keyboard: Quick Reference
  1. :warning: Important Notes
  2. Summary

:pencil: What are ping and traceroute?

  • ping tests network connectivity by sending ICMP packets
  • traceroute shows the network path packets take to reach a destination
  • Essential tools for network troubleshooting
  • Both are usually pre-installed on Linux systems

What ping can do:

  • Test if a host is reachable
  • Measure network latency (response time)
  • Check packet loss
  • Verify network connectivity
  • Test DNS resolution

What traceroute can do:

  • Show the route packets take
  • Identify network hops
  • Find where network problems occur
  • Measure latency at each hop

:zap: PING Commands

Basic Ping

ping destination

What this does:

  • Sends ICMP packets to destination
  • Shows response times
  • Runs continuously until stopped (Ctrl+C)

Examples:

ping google.com
ping 8.8.8.8
ping 192.168.1.1

Example output:

PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=113 time=16.5 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=113 time=15.2 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=113 time=14.8 ms

--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 14.8/15.5/16.5/0.7 ms

What the output means:

  • icmp_seq: Sequence number of packet
  • ttl: Time to live (hops remaining)
  • time: Response time in milliseconds
  • packet loss: Percentage of lost packets
  • rtt: Round-trip time (min/avg/max)

Ping Specific Number of Packets

ping -c 4 destination

What this does:

  • Sends only 4 packets then stops
  • -c = count
  • Useful for quick tests

Example:

ping -c 4 google.com

Ping with Timestamp

ping -D destination

What this does:

  • Shows timestamp with each packet
  • -D = print timestamp
  • Useful for logging and analysis

Ping Localhost (Test Local Network Stack)

ping -c 4 127.0.0.1

What this does:

  • Tests local network stack
  • If this fails, network stack has problems
  • Should always work on a functioning system

Example output:

PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.034 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.029 ms

--- 127.0.0.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1035ms
rtt min/avg/max/mdev = 0.029/0.031/0.034/0.002 ms

Ping with Interval

ping -i 2 destination

What this does:

  • Sends packets every 2 seconds
  • -i = interval (in seconds)
  • Default is 1 second

Note: Requires root for intervals less than 0.2 seconds.


Ping with Timeout

ping -W 5 destination

What this does:

  • Waits 5 seconds for each reply
  • -W = timeout (in seconds)
  • Useful for slow networks

:mag: TRACEROUTE Commands

Basic Traceroute

traceroute destination

What this does:

  • Shows the network path to destination
  • Displays each hop (router) along the way
  • Shows latency at each hop

Example:

traceroute google.com

Example output:

traceroute to google.com (142.250.191.14), 30 hops max, 60 byte packets
 1  router.local (192.168.1.1)  1.234 ms  1.456 ms  1.678 ms
 2  10.0.0.1 (10.0.0.1)  5.123 ms  5.234 ms  5.345 ms
 3  isp-gateway.com (203.0.113.1)  10.234 ms  10.345 ms  10.456 ms
 ...

What each line means:

  • Hop number: Number of router from source
  • Router name/IP: Name or IP of router
  • Three times: Three measurements (min/avg/max)

Limit Maximum Hops

traceroute -m 10 destination

What this does:

  • Limits maximum hops to 10
  • -m = max hops
  • Default is 30
  • Useful for local network testing

Example:

traceroute -m 3 127.0.0.1

Traceroute with ICMP

traceroute -I destination

What this does:

  • Uses ICMP instead of UDP
  • -I = ICMP
  • May work better through some firewalls

Traceroute with TCP

traceroute -T destination

What this does:

  • Uses TCP SYN packets
  • -T = TCP
  • Useful for testing TCP connectivity
  • Default port is 80

:bulb: Common Troubleshooting Scenarios

Scenario 1: Test Internet Connectivity

Problem: Can't connect to internet.

Solution:

  1. Test localhost first:

    ping -c 4 127.0.0.1
    
  2. Test router/gateway:

    ping -c 4 192.168.1.1
    

(Replace with your gateway IP)

  1. Test DNS:

    ping -c 4 8.8.8.8
    
  2. Test domain name:

    ping -c 4 google.com
    

If localhost works but others don't:

  • Network interface problem
  • Router/gateway issue
  • Internet connection problem

Scenario 2: Check Network Latency

Problem: Network seems slow.

Solution:

ping -c 10 destination

Shows average latency over 10 packets.

Interpretation:

  • < 50ms: Excellent (local network)
  • 50-100ms: Good (same country)
  • 100-200ms: Acceptable (different country)
  • > 200ms: Slow (distant or congested)

Scenario 3: Find Network Bottleneck

Problem: Slow connection, need to find where it's slow.

Solution:

traceroute destination

Look for hops with high latency - that's likely the bottleneck.


Scenario 4: Test DNS Resolution

Problem: Can't reach websites by name.

Solution:

  1. Test with IP (bypasses DNS):

    ping -c 4 8.8.8.8
    
  2. Test with domain name:

    ping -c 4 google.com
    

If IP works but domain doesn't:

  • DNS problem
  • Check /etc/resolv.conf
  • Try different DNS server

Scenario 5: Check Packet Loss

Problem: Connection is unreliable.

Solution:

ping -c 100 destination

Send 100 packets and check packet loss percentage.

Interpretation:

  • 0%: Perfect
  • < 1%: Good
  • 1-5%: Acceptable
  • > 5%: Problem (network issue)

Scenario 6: Test Specific Port

Problem: Need to test if a port is reachable.

Solution: Use nc (netcat) or telnet instead of ping:

nc -zv destination port

Or use traceroute with TCP:

traceroute -T -p 80 destination

:keyboard: Quick Reference

Ping Commands

ping destination                # Continuous ping
ping -c 4 destination          # 4 packets
ping -D destination             # With timestamp
ping -i 2 destination           # 2 second interval
ping -W 5 destination           # 5 second timeout
ping -c 4 127.0.0.1            # Test localhost

Traceroute Commands

traceroute destination          # Basic traceroute
traceroute -m 10 destination    # Max 10 hops
traceroute -I destination       # Use ICMP
traceroute -T destination       # Use TCP

Common Destinations

ping -c 4 127.0.0.1            # Localhost
ping -c 4 8.8.8.8              # Google DNS
ping -c 4 1.1.1.1              # Cloudflare DNS
ping -c 4 google.com            # Test DNS

:warning: Important Notes

  1. Ping requires network access - some networks block ICMP
  2. Traceroute may be slow - can take time to complete
  3. Some hosts block ping - don't assume host is down if ping fails
  4. Use Ctrl+C to stop ping/traceroute
  5. Root may be required for some ping options (short intervals)
  6. Firewalls may block ICMP packets

Summary

This guide covered:

  1. Ping:
  • Basic connectivity testing
  • Limiting packet count
  • Timestamps and intervals
  • Localhost testing
  1. Traceroute:
  • Network path discovery
  • Limiting hops
  • ICMP and TCP modes
  1. Troubleshooting Scenarios:
  • Internet connectivity
  • Network latency
  • Finding bottlenecks
  • DNS testing
  • Packet loss

Next Steps:

  • Practice with localhost and common destinations
  • Learn to interpret ping statistics
  • Use traceroute to understand network paths
  • Combine with other network tools (ss, ip, etc.)

For network interface management, see the IP Network Interface Guide. For network connections, see the SS Network Troubleshooting Guide.