|

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).

CommandDescription
ping google.comPings google.com. Press Ctrl + C to stop
ping 0Ping localhost (shortcut)
ping 127.0.0.1Ping localhost by IP
ping localhostPing localhost by name
ping -4 google.comForce IPv4 (default)
ping -6 google.comForce IPv6
ping -s 500 -i 1 google.com-s sets packet size, -i sets interval
ping -f google.comFlood the network (fast ping)
ping -c 2 google.comSend only 2 packets
ping -w 10 google.comSet 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:

FieldMeaning
icmp_seqPacket sequence number
ttlTime To Live — how many hops left
timeRound-trip time in milliseconds
packet lossPercentage of packets lost
rtt min/avg/max/mdevMin, average, max, and deviation of RTT

Common uses:

  • Check if a host is upping 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 stackping 127.0.0.1
  • Test DNS resolutionping 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.

CommandDescription
traceroute google.comTrace the route to google.com
traceroute -4 google.comUse IPv4
traceroute -6 google.comUse IPv6
traceroute -m 3 google.comUse a maximum of 3 hops
traceroute -n google.comDisable IP address resolution (no DNS)
traceroute -p 2324 google.comUse port 2324
traceroute -q 2 google.comSend 2 probes per hop (default 3)
traceroute 50 google.comSet 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:

FieldMeaning
Hop numberWhich router along the path
Hostname / IPThe router’s name and address
* * *No response — the router blocked ICMP or timed out
Three timesRTT for each of the 3 probes
30 hops maxMaximum 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

CommandPurpose
ping HOSTPing a host continuously
ping -c N HOSTSend N packets and stop
ping -i N HOSTSet interval between packets
ping -s N HOSTSet packet size to N bytes
ping -w N HOSTStop after N seconds
ping -4 HOSTForce IPv4
ping -6 HOSTForce IPv6
ping -f HOSTFlood ping (root only)
ping 0Ping localhost
ping 127.0.0.1Ping localhost by IP

traceroute

CommandPurpose
traceroute HOSTTrace route to host
traceroute -4 HOSTForce IPv4
traceroute -6 HOSTForce IPv6
traceroute -m N HOSTMax N hops
traceroute -n HOSTNo DNS resolution
traceroute -p N HOSTUse port N
traceroute -q N HOSTN probes per hop
traceroute N HOSTPacket 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

PitfallProblemSolution
Ping never stopsForgot Ctrl+CUse -c N
100% packet lossICMP blockedTry traceroute or TCP
* * * in tracerouteRouter blocks ICMPNormal — not always a problem
Slow tracerouteDNS lookupsUse -n
IPv6 failsNo IPv6 routeUse -4
Flood pingNetwork abuseOnly with permission
Can’t tracerouteNo root / no ICMPTry 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

CommandPurposeExample
ping HOSTTest reachabilityping google.com
ping -c N HOSTSend N packetsping -c 3 google.com
ping -i N HOSTSet intervalping -i 1 google.com
ping -s N HOSTSet packet sizeping -s 500 google.com
ping -w N HOSTTime limitping -w 10 google.com
ping -4 HOSTForce IPv4ping -4 google.com
ping -6 HOSTForce IPv6ping -6 google.com
ping 0Localhost shortcutping 0
traceroute HOSTTrace routetraceroute google.com
traceroute -m N HOSTMax N hopstraceroute -m 3 google.com
traceroute -n HOSTNo DNStraceroute -n google.com
traceroute -q N HOSTN probes/hoptraceroute -q 2 google.com
traceroute -p N HOSTPort Ntraceroute -p 2324 google.com

Key takeaways:

  • ping tests whether a host is reachable and measures latency and packet loss
  • Use -c N to limit packets, -i N for interval, -s N for size, -w N for a time limit
  • Use -4 or -6 to force IPv4 or IPv6
  • ping 0, ping 127.0.0.1, and ping localhost all test the local stack
  • traceroute shows the path packets take — hop by hop
  • Use -n to skip DNS (faster), -m N to limit hops, -q N for 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!