linux ping 命令_Linux ping命令示例

linux ping 命令

The ping (Packet INternet Groper) command is one of the most widely used utility across different Operating systems: from Windows to Linux.

ping(Packet INternet Groper)命令是跨不同操作系统(从Windows到Linux)的最广泛使用的实用程序之一。

It’s a network troubleshooting tool used for testing reachability of remote systems, servers, and network devices.

这是一个网络故障排除工具,用于测试远程系统,服务器和网络设备的可达性。

It achieves this by sending an ICMP echo request to a remote system. The ICMP packet requests are received and relayed back to the source indicating that the host is up.

它通过将ICMP回显请求发送到远程系统来实现此目的。 收到ICMP数据包请求并将其中继回源,指示主机已启动。

In this guide, we will look at how it is used and the various options that can be passed to achieve different results.

在本指南中,我们将研究如何使用它以及可以传递以实现不同结果的各种选项。

Linux ping命令语法 (Linux ping Command Syntax)

The syntax of the Linux ping command is quite simple and straight forward.

Linux ping命令的语法非常简单明了。

ping [option] [hostname or IP address]

使用ping命令获取主机的IP地址 (Using the ping command to get the IP address of a host)

We can use the ping command to find out the IP address of a website. The ping command output prints the IP address of the host.

我们可以使用ping命令找出网站的IP地址。 ping命令输出显示主机的IP地址。

$ ping journaldev.com
PING journaldev.com (45.33.45.237): 56 data bytes
64 bytes from 45.33.45.237: icmp_seq=0 ttl=56 time=59.133 ms
64 bytes from 45.33.45.237: icmp_seq=1 ttl=56 time=43.917 ms

使用ping命令测试系统的连通性或可达性 (Using the ping command to test connectivity or reachability of a system)

The most basic usage of ping command involves sending a ping request to a website address or hostname as shown.

ping命令最基本的用法包括将ping请求发送到网站地址或主机名,如图所示。

ping google.com

Sample output

样品输出

Alternatively, you can ping a server by specifying its IP address as shown.

或者,您可以通过指定服务器的IP地址来对其进行ping操作,如图所示。

ping 173.82.2.236

Sample output

样品输出

It’s important to note that in the above examples, the ping command will continue sending ping requests until you press CRTL + C.

请务必注意,在以上示例中,ping命令将继续发送ping请求,直到您按CRTL + C为止。

Ping command uses DNS resolver to find out the IP address of the host and then sends the ping request. If the hostname is invalid, it will return “Unknown host” error.

Ping命令使用DNS解析器找出主机的IP地址,然后发送ping请求。 如果主机名无效,它将返回“ Unknown host ”错误。

$ ping google
ping: cannot resolve google: Unknown host
$ ping sasadsasdd.com
ping: cannot resolve sasadsasdd.com: Unknown host
$

指定ping请求之间的时间间隔 (Specify time interval between ping requests)

There’s a 1-second gap between ping requests by default. If you want to modify this and specify a higher value, use the -i argument followed by the time interval as shown.

默认情况下,ping请求之间有1秒的间隔。 如果要修改此参数并指定更高的值,请使用-i参数,后跟时间间隔,如图所示。

ping -i 3 google.com

Sample output

样品输出

In the example above the time interval between ping packets is 3 seconds.

在上面的示例中,ping数据包之间的时间间隔为3秒。

修改ping数据包大小 (Modify the ping packet size)

The number of bytes contained in a ping request is 56 by default ( 64 bytes if you include the ping header). You can, however, alter this value to your preference by using the -s option followed by the value. To change the value to 80, execute the command.

默认情况下,ping请求中包含的字节数为56(如果包含ping标头,则为64字节)。 但是,您可以使用-s选项后跟该值,以根据自己的喜好更改此值。 要将值更改为80,请执行命令。

ping -s 80 google.com

Sample output

样品输出

指定发送ping数据包大小的时间 (Specify number of time to send the ping packet size)

As you have observed in previous examples, you need to hit CTRL + C to interrupt the sending of ping packets. To avoid this inconvenience, you can specify the number of packets to be sent using the -c flag. For instance, to send 5 ping packets, run the below command.

正如您在前面的示例中观察到的那样,您需要按CTRL + C来中断ping数据包的发送。 为了避免这种不便,您可以使用-c标志指定要发送的数据包数量。 例如,要发送5个ping数据包,请运行以下命令。

ping -c 5 google.com

Sample output

样品输出

The above command sends 5 ping packets to the target and finally stops.

上面的命令将5个ping数据包发送到目标,最后停止。

充斥目标系统 (Flood a target system)

Yes, You are probably skeptical about this, but ping command can also be used to flood a target. You can achieve this using the -f command.

是的,您可能对此表示怀疑,但是ping命令也可以用于充斥目标。 您可以使用-f命令来实现。

ping -f jaykiarie.com

Sample output

样品输出

DISCLAIMER: Caution should be taken as flooding a target system with ping requests can lead to a DOS attack which can degrade a system’s reachability or connectivity.

免责声明 :应谨慎使用ping请求充斥目标系统,这可能导致DOS攻击,这可能会降低系统的可达性或连接性。

打印ping请求的时间戳 (Print timestamp of ping requests)

If you wish, you can print the timestamp during which the ping packets are sent. This is achieved using the -D option. The timestamp is a combination of Unix time and microseconds.

如果需要,您可以打印发送ping数据包的时间戳。 这是使用-D选项实现的。 时间戳是Unix时间和微秒的组合。

Sample output

Print Timestamp In Ping

样品输出

结论 (Conclusion)

As we have seen, ping is a very useful command for network troubleshooting and helps System administrators and regular users to diagnose network problems involving connectivity between systems. You can run “man ping” command to check out all the options ping command provides.

如我们所见,ping是用于网络故障排除的非常有用的命令,可帮助系统管理员和常规用户诊断涉及系统之间连接的网络问题。 您可以运行“ man ping”命令来检查ping命令提供的所有选项。

翻译自: https://www.journaldev.com/30949/linux-ping-command-examples

linux ping 命令

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值