The Wayback Machine - https://web.archive.org/web/20260217150245/https://www.geeksforgeeks.org/linux-unix/ping-command-in-linux-with-examples/

Ping Command in Linux

Last Updated : 16 Feb, 2026

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.com

This command sends ICMP echo requests to google.com to check if the website is reachable and displays the response time for each packet.

testing internet connection using ping command
testing internet connection using ping command

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_address

Here, "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 -V

Output:

To get ping version
To get ping version

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.org

Output:

Specify the number of pings in Linux
Specify the number of pings in Linux

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:

3

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.org

Now, the ping interval will change to 2 seconds.

Output:

Changing time interval in Ping Command
Changing time interval in Ping Command

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.org

Output:

6. Setting a Ping Timeout

Sets how long (in seconds) ping should run before automatically stopping.

[Option: -w]

Example:

ping -w 3 www.geeksforgeeks.org

This 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.org

This command floods the network with PING packets directed at www.geeksforgeeks.org, providing a means to assess and test network performance.

Output:

folding with ping
folding with ping

8. Add Timestamp to PING

Timestamps record the current time of an event over a network. The ping command supports three timestamp options:

Options:

  1. tsonly (timestamp only)
  2. tsandaddr (timestamp and address)
  3. tsprespec (timestamp pre-specified for multiple hosts)

Examples:

 ping -T tsonly -c 2 127.0.0.1

Output:

Adding timestamp to ping
Adding timestamp to ping
 ping -T tsandaddr -c 2 127.0.0.1

Output:

Adding timestamp to ping
Adding timestamp to ping

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.org

This 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.org

This command fills PING packets sent to `www.geeksforgeeks.org` with the specified data, in this case, ones (represented by `ff`).

Output:

Fill Packet with Data
Fill Packet with Data

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.org

This 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:

Path Mtu Discovery
Path Mtu Discovery

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.org

This 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:

Specify TTL (Time To Live)
Specify TTL (Time To Live)

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.8

2. 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.com

3. 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.com

4. 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.com
  • 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
Comment

Explore