ping Command
The ping command is the most common tool for testing network connectivity between two hosts. It sends ICMP ECHO_REQUEST packets to a destination and waits for a reply.
Common `ping` Commands
Standard Ping
ping google.comPings the specified host until stopped manually (with Ctrl+C).
Set Packet Count
ping -c 5 google.comSends a specific number of packets. The -c flag stands for "count". In this case, it sends 5 packets and then stops.
Set Interval
ping -i 2 google.comSets the interval between packets. The -i flag sets the wait time in seconds. Here, a packet is sent every 2 seconds.
Specify Interface
ping -I eth0 google.comSpecifies the network interface from which to send the packets (e.g., eth0). Useful on machines with multiple network cards.
Practical Usage: Testing Internet Connectivity
A common use for ping is to quickly check if you have a working internet connection. For this, it's best to ping a highly reliable and available server. Public DNS resolvers from large companies are perfect for this role.
Ping Google's DNS
ping 8.8.8.8Pings Google's public DNS server. It's a fast and reliable way to check for general internet connectivity. If this works, but pinging a domain name (like google.com) doesn't, you likely have a DNS problem.
Ping Cloudflare's DNS
ping 1.1.1.1Pings Cloudflare's public DNS server. It serves the same purpose as pinging Google's DNS and is another excellent, easy-to-remember choice for connectivity tests.