
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
- When your internet connection seems slow or unreliable
- When a website or service isn't responding
- When troubleshooting network connection problems
- When trying to determine if an issue is with your network or a remote server
- When measuring network performance or latency
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 packetttl=53
: Time To Live value, showing how many more network hops the packet could traveltime=11.6 ms
: The round-trip took 11.6 milliseconds
- The statistics at the end summarize:
4 packets transmitted, 4 received
: All pings were successful0% packet loss
: No packets were lost (good connection)time 3002ms
: Total time for all testsrtt 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 size1 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
- Always use
ping -c
with a number when pinging, so it stops automatically - Look at packet loss percentage in ping results - anything above 1-2% indicates a problem
- Use
traceroute -n
for faster results when you don't need to see router names - Don't worry about occasional asterisks in traceroute - some routers are configured not to respond
- Save the output of these commands when troubleshooting to compare results over time
- Compare ping times to different destinations to identify if a problem is with one specific site
Common Mistakes to Avoid
- Running ping without the
-c
option and forgetting it runs forever until stopped - Assuming a website is down just because ping fails (some sites block ping requests)
- Misinterpreting high ping times during peak internet usage hours
- Forgetting that traceroute uses UDP on some systems and ICMP on others, which can affect results
- Assuming a problem is always at the last hop - issues can occur anywhere along the path
- Running these commands too frequently on corporate networks (may trigger security alerts)
Best Practices
- Test multiple destinations when diagnosing network issues to isolate the problem
- Use ping first to check basic connectivity before running more detailed traceroute
- Keep a record of normal ping times to your common destinations for comparison
- When reporting network issues, include both ping and traceroute results
- Try both domain names and IP addresses - DNS issues can be confused with connectivity problems
- Run tests at different times of day to identify patterns in performance problems
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