The ping command is a network utility used to test the reachability of a host and measure the time it takes for packets to travel to and from that host. It helps diagnose network connectivity issues by sending ICMP Echo Request packets and analyzing the responses.
- Sends ICMP Echo Requests to check if a system or server is reachable.
- Measures round-trip time (RTT) for packets to travel between devices.
- Helps identify packet loss, network delays, or connection failures.
- Useful for testing local network issues as well as Internet connectivity.
- Shows continuous output until stopped manually using Ctrl + C.
- Commonly used for troubleshooting DNS, routing, and basic network health.
Example: Checking Internet Connection in Linux
To check your internet connection using the ping command, open the terminal and type the following command:
ping www.google.comThis command sends ICMP echo requests to google.com to check if the website is reachable and displays the response time for each packet.

Here,
- min: minimum time to get a response
- avg: average time to get responses
- max: maximum time to get a response
The internet connection to www.google.com is working correctly with 0% packet loss, successful transmission and reception of 4 packets, and low round-trip time (RTT) values averaging 1.264 ms, indicating a responsive and stable connection.
Syntax:
ping [options] host_or_IP_addressHere, "host_or_IP_address" represents the destination you want to ping.
PING Command Options in Linux:
1. Checking Ping Version
Displays the version of the ping utility installed on your system.
[Option: -V]
Example:
ping -VOutput:

2. Specifying the Number of Pings
Defines how many ICMP packets should be sent before ping stops.
[Option: -c]
Example:
ping -c 2 www.geeksforgeeks.orgOutput:

3. Controlling Packet Size
Allows sending packets of custom sizes for testing network behavior.
[Option: -s]
Example:
ping -s 40 -c 5 www.geeksforgeeks.org Output:

4. Changing the Time Interval Between Pings
Modifies the delay (in seconds) before sending the next packet (default: 1 sec).
[Option: -i]
Example:
ping -i 2 www.geeksforgeeks.orgNow, the ping interval will change to 2 seconds.
Output:

5. Showing Only Summary Output
Displays only the final packet summary and hides per-packet details.
[Option: -q]
Example:
ping -c 5 -q www.geeksforgeeks.orgOutput:

6. Setting a Ping Timeout
Sets how long (in seconds) ping should run before automatically stopping.
[Option: -w]
Example:
ping -w 3 www.geeksforgeeks.orgThis command instructs the system to stop pinging the specified website (www.geeksforgeeks.org) after waiting for 3 seconds.
Output:

7. Flood Ping for Performance Testing
Sends packets as fast as possible to stress test the network. (Requires sudo and should be used carefully.)
[Option: -f]
Example:
ping -f www.geeksforgeeks.orgThis command floods the network with PING packets directed at www.geeksforgeeks.org, providing a means to assess and test network performance.
Output:

8. Add Timestamp to PING
Timestamps record the current time of an event over a network. The ping command supports three timestamp options:
Options:
- tsonly (timestamp only)
- tsandaddr (timestamp and address)
- tsprespec (timestamp pre-specified for multiple hosts)
Examples:
ping -T tsonly -c 2 127.0.0.1Output:

ping -T tsandaddr -c 2 127.0.0.1Output:

9. Setting Maximum Wait Time for a Response
Defines how many seconds ping waits for each reply.
[Option: -W]
Example:
ping -c 5 -W 3 www.geeksforgeeks.orgThis command configures the system to wait for a response for a maximum of 3 seconds while sending 5 PING requests to `www.geeksforgeeks.org`.
Output:

10. Filling Packets with Custom Data
Fills outgoing packets with a specific hex pattern.
[Option: -p]
Example:
ping -c 5 -p ff www.geeksforgeeks.orgThis command fills PING packets sent to `www.geeksforgeeks.org` with the specified data, in this case, ones (represented by `ff`).
Output:

11. Enabling Path MTU Discovery
Determines the maximum MTU the route can handle.
[Option: -M do | want | dont]
Example:
ping -c 5 -M want www.geeksforgeeks.orgThis command initiates Path MTU Discovery for the specified website (`www.geeksforgeeks.org`) with the option to either prohibit fragmentation (`do`), perform PMTU discovery with local fragmentation when needed (`want`), or not set the DF flag (`dont`).
Output:

12. Setting TTL (Time To Live)
Defines how many hops a packet can travel before being dropped.
[Option: -t]
Example:
ping -c 5 -t 64 www.geeksforgeeks.orgThis command sends 5 PING requests to www.geeksforgeeks.org with a Time To Live (TTL) set to 64, restricting the packet's maximum allowed hops.
Output:

Other Examples
Here are a few more examples to help you thoroughly understand the ping command and verify network connectivity:
1. Ping an IP Address
- This checks basic network connectivity to Google’s public DNS server using its IP address.
- If this works but ping google.com fails, it usually means DNS (name resolution) is the problem, not the internet.
ping 8.8.8.82. Ping a Host Only Once
- Sends just one request to check if the host is reachable.
- Useful for quick checks in scripts or automation without flooding the network.
ping -c 1 google.com3. Continuous Ping Until Stopped
- Sends ping requests continuously until you press Ctrl + C.
- Helpful for live monitoring of network stability and watching if a connection drops or becomes slow
ping google.com4. Ping with Audible Alerts
- Plays a beep sound whenever a reply is received (or sometimes on changes).
- Useful when you want to monitor connectivity while doing other work, without staring at the screen.
ping -a google.com5. Print Kernel Timestamps
- Adds a kernel timestamp in front of each line, showing exactly when each reply was received.
- Helpful for precise timing analysis, debugging delays, or correlating logs with ping activity.
ping -D google.com
