FTC disclaimer: This post contains affiliate links and I will be compensated if you make a purchase after clicking on my link.
Ping command is a handy tool that is used to test various points of your network.
It checks by sending data packets from one computer to another network, device, or IP address.
Further, it will measure how it takes to reach the destination and how long it takes to respond from the destination server.
What is Ping Command? What does the ping command do?
The ping command is a command prompt command that verifies how the source computer communicates with another computer or server in a network.
It also checks the ability of the source computer and how it is reaching out to the destination computer.
The ping command is used in the command prompt window to test the connection between two computers or servers.
How does the ping command work?
The ping command works very similar to sonar technology, where it sends pulses of sound to the nearby object, and then it echoes back.
Operators can now determine that how much time it take pulses to return to the source.
In computer networking, the ping command work within the Internet Control Message Protocol (ICMP), an integral part of the IP network.
When the ping command is generated, it will send an echo request to the IP address or server specified. The remote server or IP address will receive an echo request and respond to the request with an echo reply packet.
In other words, when you issue a ping command on a specified IP address or server, then it will send multiple packets of information to the server and wait for the response.
When the computer receives the response, it will display how long it took to respond. If there would be no reply, then it will send an error message.
The time is taken for the network to respond or reply is called latency.
The most common response you will receive contains the following information.
- Several bytes were received as a response.
- Target IP address
- The time taken to respond.
What is a ping command used for?
In networking, the ping command will test the connection between your computer and servers or any device.
It will help you determine what network problem you are facing. Further, it will test how slow your internet connection is by sending data packets.
Moreover, it will also help you identify any data packet loss when traveling from one point to another.
The ping command will also help you to determine whether the site is down or unavailable.
Where to use the ping command?
The ping command is incorporated in almost all operating systems. For instance, you can use the ping command in macOS, Linux, and any version of Windows.
You can use the ping command using the command prompt window or terminal to send a ping request.
In the simplest form, the ping tool consists of two things; ping command and destination address.
The destination address can be either an IP address or a domain name.
Moreover, you can customize the ping utility tool to obtain the required output.
ping 23.54.49.182
ping www.microsoft.com
List of available output when you ping digitalmediaglobe.com
.
Pinging digitalmediaglobe.com [2606:4700:3035::6815:1971] with 32 bytes of data:
Reply from 2606:4700:3035::6815:1971: time=199ms
Reply from 2606:4700:3035::6815:1971: time=194ms
Reply from 2606:4700:3035::6815:1971: time=224ms
Reply from 2606:4700:3035::6815:1971: time=243ms
Ping statistics for 2606:4700:3035::6815:1971:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 194ms, Maximum = 243ms, Average = 215ms
Ping switches and variables
You will find so many ping switches that customize the default ping command for more specific purposes.
Moreover, the ping switches may vary across the different operating systems.
For instance, Windows uses a ping switch -n (number) to instruct a ping command that how many pings to send. However, Unix systems use ping switch -c (count) to do the same work.
You can get the list of ping command switches by using the command. ping -?
.
Also, the corresponding variables to be used along with the ping command on that particular operating system.
Ping Command Syntax
The ping command switches and ping command syntax may vary for different operating systems.
ping [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS] [-r count] [-s count] [[-j host-list] | [-k host-list]] [-w timeout] [-R] [-S srcaddr] [-c compartment] [-p] [-4] [-6] target_name
Let’s look into the ping command switches to be used in Windows operating system.
Ping the server until stopped: -t
It instructs the ping command to keep running the ping until the user stops it. The user can stop it by pressing CTRL and C.
This type of command is mostly used to test the network speed till you get the correct response.
Resolve IP address: -a
This ping command is used to resolve the IP address or hostname.
Number of ping count: -n
This ping switch is used to instruct the number of times the echo-request or pings to be sent.
By default, the Windows operating system uses four times, and the Unix system uses five times to send echo requests.
It is used mostly to gather data, for instance, to measure the variation in reply times or responsiveness of the system.
Size of data packets: -l
This ping command option is used to set the size of the data packets.
The “Size” ping switch specifies the ping packet size. The default value for Windows is 32 bytes and for Unix/Linux operating system is 64 bytes.
You can set the maximum size of 65,527
Stop IP packets fragmentation: -t
This ping command stops IP fragmentation when ICMP Echo-Request is sent to the destination server. The IP fragmentation starts when the packet size goes beyond 1500 bytes.
The packet size in a network is known as the Maximum Transmission Unit (MTU).
So, by default, the MTU size for an IP packet is 1500 bytes.
Time to Live (TTL) value: -i
TTL stands for Time To Live. It specifies the number of hops or servers to cover before it could send failed attempt message.
The maximum TTL value you can set is 255.
Set a Type of Service (TOS) value: -v
Using this ping command, you can specify the Type of Service (TOS). It started in Windows 7, and now it is not functional.
Number of hops count: -r
This ping command will specify the number of hops between the source computer and destination computer or server. The maximum value it can display is 9.
So, it is better to use the “tracert” command to get details of the number of hops between host and destination.
Report the time: -s
This ping command option will report the time for each Echo-request send and Echo-reply received. It is measured in Internet Timestamp format.
By default, it will display the timestamp for four hops.
Timeout value: -w
Timeout ping switch specifies the time to wait before you can get the reply from the destination server.
By default, Windows operating uses 4,000 milliseconds or 4 seconds.
Trace the round trip path: -R
This ping command will trace the round trip path from source to destination and then back to the source.
Source address (srcaddr) to use: -s
It will specify the source address to be used.
Hyper-V Network Virtualization provider address: -p
This ping switch is used to ping the Hyper-V Network Virtualization provider address.
The provider address will appear on the data packets that are exchanged with a server running Hyper-V.
Use IPv4 address: -4
This ping command will force to use IPv4 address instead of the hostname or IPv6 address. In Windows OS, it uses the command ping -4
and in Linux, it uses ping
.
Use IPv6 address: -6
This ping command will tell to respond with an IPv6 address instead of the hostname or IPv4 address. In Windows OS, it uses the command ping -6
and in Linux, it uses ping6
.
The common Ping command examples
Ping domain name
The domain name or hostname we can use is www.google.com.
ping -n 6 -l 1200 www.google.com
The output will be as below:
C:\WINDOWS\system32>ping -n 6 -l 1200 www.google.com
Pinging www.google.com [2404:6800:4002:806::2004] with 1200 bytes of data:
Reply from 2404:6800:4002:806::2004: time=157ms
Reply from 2404:6800:4002:806::2004: time=517ms
Reply from 2404:6800:4002:806::2004: time=159ms
Reply from 2404:6800:4002:806::2004: time=151ms
Reply from 2404:6800:4002:806::2004: time=141ms
Reply from 2404:6800:4002:806::2004: time=147ms
Ping statistics for 2404:6800:4002:806::2004:
Packets: Sent = 6, Received = 6, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 141ms, Maximum = 517ms, Average = 212ms
Here, we have used ping switch -n to specify the number of pings to send, which is 6. Also, the switch -l specifies the packet size 1200 bytes instead of the default 32 bytes.
Additionally, there is no loss in packet size and the average time it took to respond for each ping is 212 ms.
Ping localhost
The ping command for pinging localhost is
ping 127.0.0.1
The localhost IP address is also called as IPv4 localhost IP address or IPv4 loopback IP address.
You can use this command to check Windows network features are working properly. It does not verify anything about network hardware or your computer connection with another computer in a network.
In the IPv6 version, you can use the ping command. ping ::1
.
Resolve IP address or find the hostname.
The hostname of an IP address can be resolved using the below ping command.
ping -a 192.168.1.22
This command work by first resolving the IP address to a hostname and then continue with the default ping results.
Ping command to test router.
This ping command will ping the router to verify whether it is reaching the router or not.
ping 192.168.2.1
Moreover, you can use this ping command when you cannot reach the internet or logging into your router web interface.
The router IP address or gateway address is required when you are building a local network.
Ping with IPv6 or IPv4
This command is used to retrieve IP addresses in IPv6 or IPv4 format.
ping -t -6 digitalmediaglobe.com
It will retrieve the IPv6 address and continue to ping until it is stopped with Ctrl+C.
Conclusion
A different approach is implemented while using the ping command. The inside-out approach will first ping loopback address, then to the router, and later to an internet address.
The outside-in approach will first ping to an internet address, then to the router, and in the last local devices.
Moreover, the ping command is used with other networking commands like tracert, ipconfig, netstat, and nslookup.
The ping command is also used in the Linux system, and other third-party tools also exist that provide the same basic ping command feature.
The ping command is mostly suitable to troubleshoot local networks or home networks.
But, there is more complexity for a larger network, and you have to use a lot more networking tools and a ping tool.
There would be the possibility that you won’t get a response from the destination server because of built-in firewalls. So, to ping a device, you have to turn off the firewall to get a response.