The ping
command is a powerful tool used in Linux to check network connectivity and diagnose issues. In this guide, we’ll explain how ping works and when to use it.
Learn the real technical power of the ping
command with ICMP packet analysis, TTL insights, and real-world use cases for DevOps engineers.
What is ping
?
The ping
command is a powerful network diagnostic tool that tests reachability, latency, and packet loss between your machine and a remote host. It sends ICMP Echo Request packets and waits for ICMP Echo Replies.
Used by network admins, DevOps engineers, and cybersecurity professionals, ping
helps quickly identify whether a host is up, how long it takes to respond, and if packets are being filtered or dropped
What Happens Internally When You Use ping
When you run:
ping google.com

1. DNS Resolution
Before sending packets, your machine resolves google.com
to an IP using DNS.

dig google.com
2. ICMP Echo Request Packet is Creation
- Uses ICMP (Internet Control Message Protocol)
- Operates at Layer 3 (Network Layer)
- Uses raw sockets (
SOCK_RAW
withIPPROTO_ICMP
) - The kernel prepares an IP header + ICMP header + payload.

sudo tcpdump -i eth0 icmp
3. Packet Sent Through Network Stack
- Ethernet frame is created.
- Packet travels from your NIC → router → internet.
Deep Analysis of Ping Output

Explanation:
icmp_seq
: Sequence number of packetsttl
: Time to Live – how many hops lefttime
: Round-trip time
Understanding TTL and Hops
Each router reduces the TTL by 1. If it hits 0, the packet will dropped.

traceroute google.com
Useful for identifying bottlenecks in a route.
What Can Break the Ping Command?
If ping fails, it’s usually due to one of these reasons:
Reason | Symptom | Fix |
---|---|---|
DNS failure | ping: unknown host | Use dig , fix /etc/resolv.conf |
ICMP blocked | Request timeout | Check firewall on both ends |
Routing issue | No replies | Use traceroute , ip route |
Advanced Ping Use Cases
1. Limit Number of Pings
ping -c 5 example.com
2. Custom Time Interval
ping -i 2 google.com
3. Check Internal Network
ping 192.168.1.1
4. Large Packet Test
ping -s 1024 google.com
Real-World Use Cases
- Check if server is alive
- Measure network latency
- Detect ICMP filtering by firewalls
- Test DNS resolution and routing issues
Pro Tips
- Use
ping 8.8.8.8
to test direct IP-level connectivity. - Use
ping -t 1
to manually set TTL (test router hop limits). - Use
ping -f
to flood-ping a host (admin use only).
Ping vs Traceroute vs Curl
Tool | Protocol | Purpose |
---|---|---|
ping | ICMP | Check if host is reachable |
traceroute | ICMP/UDP | Path of packet |
curl | TCP/HTTP | Application-level availability |
Conclusion
The ping
command isn’t just a beginner’s utility – it’s a powerful network-level diagnostic tool rooted in ICMP, IP routing, and system-level socket programming. Mastering it will instantly level up your ability to troubleshoot and diagnose network problems like a pro.
Leave a Reply