即使您不是网络专家(networking expert),您也可能在使用计算机、无线路由器等网络设备、在线应用程序或在互联网上玩游戏时遇到过PING一词。(PING)如果您想知道计算机上的 ping 是什么、ping 命令(ping command)如何工作、如何理解它显示的数据以及如何在Windows中使用它,请阅读本教程:
什么是平?
Ping 是一个命令行工具(command line tool),可在许多操作系统中使用,您可以使用它来测试您的计算机或设备(computer or device)是否可以通过网络和/或 Internet访问目标计算机。(destination computer)
网络测试 ( SpeedTest(SpeedTest) ) 或游戏中的 ping 是什么?
当您在各种应用程序、SpeedTest等网络测试或在线游戏中看到 ping 报告时,它指的是您的 PC 获得对ping 命令(ping command)的响应所需的时间。此时间以毫秒 (ms) 为单位报告,它是您的 Internet 连接或网络连接的(network connection)反应时间(reaction time)速度的指标。ping 越低,反应时间(reaction time)就越好。
为什么 ping 有用?
ping 命令(ping command)主要用于对网络和 Internet 上的设备的可访问性进行故障排除。此命令使用一系列Echo消息(使用Internet 控制消息协议(Internet Control Message Protocol))来确定以下内容:
为了更好地理解事情,请看下面的屏幕截图,我们在 Windows 中运行了ping 命令(ping command):ping www.microsoft.com。
从这个命令中,我们学到了以下内容:
如您所见,ping 实用程序默认发送四个回显请求,并根据应从目标获得的回复共享统计信息和数据。
ping是谁发明的?
ping 实用程序由一位名叫Mike Muuss的(Mike Muuss)美国人(American)于1983 年 12 月(December 1983)在马里兰州(Maryland)阿伯丁试验场的(Aberdeen Proving Ground)弹道研究实验室(Ballistic Research Laboratory)工作时创建。该名称来自潜艇、水面舰艇和飞机中使用的声纳技术(sonar technology),该技术发送脉冲并监听(pulse and listens)回声以检测水下物体。他发现这是 ping 实用程序如何工作的合适比喻。
在哪些操作系统和设备中可以使用 ping?
您可以在Windows、Linux、MAC OS X、Unix、FreeBSD和许多其他操作系统中为台式计算机、服务器和其他设备使用ping 工具。(ping tool)甚至像路由器这样的网络设备也使用ping 工具(ping tool)来解决网络问题。
如何在 Windows 中使用 ping?
如果您想在Windows中使用(Windows)ping 工具(ping tool),请打开命令提示符或 PowerShell(Command Prompt or PowerShell)。然后,输入ping后跟目标计算机或设备的(target computer or device)IP 地址(IP address)(或主机名)。例如,键入以下内容:“ping 192.168.1.1”或“ping www.bing.com”,不带引号。
正如微软所记录的,here,Windows中的 ping 命令可以使用很多参数。要亲自查看它们,请编写ping /?或平-?(ping -?)然后按键盘上的Enter 。Windows 列出了可用于ping 工具(ping tool)的所有参数和开关。
注意:您可以在(NOTE:)ping 命令(ping command)的任何参数之前使用 / 或 - 。它们是可互换的,并导致相同的结果。
以下是ping 命令(ping command)的所有开关的说明:
-
/t - ping 继续向目标发送 Echo 请求消息,直到手动中断。要中断并显示统计信息,请按CTRL+Break。要中断并退出 ping,请按CTRL+C。
-
/a - ping 尝试解析并显示作为目标输入的 IP 地址的主机名。
-
/n count - 使用此命令将 Echo 请求消息的数量从 4(默认值)更改为其他值。您可以使用 1 到 4294967295 之间的任何数字。
-
/l size - 设置发送到目标的 Echo 请求消息的大小(以字节为单位),从 32(默认值)到其他值。您可以使用 1 到 65527 之间的任何数字。
-
/f - 使用它来发送带有“不分段”标志的 Echo 请求消息,这样请求在到达目的地的途中不会被路由器分段。此选项仅适用于 IPv4 地址,可用于解决路径最大传输单元(Maximum Transmission Unit)(PMTU) 问题。
-
/i TTL - 设置Echo 请求的生存时间(Time to Live)(TTL) 值,最大值为 255。TTL 限制 ping 命令发送的数据的生命周期。如果 TTL 值已过且未收到回复,则丢弃数据。
-
/v TOS - 设置用于 Echo 请求的服务类型 (TOS) 。(Type of Service (TOS))默认值为 0,最大值为 255。此选项仅适用于 IPv4 地址。
-
/r count - 设置您的 PC 和您希望通过 ping 命令记录和显示的目标之间的跳数。计数的最大值为 9。它仅适用于 IPv4 地址。
-
/s count - 报告收到每个 Echo 请求并发送每个回复的时间(以Internet 时间戳格式)。(Internet Timestamp)计数的最大值为 4,这意味着只有前四跳可以加时间戳。此选项仅适用于 IPv4 地址。
-
/j host-list - 使用主机列表中指定的松散源路由(Loose Source Route)。使用这种类型的路由,连续的中间目的地可以被一个或多个路由器分开。主机列表中的地址或名称的最大数量为 9。主机列表是由空格分隔的一系列 IP 地址,它们必须是 IPv4 地址。
-
/k host-list - 使用主机列表中指定的严格源路由(Strict Source Route)。使用严格路由,下一个中间目的地必须可以直接到达(并且不被路由器隔开)。主机列表中的地址或名称的最大数量为 9。主机列表是一系列以空格分隔的 IPv4 地址。
-
/w timeout - 超时值调整 ping 等待每个回复的时间量(以毫秒为单位)。默认超时值为 4000 或 4 秒。
-
/r range - 告诉 ping 命令跟踪往返路径,以获取多个跃点。它仅适用于 IPv6 地址。范围必须是 1 到 9 之间的数字。
-
/s srcaddr - 指定使用 IPv6 地址时要使用的源地址。地址必须在srcaddr之后输入。
-
/c compartments- 指定路由隔间标识符。
-
/p - ping Hyper-V 网络虚拟化提供程序地址。
-
/4 - 强制使用 IPv4 地址,它与主机名一起使用,而不是 IP 地址。例如,写"ping /4 www.microsoft.com"(不带引号),它会返回主机名的 IPv4 地址。
-
/6 - 强制使用 IPv6 地址,它与主机名一起使用,而不是 IP 地址。例如,写入“ping /6 www.microsoft.com”,您会看到主机名的 IPv6 地址。
使用 ping 命令的几个示例:
为了确保您更好地理解如何使用ping 命令(ping command),我们将分享一些示例并解释它们在现实生活中的使用方式。如果您想监控某个网站及其可用性,您可以使用不带引号的“ping -t domainname” 。该命令无休止地对它进行 ping 操作,并共享回复每个Echo 请求(Echo request)所需的时间。
但是,如果您对管理良好的主机进行这种无休止的监控,您的 PC 可能会被禁止访问。不要忘记按键盘上的CTRL+C
您可能希望使用“ping -n count hostname”来发送有限数量的("ping -n count hostname")Echo 请求(Echo request)消息,如下例所示:
在上面的屏幕截图中,您可以看到主机最初是可用的并回复了ping 命令(ping command),然后它就下线了,所有剩余的请求都超时了。
如果您知道主机的IP 地址(IP address),并且想知道主机名,则可以使用"ping -a IP address"。ping 尝试解析并显示目标的主机名,然后返回它,类似于下面的屏幕截图。
您是否使用ping 命令(ping command),以及如何使用?
现在您知道 ping 是什么、它是如何工作的、它做了什么以及如何在Windows中使用它。在结束本教程之前,请在下方发表评论并分享(comment below and share)您可能遇到的任何问题。另外,我们想知道您如何使用ping 命令(ping command)。
What is the ping command? What is ping in apps and games? How to use ping, in Windows?
Even though you are not a networking expert, you may have encountered the term PING, when using computеrs, networking devices like wireless routers, online apps or when playing games on the internet. If you want to knоw what the ping is when it comes to computers, how the ping command works, how to understand the data it displays, and how to use it in Windows, read this tutorial:
What is ping?
Ping is a command line tool, available in many operating systems, that you can use to test whether your computer or device can reach a destination computer through the network and/or the internet.
What is ping in networking tests (SpeedTest) or games?
When you see the ping reported in all kinds of apps, in networking tests like SpeedTest, or in online games, it refers to the time it takes for your PC to get a response to a ping command. This time is reported in milliseconds (ms), and it is an indicator of the speed of the reaction time of your internet connection or your network connection. The lower the ping, the better the reaction time.
Why is ping useful?
The ping command is useful mostly for troubleshooting the accessibility of devices on the network and the internet. This command uses a series of Echo messages (using the Internet Control Message Protocol) to determine things like:
To better understand things, take a look at the screenshot below, where we ran a ping command, in Windows: ping www.microsoft.com.
From this command, we learned the following:
-
That the www.microsoft.com website is available and reachable from our Windows PC because we received a reply.
-
The IPv6 address of the microsoft.com website. It is the weird address that is displayed after the text "Reply from."
- That there was no data loss in our connection to the microsoft.com website.
- The time it took, in milliseconds, for microsoft.com to reply to our ping command: for each of the four echo requests individually, the minimum, the maximum and the average time it took to respond to our ping command.
As you can see, the ping utility sends four echo requests by default, and it shares statistics and data based on the replies it should get from the target.
Who invented ping?
The ping utility was created by an American named Mike Muuss, in December 1983, while working in Ballistic Research Laboratory at the Aberdeen Proving Ground, in Maryland. The name comes from the sonar technology used in submarines, surface ships, and aircraft, that sends a pulse and listens for the echo to detect underwater objects. He found it a suitable metaphor for how the ping utility works.
In which operating systems and devices is ping available?
You can use the ping tool in Windows, Linux, MAC OS X, Unix, FreeBSD and many other operating systems for desktop computers, servers, and other equipment. Even networking equipment like routers implemented the ping tool for troubleshooting network problems.
How to use ping in Windows?
If you want to use the ping tool in Windows, open the Command Prompt or PowerShell. Then, enter ping followed by the IP address (or the hostname) of the target computer or device. For example, type something like: "ping 192.168.1.1" or "ping www.bing.com" without the quotation marks.
As documented by Microsoft, here, the ping command in Windows can use lots of parameters. To see them for yourself, write ping /? or ping -? and press Enter on your keyboard. Windows lists all the parameters and switches that you can use for the ping tool.
NOTE: You can use / or - before any parameter of the ping command. They are interchangeable and lead to the same result.
Here is an explanation of all the switches for the ping command:
-
/t - ping continues sending Echo request messages to the destination until interrupted manually. To interrupt and display statistics, press CTRL+Break. To interrupt and quit the ping, press CTRL+C.
-
/a - the ping tries to resolve and show the hostname of an IP address that is entered as the target.
-
/n count - use this change the number of Echo request messages from 4 (the default) to something else. You can use any number from 1 to 4294967295.
-
/l size - sets the size (in bytes) of the Echo request message that is sent to the target, from 32 (the default) to something else. You can use any number from 1 to 65527.
-
/f - use this to send Echo request messages with a "Do Not Fragment" flag turned on so that the request is not fragmented by routers, on the way to the destination. This option works for IPv4 addresses only, and it is useful for troubleshooting path Maximum Transmission Unit (PMTU) problems.
-
/i TTL - sets the Time to Live (TTL) value for the Echo request, the maximum of which is 255. TTL limits the lifetime of the data being sent by the ping command. If the TTL value has elapsed and no reply was received, the data is discarded.
-
/v TOS - sets the Type of Service (TOS) used for the Echo request. The default value is 0, and the maximum is 255. This option works only for IPv4 addresses.
-
/r count - sets the number of hops between your PC and the target that you want be recorded and displayed by the ping command. The maximum value for the count is 9. It works only with IPv4 addresses.
-
/s count - reports the time (in Internet Timestamp format) when each Echo request is received and each reply is sent. The maximum value for the count is 4, meaning that only the first four hops can be time stamped. This option works just with IPv4 addresses.
-
/j host-list - uses the Loose Source Route specified in the host list. With this type of routing, successive intermediate destinations can be separated by one or multiple routers. The maximum number of addresses or names in the host list is 9. The host list is a series of IP addresses separated by spaces, and they have to be IPv4 addresses.
-
/k host-list - uses the Strict Source Route specified in the host list. With strict routing, the next intermediate destination must be reachable directly (and not separated by a router). The maximum number of addresses or names in the host list is 9. The host list is a series of IPv4 addresses separated by spaces.
-
/w timeout - the timeout value adjusts the amount of time, in milliseconds, that the ping waits for each reply. The default timeout value is 4000 or 4 seconds.
-
/r range - tells the ping command to trace the round trip path, for a number of hops. It works only with IPv6 addresses. The range must be a number between 1 and 9.
-
/s srcaddr - specifies the source address to use when working with IPv6 addresses. The address must be entered after srcaddr.
-
/c compartments - specifies the routing compartment identifier.
-
/p - pings a Hyper-V Network Virtualization provider address.
-
/4 - forces the use of the IPv4 address and it is used in conjunction with hostnames, not IP addresses. For example, write "ping /4 www.microsoft.com" (without the quotation marks), and it returns the IPv4 address of the hostname.
-
/6 - forces the use of the IPv6 address and it is used in conjunction with hostnames, not IP addresses. For example, write "ping /6 www.microsoft.com" and you see the IPv6 address of the hostname.
A few examples of working with the ping command:
To make sure that you better understand how to work with the ping command, we will share a few examples and explain how they are used in real life. If you want to monitor a certain website and its availability, you could use "ping -t domainname" without the quotation marks. The command endlessly pings it and shares the time it takes to reply to each Echo request.
However, if you do this kind of endless monitoring of well-managed hosts, your PC could get banned from accessing. Do not forget to stop it by pressing CTRL+C on your keyboard.
You may want to use a finite number of Echo request messages to send, using "ping -n count hostname" like in the example below:
In the screenshot above you can see that the host was initially available and replying to the ping command, and it then went offline, and all the remaining requests timed out.
If you know the IP address of a host, and you want to know the hostname, you can use "ping -a IP address". The ping tries to resolve and display the hostname of the target and then returns it, similar to the screenshot below.
Do you use the ping command, and how?
Now you know what ping is, how it works, what it does, and how to use it in Windows. Before closing this tutorial, comment below and share any questions that you might have. Also, we would like to know how you use the ping command.