Chapter 35: Bash ping
What does ping actually do? (super simple first)
ping = checks if another computer/device/server is reachable over the network and measures how long it takes for a message to go there and come back.
Think of it like this:
- You shout “Hello!” from your house to your friend’s house across the street.
- If he shouts “Hi!” back → he’s alive/reachable.
- You count how many seconds it took for the sound to go and come back → that’s the round-trip time (latency).
In networking, ping sends small test packets (called ICMP Echo Request) to an IP address or domain name, and waits for ICMP Echo Reply.
If you get replies → the destination is alive and network path is working. If no reply → either destination is down, firewall is blocking, or network problem.
Why do we use ping? (real reasons you will use it daily)
- Check if your internet is working
- See if a website/server is down (YouTube not loading? ping youtube.com)
- Measure latency (delay) – very important for gaming, video calls, trading apps
- Find if problem is in your Wi-Fi, ISP, or far-away server
- Test DNS (if ping 8.8.8.8 works but ping google.com fails → DNS issue)
- Quick network troubleshooting (most first step when something is slow/offline)
1. Basic usage (try right now!)
|
0 1 2 3 4 5 6 |
ping google.com |
Example output you might see:
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
PING google.com (142.250.77.206) 56(84) bytes of data. 64 bytes from 142.250.77.206: icmp_seq=1 ttl=117 time=18.2 ms 64 bytes from 142.250.77.206: icmp_seq=2 ttl=117 time=17.9 ms 64 bytes from 142.250.77.206: icmp_seq=3 ttl=117 time=19.1 ms 64 bytes from 142.250.77.206: icmp_seq=4 ttl=117 time=18.5 ms ^C --- google.com ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3004ms rtt min/avg/max/mdev = 17.900/18.425/19.100/0.474 ms |
Press Ctrl+C to stop (otherwise it runs forever).
2. Understand every line (very important!)
| Line / Part | What it means | Good value example | When to worry |
|---|---|---|---|
| PING google.com (142.250.77.206) | Domain → resolved IP | 142.250.77.206 | If no IP → DNS broken |
| 64 bytes from … icmp_seq=1 | Received packet size + sequence number | icmp_seq=1,2,3… | Missing seq = loss |
| ttl=117 | Time To Live (how many hops left before packet dies) | 50–120 typical | Very low = many hops |
| time=18.2 ms | Round Trip Time (latency) – how long packet took to go & come back | < 50 ms = excellent | >150 ms = laggy |
| — statistics — | Summary after Ctrl+C | – | – |
| 4 packets transmitted, 4 received | How many sent vs received | 100% received | Any loss = problem |
| 0% packet loss | Percentage of packets that never came back | 0–1% = good | >5–10% = unstable |
| rtt min/avg/max/mdev | Round-trip times: min, average, max, standard deviation (jitter) | avg < 50 ms, mdev < 5 | High mdev = unstable connection |
3. Most useful options (you’ll use these 90% of time)
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# Send only 4 packets (very common) ping -c 4 google.com # Don't resolve name to IP (faster, shows only IP) ping -n google.com # Ping an IP directly (bypasses DNS) ping 8.8.8.8 # Google's public DNS – very reliable test # Change packet size (test MTU / fragmentation) ping -s 1472 google.com # 1472 + 28 header = 1500 bytes (common MTU) # Flood mode (very fast – test stability – careful!) ping -f google.com # sends as fast as possible (needs root on some systems) # Audible ping (beep when reply comes) ping -a google.com # Set interval between pings (default 1 sec) ping -i 0.2 google.com # every 0.2 seconds # Show timestamp on each line ping -D google.com # Quiet mode – only summary at end ping -q -c 10 8.8.8.8 |
4. Real-life examples you will use daily (Hyderabad style)
- Internet not working? Start here:
Bash0123456789ping 8.8.8.8 -c 4# If works → internet is up, problem is DNS or appping google.com -c 4# If this fails → DNS issue (change to 8.8.8.8 in settings)
- BGMI / COD laggy? Check latency:
Bash012345678ping delhi.pubgmobile.com -c 10# or find server IP from game logs# avg time > 100–150 ms → lag (common on Jio 4G/5G sometimes)
- Website not opening?
Bash01234567ping www.instagram.com -c 4# If 100% loss → site down or your ISP blocking
- Check your router is alive:
Bash01234567ping 192.168.1.1 -c 4 # most home routers# or ping your default gateway (find with ip route)
- Test Wi-Fi stability (packet loss):
Bash01234567ping -c 100 8.8.8.8 | grep loss# Look for >2–3% loss → bad Wi-Fi signal or interference
5. Quick cheat-sheet table
| Goal | Command example | What to look for |
|---|---|---|
| Basic check (4 packets) | ping -c 4 google.com | 0% loss, avg <50 ms |
| Test internet connection | ping -c 4 8.8.8.8 | Reliable IP test |
| Check DNS resolution | ping google.com vs ping 8.8.8.8 | If IP works but name fails → DNS |
| Measure gaming latency | ping -c 10 server-ip-or-domain | avg <60 ms ideal |
| Check router | ping 192.168.1.1 -c 4 | First troubleshooting step |
| Test for packet loss | ping -c 100 8.8.8.8 | loss % should be 0–1% |
| Fast continuous test | ping -i 0.2 8.8.8.8 | Watch for sudden jumps |
6. Pro tips & common gotchas
- Firewall blocks ping → many servers (especially cloud) block ICMP → 100% loss doesn’t always mean down (try curl google.com instead)
- High latency on mobile data → normal (Jio/Airtel 4G/5G often 30–100 ms)
- Packet loss >5% → bad Wi-Fi, faulty cable, ISP issue, or overloaded network
- mdev high (jitter) → unstable connection (video call will stutter)
- Alternative modern tool: mtr (combines ping + traceroute)
Bash01234567sudo apt install mtrmtr google.com
Now open your terminal and try these 3 right now:
|
0 1 2 3 4 5 6 7 8 |
ping -c 4 8.8.8.8 ping -c 4 google.com ping -c 10 www.youtube.com |
Tell me:
- What’s your average time to 8.8.8.8? (e.g. 22 ms)
- Any packet loss?
Or ask:
- “Why does ping youtube.com work but website not opening?”
- “How to ping from phone?”
- “What is good ping for BGMI / Free Fire?”
We’ll troubleshoot together! 😄
