Linux CLI 30 🐧 ping and trace route commands
ping google.com
ping -4 google.com
ping -s 500 -i 1 google.com
traceroute google.com
traceroute -m 3 google.com
traceroute -n google.com
ping and traceroute are two of the most fundamental network diagnostic tools. ping tells you whether a host is reachable and how fast the round trip is. traceroute tells you which path packets take to get there, hop by hop.
Key point: Both tools use ICMP (Internet Control Message Protocol) by default. Some networks block ICMP, so a failed ping doesn’t always mean a host is down.
a – ping command
ping is a network utility that tests whether a device is connected on a network. It sends small packets to a target host and waits for a reply, measuring the round-trip time (RTT).
| Command | Description |
|---|---|
ping google.com | Pings google.com. Press Ctrl + C to stop |
ping 0 | Ping localhost (shortcut) |
ping 127.0.0.1 | Ping localhost by IP |
ping localhost | Ping localhost by name |
ping -4 google.com | Force IPv4 (default) |
ping -6 google.com | Force IPv6 |
ping -s 500 -i 1 google.com | -s sets packet size, -i sets interval |
ping -f google.com | Flood the network (fast ping) |
ping -c 2 google.com | Send only 2 packets |
ping -w 10 google.com | Set a 10-second time limit |
Examples:
# Basic ping — runs forever until Ctrl+C
$ ping google.com
PING google.com (142.250.185.78) 56(84) bytes of data.
64 bytes from 142.250.185.78: icmp_seq=1 ttl=115 time=12.3 ms
64 bytes from 142.250.185.78: icmp_seq=2 ttl=115 time=11.8 ms
64 bytes from 142.250.185.78: icmp_seq=3 ttl=115 time=12.1 ms
^C
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 11.802/12.067/12.301/0.204 ms
# Check the local network stack
$ ping 127.0.0.1
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.045 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.038 ms
^C
--- 127.0.0.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 0.038/0.041/0.045/0.003 ms
# Same thing using the "0" shortcut
$ ping 0
# Force IPv4
$ ping -4 google.com
PING google.com (142.250.185.78) 56(84) bytes of data.
...
# Force IPv6
$ ping -6 google.com
PING google.com (2607:f8b0:4004:c07::65) 56 data bytes
64 bytes from 2607:f8b0:4004:c07::65: icmp_seq=1 ttl=115 time=12.5 ms
...
# Set packet size to 500 bytes and interval to 1 second
$ ping -s 500 -i 1 google.com
PING google.com (142.250.185.78) 500(528) bytes of data.
508 bytes from 142.250.185.78: icmp_seq=1 ttl=115 time=12.4 ms
508 bytes from 142.250.185.78: icmp_seq=2 ttl=115 time=12.0 ms
...
# Send only 2 packets
$ ping -c 2 google.com
PING google.com (142.250.185.78) 56(84) bytes of data.
64 bytes from 142.250.185.78: icmp_seq=1 ttl=115 time=12.1 ms
64 bytes from 142.250.185.78: icmp_seq=2 ttl=115 time=11.9 ms
--- google.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
# Stop after 10 seconds
$ ping -w 10 google.com
...
# Flood ping (requires root, very fast)
$ sudo ping -f google.com
Reading the output:
| Field | Meaning |
|---|---|
icmp_seq | Packet sequence number |
ttl | Time To Live — how many hops left |
time | Round-trip time in milliseconds |
packet loss | Percentage of packets lost |
rtt min/avg/max/mdev | Min, average, max, and deviation of RTT |
Common uses:
- Check if a host is up —
ping google.com - Check latency to a server —
ping 8.8.8.8 - Check packet loss on a bad connection —
ping -c 100 google.com - Test the local network stack —
ping 127.0.0.1 - Test DNS resolution —
ping google.com(if IP works but name doesn’t, it’s DNS)
b – traceroute command
traceroute shows how packets travel from your computer to another computer through the network. It reveals every hop (router) along the way, which is extremely useful for diagnosing connection issues and routing problems.
| Command | Description |
|---|---|
traceroute google.com | Trace the route to google.com |
traceroute -4 google.com | Use IPv4 |
traceroute -6 google.com | Use IPv6 |
traceroute -m 3 google.com | Use a maximum of 3 hops |
traceroute -n google.com | Disable IP address resolution (no DNS) |
traceroute -p 2324 google.com | Use port 2324 |
traceroute -q 2 google.com | Send 2 probes per hop (default 3) |
traceroute 50 google.com | Set packet length to 50 bytes |
Examples:
# Basic traceroute
$ traceroute google.com
traceroute to google.com (142.250.185.78), 30 hops max, 60 byte packets
1 _gateway (192.168.1.1) 1.234 ms 1.456 ms 1.678 ms
2 10.0.0.1 (10.0.0.1) 8.901 ms 9.123 ms 9.345 ms
3 isp-router.example.net (203.0.113.1) 10.567 ms 10.789 ms 11.012 ms
4 * * *
5 core1.example.net (198.51.100.1) 15.234 ms 15.456 ms 15.678 ms
6 142.250.185.78 (142.250.185.78) 16.901 ms 17.123 ms 17.345 ms
# Force IPv4
$ traceroute -4 google.com
...
# Force IPv6
$ traceroute -6 google.com
...
# Limit to 3 hops
$ traceroute -m 3 google.com
traceroute to google.com (142.250.185.78), 3 hops max, 60 byte packets
1 _gateway (192.168.1.1) 1.234 ms 1.456 ms 1.678 ms
2 10.0.0.1 (10.0.0.1) 8.901 ms 9.123 ms 9.345 ms
3 isp-router.example.net (203.0.113.1) 10.567 ms 10.789 ms 11.012 ms
# Disable DNS resolution — faster
$ traceroute -n google.com
traceroute to google.com (142.250.185.78), 30 hops max, 60 byte packets
1 192.168.1.1 1.234 ms 1.456 ms 1.678 ms
2 10.0.0.1 8.901 ms 9.123 ms 9.345 ms
3 203.0.113.1 10.567 ms 10.789 ms 11.012 ms
...
# Use a specific port
$ traceroute -p 2324 google.com
...
# Send 2 probes per hop instead of 3
$ traceroute -q 2 google.com
traceroute to google.com (142.250.185.78), 30 hops max, 60 byte packets
1 _gateway (192.168.1.1) 1.234 ms 1.456 ms
2 10.0.0.1 (10.0.0.1) 8.901 ms 9.123 ms
...
# Set packet length to 50 bytes
$ traceroute 50 google.com
...
Reading the output:
| Field | Meaning |
|---|---|
| Hop number | Which router along the path |
| Hostname / IP | The router’s name and address |
* * * | No response — the router blocked ICMP or timed out |
| Three times | RTT for each of the 3 probes |
30 hops max | Maximum hops before giving up |
How it works: traceroute sends packets with increasing TTL (Time To Live) values. Each router that receives a packet decrements the TTL; when it hits zero, the router sends back an ICMP “time exceeded” message. By starting at TTL=1 and increasing, traceroute maps every hop.
Common uses:
- Find where a connection is slow or failing —
traceroute google.com - Identify the ISP’s routers on the path
- Detect routing loops or unusual paths
- Check if a firewall is blocking traffic (
* * *at a certain hop) - Compare routes from different networks
Complete Example Session
# ============================================
# PART 1: BASIC PING
# ============================================
$ ping google.com
PING google.com (142.250.185.78) 56(84) bytes of data.
64 bytes from 142.250.185.78: icmp_seq=1 ttl=115 time=12.3 ms
64 bytes from 142.250.185.78: icmp_seq=2 ttl=115 time=11.8 ms
64 bytes from 142.250.185.78: icmp_seq=3 ttl=115 time=12.1 ms
^C
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 11.802/12.067/12.301/0.204 ms
# ============================================
# PART 2: PING LOCALHOST
# ============================================
$ ping 127.0.0.1
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.045 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.038 ms
^C
--- 127.0.0.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 0.038/0.041/0.045/0.003 ms
# ============================================
# PART 3: PING WITH OPTIONS
# ============================================
$ ping -4 google.com
PING google.com (142.250.185.78) 56(84) bytes of data.
64 bytes from 142.250.185.78: icmp_seq=1 ttl=115 time=12.4 ms
...
$ ping -6 google.com
PING google.com (2607:f8b0:4004:c07::65) 56 data bytes
64 bytes from 2607:f8b0:4004:c07::65: icmp_seq=1 ttl=115 time=12.5 ms
...
$ ping -s 500 -i 1 google.com
PING google.com (142.250.185.78) 500(528) bytes of data.
508 bytes from 142.250.185.78: icmp_seq=1 ttl=115 time=12.4 ms
508 bytes from 142.250.185.78: icmp_seq=2 ttl=115 time=12.0 ms
^C
$ ping -c 2 google.com
PING google.com (142.250.185.78) 56(84) bytes of data.
64 bytes from 142.250.185.78: icmp_seq=1 ttl=115 time=12.1 ms
64 bytes from 142.250.185.78: icmp_seq=2 ttl=115 time=11.9 ms
--- google.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
# ============================================
# PART 4: BASIC TRACEROUTE
# ============================================
$ traceroute google.com
traceroute to google.com (142.250.185.78), 30 hops max, 60 byte packets
1 _gateway (192.168.1.1) 1.234 ms 1.456 ms 1.678 ms
2 10.0.0.1 (10.0.0.1) 8.901 ms 9.123 ms 9.345 ms
3 isp-router.example.net (203.0.113.1) 10.567 ms 10.789 ms 11.012 ms
4 * * *
5 core1.example.net (198.51.100.1) 15.234 ms 15.456 ms 15.678 ms
6 142.250.185.78 (142.250.185.78) 16.901 ms 17.123 ms 17.345 ms
# ============================================
# PART 5: TRACEROUTE WITH OPTIONS
# ============================================
$ traceroute -4 google.com
...
$ traceroute -6 google.com
...
$ traceroute -m 3 google.com
traceroute to google.com (142.250.185.78), 3 hops max, 60 byte packets
1 _gateway (192.168.1.1) 1.234 ms 1.456 ms 1.678 ms
2 10.0.0.1 (10.0.0.1) 8.901 ms 9.123 ms 9.345 ms
3 isp-router.example.net (203.0.113.1) 10.567 ms 10.789 ms 11.012 ms
$ traceroute -n google.com
traceroute to google.com (142.250.185.78), 30 hops max, 60 byte packets
1 192.168.1.1 1.234 ms 1.456 ms 1.678 ms
2 10.0.0.1 8.901 ms 9.123 ms 9.345 ms
3 203.0.113.1 10.567 ms 10.789 ms 11.012 ms
...
$ traceroute -q 2 google.com
traceroute to google.com (142.250.185.78), 30 hops max, 60 byte packets
1 _gateway (192.168.1.1) 1.234 ms 1.456 ms
2 10.0.0.1 (10.0.0.1) 8.901 ms 9.123 ms
...
$ traceroute -p 2324 google.com
...
$ traceroute 50 google.com
...
# ============================================
# PART 6: DIAGNOSE A PROBLEM
# ============================================
# Ping fails but localhost works — network issue
$ ping 127.0.0.1
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.045 ms
$ ping google.com
PING google.com (142.250.185.78) 56(84) bytes of data.
^C
--- google.com ping statistics ---
3 packets transmitted, 0 received, 100% packet loss
# Trace to find where it breaks
$ traceroute google.com
traceroute to google.com (142.250.185.78), 30 hops max, 60 byte packets
1 _gateway (192.168.1.1) 1.234 ms 1.456 ms 1.678 ms
2 10.0.0.1 (10.0.0.1) 8.901 ms 9.123 ms 9.345 ms
3 * * *
4 * * *
5 * * *
# → problem starts at hop 3 (ISP side)
Quick Reference
ping
| Command | Purpose |
|---|---|
ping HOST | Ping a host continuously |
ping -c N HOST | Send N packets and stop |
ping -i N HOST | Set interval between packets |
ping -s N HOST | Set packet size to N bytes |
ping -w N HOST | Stop after N seconds |
ping -4 HOST | Force IPv4 |
ping -6 HOST | Force IPv6 |
ping -f HOST | Flood ping (root only) |
ping 0 | Ping localhost |
ping 127.0.0.1 | Ping localhost by IP |
traceroute
| Command | Purpose |
|---|---|
traceroute HOST | Trace route to host |
traceroute -4 HOST | Force IPv4 |
traceroute -6 HOST | Force IPv6 |
traceroute -m N HOST | Max N hops |
traceroute -n HOST | No DNS resolution |
traceroute -p N HOST | Use port N |
traceroute -q N HOST | N probes per hop |
traceroute N HOST | Packet length N bytes |
Best Practices
✅ Do This:
# Use -c to limit packets
ping -c 5 google.com # ✅
# Use -n with traceroute for speed
traceroute -n google.com # ✅
# Test localhost first when diagnosing
ping 127.0.0.1 # ✅
# Use -4 or -6 explicitly when needed
ping -6 google.com # ✅
# Limit hops with traceroute -m for quick checks
traceroute -m 5 google.com # ✅
# Use traceroute when ping succeeds but is slow
ping -c 10 google.com && traceroute google.com # ✅
❌ Don’t Do This:
# Don't flood a network without permission
sudo ping -f google.com # ❌ abuse
# Don't assume ping failure = host down
ping example.com # ❌ ICMP might be blocked
# Don't run traceroute without -n on slow DNS
traceroute google.com # ❌ slow (waits for DNS)
# Don't use ping as a port scanner
ping -p 80 google.com # ❌ wrong tool
# Don't ignore packet loss in the summary
ping -c 100 google.com # ❌ check loss %
Common Pitfalls
| Pitfall | Problem | Solution |
|---|---|---|
| Ping never stops | Forgot Ctrl+C | Use -c N |
| 100% packet loss | ICMP blocked | Try traceroute or TCP |
* * * in traceroute | Router blocks ICMP | Normal — not always a problem |
| Slow traceroute | DNS lookups | Use -n |
| IPv6 fails | No IPv6 route | Use -4 |
| Flood ping | Network abuse | Only with permission |
| Can’t traceroute | No root / no ICMP | Try sudo or tcptraceroute |
Real-World Examples
1. Check if a Host is Up
$ ping -c 3 8.8.8.8
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=117 time=9.12 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=117 time=9.34 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=117 time=9.21 ms
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss
2. Test Local Network Stack
$ ping -c 2 127.0.0.1
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.045 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.038 ms
# ✅ Local stack is fine
3. Check DNS Resolution
$ ping -c 1 google.com
PING google.com (142.250.185.78) 56(84) bytes of data.
64 bytes from 142.250.185.78: icmp_seq=1 ttl=115 time=12.3 ms
# ✅ DNS works
$ ping -c 1 nonexistent.example
ping: nonexistent.example: Name or service not known
# ❌ DNS failure
4. Measure Latency to a Server
$ ping -c 20 1.1.1.1
...
--- 1.1.1.1 ping statistics ---
20 packets transmitted, 20 received, 0% packet loss, time 19023ms
rtt min/avg/max/mdev = 8.123/9.456/12.789/1.234 ms
5. Trace the Path to a Website
$ traceroute -n google.com
traceroute to google.com (142.250.185.78), 30 hops max, 60 byte packets
1 192.168.1.1 1.234 ms 1.456 ms 1.678 ms
2 10.0.0.1 8.901 ms 9.123 ms 9.345 ms
3 203.0.113.1 10.567 ms 10.789 ms 11.012 ms
4 198.51.100.1 15.234 ms 15.456 ms 15.678 ms
5 142.250.185.78 16.901 ms 17.123 ms 17.345 ms
6. Find Where a Connection Breaks
$ ping -c 5 example.com
...
--- example.com ping statistics ---
5 packets transmitted, 0 received, 100% packet loss
$ traceroute -n example.com
1 192.168.1.1 1.234 ms 1.456 ms 1.678 ms
2 10.0.0.1 8.901 ms 9.123 ms 9.345 ms
3 * * *
4 * * *
# → ISP side is dropping packets
7. Test IPv6 Connectivity
$ ping -6 -c 3 google.com
PING google.com (2607:f8b0:4004:c07::65) 56 data bytes
64 bytes from 2607:f8b0:4004:c07::65: icmp_seq=1 ttl=115 time=12.5 ms
...
# ✅ IPv6 works
8. Flood Ping (Stress Test — root only)
$ sudo ping -f -c 1000 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
....................................................
--- 192.168.1.1 ping statistics ---
1000 packets transmitted, 1000 received, 0% packet loss
Visual: How traceroute Works
┌──────────────────────────────────────────────┐
│ Your Computer │
│ │
│ TTL=1 ───────► Router 1 │
│ │ │
│ └── TTL=0 ──► ICMP reply │
│ │
│ TTL=2 ───────► Router 1 ──► Router 2 │
│ │ │
│ └── TTL=0 ──► ICMP reply
│ │
│ TTL=3 ───────► Router 1 ──► Router 2 ──► Target
│ │
└──────────────────────────────────────────────┘
Result:
1 Router 1 1.23 ms
2 Router 2 8.90 ms
3 Target 16.9 ms
Summary
| Command | Purpose | Example |
|---|---|---|
ping HOST | Test reachability | ping google.com |
ping -c N HOST | Send N packets | ping -c 3 google.com |
ping -i N HOST | Set interval | ping -i 1 google.com |
ping -s N HOST | Set packet size | ping -s 500 google.com |
ping -w N HOST | Time limit | ping -w 10 google.com |
ping -4 HOST | Force IPv4 | ping -4 google.com |
ping -6 HOST | Force IPv6 | ping -6 google.com |
ping 0 | Localhost shortcut | ping 0 |
traceroute HOST | Trace route | traceroute google.com |
traceroute -m N HOST | Max N hops | traceroute -m 3 google.com |
traceroute -n HOST | No DNS | traceroute -n google.com |
traceroute -q N HOST | N probes/hop | traceroute -q 2 google.com |
traceroute -p N HOST | Port N | traceroute -p 2324 google.com |
Key takeaways:
pingtests whether a host is reachable and measures latency and packet loss- Use
-c Nto limit packets,-i Nfor interval,-s Nfor size,-w Nfor a time limit - Use
-4or-6to force IPv4 or IPv6 ping 0,ping 127.0.0.1, andping localhostall test the local stacktracerouteshows the path packets take — hop by hop- Use
-nto skip DNS (faster),-m Nto limit hops,-q Nfor probes per hop * * *in traceroute means a router didn’t reply — not always an error- ICMP can be blocked — a failed ping doesn’t always mean a host is down
- Use ping first, then traceroute to localize where a problem begins
Remember: ping tells you if a host responds; traceroute tells you how your packets get there. Start with a localhost ping to confirm your stack, then ping the gateway, then an external IP, then a hostname — this narrows down where the problem is. Use -c to avoid infinite pings, -n to speed up traceroute, and always check the summary line for packet loss. Master these two tools, and you can diagnose most network problems from the command line.
Stop using slow, ad-bloated tool sites! 🤮
🔎 Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
✅ Finance (Mortgage, Interest, Inflation)
✅ Tech (Base64, JSON, Dev Suite, IP)
✅ Health (BMI, BMR, TDEE)
✅ Productivity (Timer, Workspace, QR)
⚡️ Fast & Private
🔒 No data leaves your device
💎 100% Free
🔗 Use it now: https://tools.kandz.me
🔖 Bookmark it—you’ll need it later!