How to Use Ping Utility with Examples

The ping utility is a basic, yet the most widely used network command-line tool used to test network connectivity and name resolution of a remote device. The device can be another computer, network switch, or a router on your local network. Or, it can be a device on the Internet, such as a web server, web site, DNS server, or email server. Ping uses the Internet Control Message Protocol (ICMP) Echo function as described in RFC 792. A small data packet is sent through the network to the remote device. The device that sent the packet then waits and listens for a return packet. If the connections are good and the remote device is online, a good return packet will be received. If you encounter issues accessing a website, sending an email, or opening a file on your network file server, the ping tool is used to test and troubleshoot connectivity issue.

These commands shown here are tested on Windows 10 but most will work in other versions of Windows as well. In this article, we will cover the following:


Overview

The ping command allows you to send a signal to another computer (either on your local network or a computer on the Internet) to determine if it is active or if it can be reached. This command uses Internet Control Message Protocol (ICMP) to send out an ECHO_REQUEST to the target computer and waits for an ECHO_REPLY packet.

The ping command is one of the primary network troubleshooting tools to test reachability of a remote computer (hence the term ‘can it be pinged?’). Written by Mike Muuss in 1983, this utility, comprise of about a thousand line of code, was reportedly named ‘ping’ to have it sound like the ping submarine sonar makes.

How ping accomplishes this is by sending a series of small data packet to a device and waiting for a reply from the device to acknowledge (also referred to as replies) it received the data. For most Windows computer, the ping command sends a series of four (4) data packets. Most network devices are configured to automatically listen for and acknowledge receipt of each ping packet sent to them. The ping/reply process typically takes just milliseconds for each data packet. The replies, will let us know if the device is online and how long it took to receive the reply (known as latency).

The ping command reports the following information:

  • How many data packets were sent, received, and lost (you want to see zero lost).
  • Amount of time it took to receive the replies from the remote device - also referred to as latency. This is expressed in milliseconds, lower is better. Anything lower than 20 milliseconds (ms) is very good.
  • Time-to-Live (TTL) value that is used to tell the remote device how long to hold/use the packet before it can discard it. The TTL exact value differs based on the operating system. Maximum value is 255.
  • The IP address of the remote device (if it is a URL being pinged).

How to Launch Command Prompt

To use this utility, you will need to launch the Command Prompt window. The three common ways to launch the Command Prompt window are:

  1. Search for cmd using the built-in Windows search tool.
  2. Right-click on the Start icon and select Command Prompt.



  3. Press the keyboard combination WinKey + R, then type cmd at the Run window that appears.

    Run cmd


Ping Syntax

ping [/t] [/a] [/n <Count>] [/l <Size>] [/f] [/I <TTL>] [/v <TOS>] [/r <Count>] [/s <Count>] [{/j <Hostlist> | /k <Hostlist>}] [/w <timeout>] [/R] [/S <Srcaddr>] [/4] [/6] <TargetName>


Ping Parameters

Parameter Description
-t Ping the specified host until interrupted. To see statistics and continue - type Control-Break. To stop - type Control-C.
-a Resolve addresses to hostnames.
-n count Set the number of echo requests to send. Default is 4.
-l size Set the length (in bytes) of the data field (send buffer size). The default is 32 bytes. Maximum is 65,527.
-f Set the Don't Fragment flag in packet (IPv4-only) in the IP header set to 1. The echo Request message cannot be fragmented by routers in the path to the destination. This parameter is useful for troubleshooting path Maximum Transmission Unit (PMTU) problems.
-i TTL Set the Time To Live value. The default is the default TTL value of the host. The maximum TTL is 255.
-v TOS Type Of Service (IPv4-only. This setting has been deprecated and has no effect on the type of service field in the IP Header).
-r count Record route for count hops (IPv4-only).Count must be a minimum of 1 and a maximum of 9.
-s count Timestamp for count hops (IPv4-only). Count must be a minimum of 1 and a maximum of 4.
-j host-list

Loose source route along host-list (IPv4-only). With loose source routing, successive intermediate destinations can be separated by one or more routers. The maximum number of addresses of names is the host list is nine (9). The hostlist is simply a series of IP addresses in dotted decimal notation (e.g., 192.168.128.8) each separated by spaces. This parameter is only for IPv4 addresses.

-k host-list Strict source route along host-list (IPv4-only). With strict source routing, successive intermediate destinations must be directly reachable. The maximum number of addresses of names is the host list is nine (9). The hostlist is simply a series of IP addresses in dotted decimal notation (e.g., 192.168.128.8) each separated by spaces. This parameter is only for IPv4 addresses.
-w timeout Timeout in milliseconds to wait for each reply.
-R Use routing header to test reverse route also (IPv6-only). Per RFC 5095 the use of this routing header has been deprecated. Some systems may drop echo requests if this header is used.
-S srcaddr Source address to use (IPv6-only).
-c compartment Routing compartment identifier.
-p Ping a Hyper-V Network Virtualization provider address.
-4 Force tracert to use IPv4 for the trace.
-6 Force tracert to use IPv6 for the trace.
/? Displays help information.


Example Usage

There are a variety of switches (sub commands) available with the ping utility that will configure how it behaves. The examples in this article illustrates common ways ping is used.

ping <URL> - Test Reachability to a Website

To test network connectivity to a website, such as www.meridianoutpost.com, type the following in the command window then press Enter: ping www.meridianoutpost.com

In the example illustration shown below, the ping command sent four data packets to the web server hosting the website www.meridianoutpost.com. There were four 'pings' sent and four replies received (one for each of the four 'pings'). Additionally, the ping reports the amount of time it took to receive each of the replies (lower time is better) and other useful information. In this example, it shows the average round trip time is 66ms and the web server received and replied to all four ping packets.

Lastly, the ping also will report the IP of the website being pinged, namely 72.47.244.140. Ping will perform a DNS lookup to find the IP address of the remote device as it is required for any network communication on the Internet.

ping website

If the website you are pinging is offline, does not exist, or there is no network connectivity to it, ping will response back with time outs or other related messages in its result, as illustrated below.

ping timed out


ping <IP Address> - Test Reachability to a Specific IP

To test network connectivity to a specific IP address, such as 8.8.8.8 (this IP is a Google DNS server), type the following in the command window then press Enter: ping 8.8.8.8

ping ip address

If the website you are pinging is offline, does not exist, or there is no network connectivity to it, ping will response back with time outs or other messages in its result, similar to the those illustrated in the ping <URL> example


ping -n -l - Ping Using Custom Number of Packets and Packet Size

The ping utility allows to you custom how it behaves. Using the -n and -l switches, we can define the number of packet to send and the size of each packet, respectively. For example, to send 10 packets, each sized at 2,000 bytes to the web server hosting the website www.meridianoutpost.com, type the following in the command window then press Enter: ping -n 10 -l 2000 www.meridianoutpost.com

ping -n -l


ping -a - Ping to Find Hostname of an IP Address

You can use the -a switch to have ping report the hostname of a particular IP address. For example, the IP address 72.47.244.140 is a web server on the Internet. To find out the hostname of this server using ping command, type the following in the command window then press Enter: ping -a 72.47.244.140

In the example illustration shown below, the hostname for the web server with IP address of 72.47.244.140 is agaaacgeks.gs11.gridserver.com.

ping -a



ping <Domain Name> - Find the IP Address of a Domain Name/Website

Just like ping <URL> described previously, you can look up the IP address of a website or a domain with the ping utility. For example, to find the IP address to the domain mediatemple.net, type the following in the command window then press Enter: ping mediatemple.net

As the screenshot below shows, the IP for the domain mediatemple.net is 143.204.142.118.

ping domain name


ping -t - Ping Continuously

To continuously ping a device, use the -t switch. This will indefinitely ping the remote device until you explicitly stop it. The most common reason for using this switch is to have a real-time visible indicator to identify was a device comes online or offline. This would typically be in scenarios where administrator are troubleshooting or configuring a system. By continously pinging the device and looking at the response, one can know when it come online or offline.

To continuously ping, as an example, the IP address of 192.168.1.1, type the following in the command window then press Enter: ping -t 192.168.1.1

You can also specify an website URL to continuously ping as well. To stop the continuous ping, press CTRL+C.

ping -t


ping 127.0.0.1 - Loopback Address

The 127.0.0.1 is a special IP address, called a loopback address. It is a virtual IP address, in that it cannot be assigned to a device. This IP address is always interrupted to be 'yourself'. Meaning, if you ping this IP from your computer, you are pinging your own computer. If you are on a file server and you ping this loopback address from that device, you are pinging that file server.

This loopback address is used to test the device TCP/IP network stack (e.g., network software/driver) of the computer. If you are experience network connectivity issue on a computer, you would first perform ping 127.0.0.1 from that computer first. If ping responses with packet lost, then your connectivity issue is likely on that computer. You will need to resolve this first before exploring other causes. If the loopback ping reports no packet lost, then your connectivity issue is not stemming from your computer and you can then explore other causes upstream.

ping loopback


Other Usages and Getting Help

The example usage described in the article shows only some of the functions available with ping. To get a list of the available switches, type the following in the command window then press Enter: ping /?

ping /?


Tips

Improve Ping Time & Troubleshooting

  • Low ping time is better than high ping time. For online gaming, a ping time of 100ms or less is good. Ping time of 50ms or less is very good.
  • High ping time? Try these sugguest to improve to reduce your ping time:
    • If you are using a wireless connection, move closer to your router or wireless access point.
    • Use a wired connection to your network instead of a wireless connection.
    • Close any unnecessary background applications and websites.
    • Avoid stream (video, audio) on other computers on your network.
    • Reboot your router or modem.
  • You can check connectivity to various devices on the Internet by pinging them (web servers, email servers, web sites). Slower response times than normal can indicate network congestion on the network pathway.
  • If a ping to a domain name or a web site URL fails, try pinging its IP address instead. If pinging by IP is successful, this means there is a DNS issue where your computer is unable to resolve the domain or website to an IP address.
  • If pinging a host fails, try using the tracert utility to identify where the data packet is failing along its route.


Ping Responses Explained

  • <Destination Host> Unreachable: This ping response indicates a network pathway to the remote device cannot be found. This can mean a network device between your computer and the remote device, such as your firewall, is offline or mis-configured.
  • No Reply From <Destination Host>: This ping response indicates that the network pathway to the remote device is fine, but there is a problem with the device itself
  • ICMP Host Unreachable From Gateway: This ping response indicates your computer can communication with your local gateway (e.g., your local router) but the gateway itself is unable to reach the remote device. This can mean an issue with your ISP or ISP-provided device.
  • Request Timed Out: This ping response can indicate the remote device is offline. However, it is not always the case. A device can be configured to not response to ping requests. Administrators can opt to do this for security reasons as they feel that not announcing a device is online can minimize their exposure to bad actors on the Internet from performing malicious activities (e.g., hacking) against it.
  • TTL Expired In Transit: This response indicates the amount of time the packet may live on the network has exceeded the maximum amount of "time", more accurately, the number of hops. This can mean that there is a mis-configured router along the network pathway. The TTL (time to live) can be increased by using the -i switch and specifying a value. For example, to specify a TTL of 200 (the maximum value allows is 255) when pinging 8.8.8.8, type the following in the command window then press Enter: ping -i 200 8.8.8.8
  • Unknown Host: This response indicates that the IP address or website you are pinging is not found on the network or Internet. This can mean either:
    • You mis-typed your IP or website URL
    • A DNS server was not available to resolve the hostname


Example of a Good Ping Result

The following is an example of a good ping result. It shows all four test packets were sent successfully to the remote host. The four response packets sent from the remote host is received successfully by the local device (as indicated by 0% loss). Additionally, the round trip time are not excessively long.

Reply from 192.168.1.1: bytes=32 time<1ms TTL=64
Reply from 192.168.1.1: bytes=32 time<1ms TTL=64
Reply from 192.168.1.1: bytes=32 time<1ms TTL=64
Reply from 192.168.1.1: bytes=32 time<1ms TTL=64

Ping statistics for 192.168.1.1:
  Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
  Minimum = 63ms, Maximum = 63ms, Average = 63ms


Example Ping Result Showing Remote Device Not Responding

The following is an example ping result showing a that four test packets were sent to the remote device but none were responded to. This can mean one of the following likely scenarios:

  1. There a network connection issue (e.g., network congestion) to the device.
  2. The device is configured to not response to ping packets (ICMP echo replies). If this is the case, the device is likely online and functioning, despite it not responding to your ping test.
Pinging 192.168.1.222 with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.

Ping statistics for 192.168.1.222:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),


Example Ping Result Showing Remote Device Unreachable

The following is an example ping result showing a problem reaching the remote device. Four test packets were sent and no where received back from the remote host. A ping result like this can meaning one of the following:

  1. There is no network route (network path) to the remote device (perhaps due to a firewall or a network router configuration).
  2. The device is turned off.
  3. There is not device with that IP address.
Pinging 192.168.1.222 with 32 bytes of data:
Destination host unreachable.
Destination host unreachable.
Destination host unreachable.
Destination host unreachable.

Ping statistics for 192.168.1.222:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),


Redirect Output to Text File

  • Instead of displaying the results on the screen, you can have the results saved automatically to a text file on your computer. To do this, simply use the ">" symbol followed by the folder path and file name of your choice. For example, to redirect the output of ping 192.168.1.1, type the following in the command window then press Enter: ping 192.168.1.1 > c:\temp\ping-results.txt

    This will create a file named ping-results.txt in the folder path c:\temp that will have your ping result. You can then open this file with any text editor, such as Notepad on a Windows computer, as illustrated below.

    ping redirected output


Add Timestamp to Ping Result

The Windows ping utility does not come with a built-in function report the date and time in its results. However, with a bit of scripting, we can display the date and time next to each ping responses. The following script was developed from referencing various posts on StackOverflow. This example pings the website www.meridianoutpost.com. To see this script in action, type the following in the command window then press Enter:

ping meridianoutpost.com | cmd /q /v /c "(pause&pause)>nul & for /l %a in () do (set /p "data=" && echo(!date! !time! !data!) & ping -n 2 meridianoutpost.com > nul"

You will need to press CTRL+C to bring back the prompt. As illustrated below, this command displays the date and time next to each ping response.

ping with timestamp


Recommended Reading


Improve confidence and job performance

Improve productivity and efficiency

Learn more,
earn more

Life-long
investment
To learn more about this topic, we are providing you with recommendations to help you further your knowledge. These are our affiliate links to Amazon where you can purchase them and also explore a variety of other relevant books.


Summary

Simply knowing a device is reachable with a ping does not necessarily mean that the device is fully operating correctly. Being able to ping a web server, for example, only mean the network subsystem is working correctly. However, it does not mean that the Internet Information Services (IIS) on a Windows web server or Apache on a Linux web server application is functioning normal to deliver web page content.

The ping utility is a useful tool for troubleshooting basic network issues. As a helpdesk technician, network administrator, or system administrator, this will undoubtedly be used in conjunction with other advanced tools to effective trouble network issues.