ping
Command: Testing Network Connectivity
Summary
The ping
command is a fundamental network utility used to test the reachability of a host on an Internet Protocol (IP) network. It works by sending ICMP (Internet Control Message Protocol) echo request packets to a target host and waiting for an ICMP echo reply.
Introduction
The ping
command is a diagnostic tool that verifies whether a host can be reached across a network. It measures the round-trip time (RTT) for packets sent from the originating host to a destination computer and back. This helps determine network latency and packet loss. A successful ping
indicates that the target host is operational and reachable on the network. It's one of the first tools network administrators use to troubleshoot connectivity problems.
Use case and Examples
Basic Ping
This will send ICMP echo requests to google.com and display the round-trip time for each packet received. It will continue until interrupted (Ctrl+C).Ping with Count Limit
This will send only 5 ICMP echo requests to google.com, then stop. The output will show statistics for the 5 packets.Ping by IP Address
This will ping the Google Public DNS server using its IP address. This is useful for testing basic network connectivity independent of DNS resolution.Ping with Interval
This will send ICMP echo requests every 2 seconds instead of the default interval.Ping with Packet Size
This command sends ping packets with a data size of 100 bytes. Useful for testing MTU issues. Note that the header size is added to this, so the actual packet size will be larger.Commonly used flags
Flag | Description | Example |
---|---|---|
-c count | Stop after sending count ECHO_REQUEST packets. | ping -c 3 google.com (Sends 3 ping requests) |
-i interval | Wait interval seconds between sending each packet. The default is to wait one second between each packet. Requires root privileges for intervals less than 0.2 seconds. | ping -i 0.5 google.com (Sends ping requests every 0.5 seconds - may require sudo) |
-s packetsize | Specifies the number of data bytes to be sent. The default is 56, which translates into 84 ICMP data bytes when combined with the 28 bytes of ICMP header information. | ping -s 100 google.com (Sends ping requests with a 100-byte payload) |
-t ttl | Specifies the IP Time To Live. This sets the maximum number of hops a packet can take before it is discarded. | ping -t 10 google.com (Sets TTL to 10) |
-W timeout | Time to wait for a response, in seconds. | ping -W 2 google.com (Waits 2 seconds for a response) |
-q | Quiet output. Nothing is displayed except summary lines at startup time and when finished. | ping -q google.com (Displays only summary information) |