The ping command is the quickest way to check whether another machine is reachable over the network. It sends small ICMP echo requests to a host and measures how long the replies take, which makes it a first step for troubleshooting connectivity, latency, and packet loss on Linux.

This is part 3 of my Linux networking series. If you missed the earlier posts, start with Linux dig Command: 5 Examples Every Developer Should Know, then read the nslookup post.

1. Install ping

ping is installed by default on most systems. If it's missing, install it on Debian/Ubuntu with:

sudo apt update sudo apt install iputils-ping 

2. Ping a Domain or IP Address

ping google.com 

On Linux, ping keeps running until you stop it with Ctrl + C. Each line of output looks like this:

64 bytes from ... icmp_seq=1 ttl=117 time=14.2 ms 
  • icmp_seq is the packet number.
  • ttl is the time to live, which limits how many network hops a packet can make.
  • time is the round-trip time in milliseconds. Lower is better.

When you stop it, ping prints a summary with the packets sent and received, the percentage of packet loss, and the minimum, average, and maximum round-trip times.

3. Send a Fixed Number of Packets

ping -c 4 google.com 

The -c option stops ping after the given number of packets. This is useful in scripts and for quick checks, because you don't need to press Ctrl + C.

For a short summary only, add -q:

ping -c 4 -q google.com 

4. Change the Interval and Timeout

Wait 2 seconds between packets with -i:

ping -i 2 google.com 

Set how long to wait for each reply with -W (in seconds):

ping -c 4 -W 2 google.com 

Intervals shorter than 0.2 seconds require root privileges, so most of the time the default of 1 second is fine.

5. Tell DNS Problems from Network Problems

Ping a domain name and an IP address separately:

ping -c 4 google.com ping -c 4 8.8.8.8 
Domain works IP works What it likely means
Yes Yes Everything is fine
No Yes DNS problem (check dig or nslookup)
No No Network or firewall problem

If the IP address responds but the domain doesn't, the network is fine and the problem is name resolution. That's where the dig and nslookup commands from earlier in the series come in.

Bonus: Choose IPv4 or IPv6

ping -4 google.com ping -6 google.com 

Bonus: Change the Packet Size

ping -c 4 -s 1000 google.com 

The -s option sets the data size in bytes (the default is 56). Larger packets can help you spot problems that only appear with bigger payloads.

Tips

  • Some servers and firewalls block ICMP, so a failed ping doesn't always mean the host is down.
  • High or uneven time values point to network congestion or a poor connection.
  • Any packet loss above 0% is worth investigating.

Conclusion

The ping command is simple, but it answers the first question in any network problem: can I reach this host? Combine it with dig and nslookup and you can quickly tell whether the issue is DNS or the network itself.

Next: Linux traceroute Command: Simple Examples.

About Me

I'm Safal Bhattarai, a Tech Lead, Full Stack Developer, and DevOps Engineer.

🌐 Website · 💻 GitHub