Ping Traceroute Network Testing - ryzendew/Linux-Tips-and-Tricks GitHub Wiki
Ping & Traceroute Network Testing for Beginners
Table of Contents
- :pencil: What are ping and traceroute?
- :zap: PING Commands
- :mag: TRACEROUTE Commands
- :bulb: Common Troubleshooting Scenarios
- Scenario 1: Test Internet Connectivity
- Scenario 2: Check Network Latency
- Scenario 3: Find Network Bottleneck
- Scenario 4: Test DNS Resolution
- Scenario 5: Check Packet Loss
- Scenario 6: Test Specific Port
:pencil: What are ping and traceroute?
pingtests network connectivity by sending ICMP packetstracerouteshows 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:
-
Test localhost first:
ping -c 4 127.0.0.1 -
Test router/gateway:
ping -c 4 192.168.1.1
(Replace with your gateway IP)
-
Test DNS:
ping -c 4 8.8.8.8 -
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:
-
Test with IP (bypasses DNS):
ping -c 4 8.8.8.8 -
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
- Ping requires network access - some networks block ICMP
- Traceroute may be slow - can take time to complete
- Some hosts block ping - don't assume host is down if ping fails
- Use Ctrl+C to stop ping/traceroute
- Root may be required for some ping options (short intervals)
- Firewalls may block ICMP packets
Summary
This guide covered:
- Ping:
- Basic connectivity testing
- Limiting packet count
- Timestamps and intervals
- Localhost testing
- Traceroute:
- Network path discovery
- Limiting hops
- ICMP and TCP modes
- 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.