1. WebsitePlanet
  2. >
  3. Glossary
  4. >
  5. Website builders
  6. >
  7. What Is Ping?

What Is Ping?

Miguel Amado Written by:
Christine Hoang Reviewed by: Christine Hoang
04 December 2024
Ping is a fundamental network utility used to test the reachability of a host on an IP network and measure the round-trip time for messages sent from the originating host to a destination computer. It’s a command available on virtually every operating system with network connectivity.

Definition of Ping

Ping operates by sending Internet Control Message Protocol (ICMP) echo request packets to the target host and waiting for an ICMP echo reply. It reports errors, packet loss, and a statistical summary of the results, including the minimum, maximum, average round-trip times, and standard deviation of the round-trip time.

The term “ping” was coined from the sound that sonar makes, as its methodology is analogous to sonar’s technique of sending a pulse of sound and listening for the echo to detect objects underwater. Just as sonar sends out sound waves and listens for their echos, ping sends out ICMP echo requests and listens for ICMP echo replies.

How Does Ping Work?

When you issue a ping command, here’s what happens under the hood:

  1. Constructing the ICMP Echo Request: The ping utility constructs an ICMP echo request packet. This packet includes a type field (set to 8 for echo request), a code field (set to 0), a checksum field, an identifier, a sequence number, and an optional data payload.
  2. Sending the Packet: The utility sends this packet to the specified IP address using the ICMP protocol. If a hostname is provided instead of an IP address, ping will first resolve the hostname to an IP address using DNS.
  3. Waiting for a Response: After sending the echo request, the utility waits for an ICMP echo reply message from the target host. It will wait up to a certain timeout period (which can be adjusted with command-line options).
  4. Receiving the Echo Reply: If the target host receives the echo request and it is able to respond, it will send back an ICMP echo reply packet. This packet has a type field of 0, with the rest of the packet containing the same data as the request.
  5. Recording the Results: The ping utility records the time between when the request was sent and when the reply was received. This is the round-trip time (RTT).
  6. Repeating the Process: By default, the ping utility will send echo requests a specified number of times (typically four) or until stopped. The interval between each request can also be adjusted.
  7. Presenting the Statistics: Once all echo requests have been sent (or the process is stopped), ping presents a statistical summary that includes the success rate, the minimum, maximum, and average round-trip times, and sometimes additional metrics like standard deviation.
If the target host is unreachable, the ping utility will report a failure after the timeout period. Failures can occur due to various reasons: the host might be down, a firewall might be blocking ICMP traffic, or network congestion could be causing packets to be dropped.

Ping and the OSI Model

Ping operates on the Network layer (Layer 3) of the OSI model. This is the layer responsible for packet forwarding including routing through intermediate routers.

ICMP, the protocol used by ping, is part of the Internet Protocol Suite, which is a set of communications protocols used on the Internet and similar computer networks. ICMP is used by network devices, like routers, to send error messages and operational information indicating success or failure when communicating with another IP address.

Although ICMP is used for diagnostic and control purposes, it’s not a transport protocol like TCP or UDP. It’s more like a helper protocol for IP.

Ping Message Format

The ICMP echo request and echo reply packets used by ping have a specific format:

  1. Type (8 bits): For echo request, type = 8. For echo reply, type = 0.
  2. Code (8 bits): For echo request and reply, code = 0.
  3. Checksum (16 bits): Error checking data, calculated from the ICMP packet.
  4. Identifier (16 bits): Used to match echo replies with echo requests. Usually set to a unique value for each ping process.
  5. Sequence Number (16 bits): Also used to match echo replies with echo requests. Usually incremented for each packet sent.
  6. Data (variable length): Optional data that is sent in the ping. Its size can be set with command-line options.
These fields are encapsulated into the data portion of an IP packet.

Ping Command Syntax and Options

The basic syntax of the ping command is:

ping [options] destination

Here, destination is either an IP address or a hostname. If a hostname is provided, ping will attempt to resolve it to an IP address using DNS.

Some common options include:

  • -c count: Stop after sending count ICMP echo request packets.
  • -i interval: Wait interval seconds between sending each packet. The default is to wait for one second between each packet.
  • -s packetsize: Specifies the number of data bytes to be sent. The default is 56, which translates into 64 ICMP data bytes when combined with the 8 bytes of ICMP header data.
  • -t timeout: Specify a timeout, in seconds, before ping exits regardless of how many packets have been sent or received.
  • -W waittime: Time to wait for a response, in seconds. This option affects only timeout in absense of any responses, otherwise ping waits for two RTTs.
Options can vary slightly depending on the operating system and version of ping.

Interpreting Ping Results

A typical ping output looks like this:

PING example.com (93.184.216.34) 56(84) bytes of data.
64 bytes from 93.184.216.34: icmp_seq=1 ttl=56 time=11.4 ms
64 bytes from 93.184.216.34: icmp_seq=2 ttl=56 time=11.5 ms
64 bytes from 93.184.216.34: icmp_seq=3 ttl=56 time=11.3 ms
64 bytes from 93.184.216.34: icmp_seq=4 ttl=56 time=11.7 ms

— example.com ping statistics —
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 11.321/11.515/11.745/0.187 ms

Let’s break this down:

The first line shows the ICMP echo request being sent, including the target IP address and the size of the packet.

Each subsequent line represents an ICMP echo reply received. It includes:

  • The number of bytes in the reply (typically the same as the request)
  • The IP address the reply came from
  • The ICMP sequence number (icmp_seq)
  • The Time to Live (TTL) of the packet
  • The round-trip time (RTT) for that specific packet
To expand a little bit more, TTL stands for “Time to Live”. It’s a field in the IP header that gets decremented at each router hop. When the TTL reaches zero, the packet is discarded. This prevents packets from getting stuck in infinite routing loops. In the context of ping, the TTL value can give a rough indication of the operating system of the target host, as different operating systems set different default TTL values.

After all packets are sent (or the ping is stopped), a summary is shown. This includes:

  • The total number of packets transmitted and received
  • The percentage of packets lost (if any)
  • The total time the ping took
  • The minimum, average, maximum, and standard deviation (mdev) of the round-trip times
Here’s how to interpret some key values:

  • Packet Loss: This is the percentage of packets that were sent but not received back. A high packet loss (more than a few percent) could indicate network congestion, a problem with the target host, or a problem with the network in between.
  • Round-Trip Time (RTT): This is the time it takes for an ICMP echo request to be sent plus the time it takes for an ICMP echo reply to be received. It’s a measure of the latency of the network. High RTTs could indicate network congestion, a problem with the target host, or simply a long distance between the two hosts.
  • Time to Live (TTL): This is a field in the IP header that’s decremented at each router hop. When it reaches zero, the packet is discarded. This prevents packets from being stuck in infinite routing loops. The initial TTL value can give a rough indication of the operating system of the target host.
For general internet usage, a ping speed (which is actually the round-trip latency) of 100ms or less is considered good. However, for more latency-sensitive applications like online gaming, a ping speed of 50ms or less is preferable. It’s important to note that ping speed is affected by the physical distance between the hosts: the further the distance, the higher the latency.

Applications of Ping

Ping is an incredibly versatile tool with numerous applications:

  1. Network Diagnostics: Ping is often the first tool used when diagnosing network problems. If a ping to a host fails, it immediately tells you that there’s a problem reaching that host.
  2. Connectivity Testing: Before attempting to connect to a service on a host (like a web server or an SSH server), it’s often a good idea to ping the host first to ensure it’s reachable.
  3. Latency Measurement: The round-trip times reported by ping can give you a good idea of the latency between your host and the target host. This is particularly useful when troubleshooting performance issues.
  4. Traceroute: While ping itself doesn’t perform traceroute functionality, the principles of ICMP used by ping are also used by the traceroute utility to map the path packets take from the source to the destination.
  5. Network Discovery: Pinging a range of IP addresses can help discover which IP addresses are in use on a network. This is often referred to as a “ping sweep”.
  6. Scripting and Automation: Because ping is a simple command-line utility, it’s often used in scripts and automation tasks. For example, a script might ping a host and take a certain action based on whether the ping succeeds or fails.

Limitations and Challenges

Despite its usefulness, ping does have some limitations and challenges:

  1. Firewall and Security Considerations: Many firewalls are configured to block ICMP traffic to prevent certain types of network attacks and reconnaissance. This means that a failed ping doesn’t necessarily mean the target host is down; it could just mean that ICMP traffic is being blocked.
  2. Other Causes of Failure: A failed ping could be due to many reasons other than the target host being down. It could be due to a network problem, a misconfigured router, or the ICMP echo request being dropped due to network congestion.
  3. Packet Loss and Latency: While ping can report on packet loss and latency, it doesn’t provide detailed information on the causes of these issues. Other tools (like traceroute or network monitoring systems) are needed for more in-depth troubleshooting.
  4. ICMP Echo vs Application Layer: A successful ping only means that the target host is reachable and responding to ICMP echo requests. It doesn’t guarantee that any specific service (like a web server or database) is running on that host.
  5. Potential for Abuse: Ping can be used maliciously in certain types of network attacks, like ping floods (where a target is overwhelmed with ICMP echo requests) or ping of death (where a malformed ICMP packet causes a system crash).
Despite these limitations, ping remains an essential tool for network diagnostics and troubleshooting.

Why is ping not working?

There could be several reasons why ping is not working:

  1. The target host is down or not connected to the network.
  2. There’s a network problem between your host and the target host.
  3. A firewall is blocking ICMP traffic.
  4. The ping request or reply is being dropped due to network congestion.
To troubleshoot, you can try pinging other hosts to determine if the problem is with the target host or the network. You can also use other tools like traceroute to further diagnose network issues.

Summary

Ping is a fundamental network utility used to test the reachability of a host and measure the round-trip latency. It works by sending ICMP echo request packets to the target host and waiting for ICMP echo reply packets. Ping provides a basic but essential diagnostic tool for network troubleshooting and performance measurement.

Understanding how ping works, how to interpret its results, and its limitations is crucial for anyone involved in network administration or troubleshooting. While ping is a simple tool, it’s often the first step in diagnosing network issues and is an essential part of any network administrator’s toolkit. Mastering ping can help you quickly identify and resolve network problems, leading to a more stable and better-performing network.

Rate this Article
4.3 Voted by 3 users
You already voted! Undo
This field is required Maximal length of comment is equal 80000 chars Minimal length of comment is equal 10 chars
Related posts
Show more related posts
We check all user comments within 48 hours to make sure they are from real people like you. We're glad you found this article useful - we would appreciate it if you let more people know about it.
Popup final window
Share this blog post with friends and co-workers right now:
1 1 1

We check all comments within 48 hours to make sure they're from real users like you. In the meantime, you can share your comment with others to let more people know what you think.

Once a month you will receive interesting, insightful tips, tricks, and advice to improve your website performance and reach your digital marketing goals!

So happy you liked it!

Share it with your friends!

1 1 1

Or review us on 1

3468092
50
5000
114310437