Skip to main content

Command Palette

Search for a command to run...

Cheatsheet & Examples: ping

Updated
3 min read
H

I am a developer from Malaysia. I work with PHP most of the time, recently I fell in love with Go. When I am not working, I will be ballroom dancing :-)

The ping command is a network utility used to test the reachability of a host on an Internet Protocol (IP) network. It works by sending Internet Control Message Protocol (ICMP) echo request packets to the target host and listening for echo response packets.

Basic Ping to a Host

Example Usage: ping google.com

What it does: Sends ICMP echo request packets to the host google.com and displays the round-trip time for each packet received. It will continue to ping the host indefinitely unless interrupted.

Command-line Arguments Explained:

  • google.com: This is the hostname or IP address of the target host you want to test.

Ping with a Specific Count

Example Usage: ping -c 4 google.com

What it does: Sends a specified number of ICMP echo request packets to the host. After receiving the specified number of responses or a timeout, it displays statistics.

Command-line Arguments Explained:

  • -c 4: This option specifies the number of echo requests to send. In this example, it sends 4 packets.
  • google.com: The target host.

Ping with a Timeout

Example Usage: ping -W 2 -c 3 google.com

What it does: Sends a specified number of packets, but with a timeout setting, meaning the ping will terminate if no response is received within the specified number of seconds.

Command-line Arguments Explained:

  • -W 2: Specifies the timeout in seconds to wait for a response.
  • -c 3: Specifies the number of packets to send, in this example, 3.
  • google.com: The target host.

Ping with a Packet Size Adjustment

Example Usage: ping -s 1000 google.com

What it does: Sends ICMP echo requests with a specified packet size. This can be useful for testing network MTU (Maximum Transmission Unit) and for general network performance testing.

Command-line Arguments Explained:

  • -s 1000: Specifies the size of the ICMP payload in bytes. The default is typically 56 bytes. This value, plus the ICMP header, results in a larger packet size being sent.
  • google.com: The target host.

Ping with a Time to Live (TTL) Adjustment

Example Usage: ping -t 64 google.com

What it does: Sends ICMP echo requests with a specific time to live (TTL) value. TTL defines how many hops a packet can make before being discarded.

Command-line Arguments Explained:

  • -t 64: Specifies the TTL value for the packets.
  • google.com: The target host. Note that this option is not available on all ping implementations. Some systems might have an equivalent with different syntax.

Ping Using Numeric IP Address

Example Usage: ping 8.8.8.8

What it does: Sends ICMP echo request packets to the IP address 8.8.8.8, which is Google's public DNS server.

Command-line Arguments Explained:

  • 8.8.8.8: The numeric IP address of the target host.

More from this blog

Hong's Tech Blog

110 posts

The blog is older than you know. I prefer counting from the emergence of one integral anomaly to the emergence of the next, in which case this is the forth version.