linux基本命令示例_带有示例Linux ping命令教程

linux基本命令示例

linux基本命令示例

Ping is one of the most used tool for network diagnostics. When internet is not working, can not access file shares etc we will firstly ping command. Ping is one of the most known tool in the IT area. Ping actually uses ICMP packets to get information about network status. In this tutorial we will look practical use cases of Ping tool.

Ping是最常用的网络诊断工具之一。 当互联网无法正常工作,无法访问文件共享等时,我们将首先ping命令。 Ping是IT领域中最知名的工具之一。 Ping实际上使用ICMP数据包来获取有关网络状态的信息。 在本教程中,我们将介绍Ping工具的实际用例。

句法 (Syntax)

Syntax of ping command for Linux is like below.

Linux的ping命令的语法如下。

$ ping [options] [hop1...] destination

帮帮我 (Help)

$ ping -h
Help
Help
帮帮我

ICMP(ICMP)

ICMP is a network protocol mainly used by ping command. ICMP have different type of messages to exchange network, host, router, switch information. Ping command uses ICMP Request which is numbered 8 and ICMP Reply which is numbered 0.

ICMP是主要由ping命令使用的网络协议。 ICMP具有不同类型的消息以交换网络,主机,路由器,交换机信息。 Ping命令使用编号为8的ICMP Request和编号为0的ICMP Reply

(Ping)

We will just ping with default settings for ping command. By default ping will work infinitely. We can stop ping command with processes cancel keyboard shortcut CTRL+c .

我们将使用ping命令的默认设置来ping。 默认情况下,ping将无限工作。 我们可以通过进程取消键盘快捷键CTRL+c来停止ping命令。

$ ping poftut.com
Ping
Ping

After stopping ping command there will be some statistics about ping command. There will be following information

停止ping命令后,将有一些有关ping命令的统计信息。 将有以下信息

  • Packet transmitted shows the count of total packet sent

    Packet transmittedPacket transmitted显示已Packet transmitted的总数据包数

  • Received show total count of packets received

    Received显示已接收的数据包总数

  • Packet loss show the percentage of lost or not responded packages

    Packet loss显示丢失或未响应的软件包的百分比

  • Time shows how long the ping command worked.

    Time显示ping命令的工作时间。

  • Rtt min show minimum round trip time which is how long take a ICMP request and response

    Rtt min显示最小往返时间,这是ICMP请求和响应所花费的时间

  • Rtt avg shows average round trip time

    Rtt avg显示平均往返时间

  • Rtt max shows maximum round trip time

    Rtt max显示最大往返时间

增加间隔(Increase Interval)

By default ping command uses 1 second intervals. Interval is the time between two ping or ICMP request. This amount can be changed with -i option

缺省情况下,ping命令使用1秒间隔。 间隔是两次ping或ICMP请求之间的时间。 可以使用-i选项更改此金额

$ ping -i 2 poftut.com
Increase Interval
Increase Interval
增加间隔

减少间隔(Decrease Interval)

In previous example we have increased the interval. We can also set lower interval for ping requests. But there is a minor difference. To set interval lower than 0.2 we need root privileges. In this example we will set interval as 0.5 second.

在前面的示例中,我们增加了间隔。 我们还可以为ping请求设置较低的间隔。 但是有微小的区别。 要将间隔设置为小于0.2,我们需要root特权。 在此示例中,我们将间隔设置为0.5秒。

$ ping -i 0.5 poftut.com
Decrease Interval
Decrease Interval
减少间隔

检查本地接口状态(Check Local Interface Status)

Ping have some diagnostic feature. We can check the status of the local network interface with  destination address

Ping具有一些诊断功能。 我们可以使用目标地址检查本地网络接口的状态

$ ping  0
Check Local Interface Status
Check Local Interface Status
检查本地接口状态

设置数据包计数(Set Packet Count)

As we stated before ping command will work endlessly if there is no interrupt for ping. Providing this interrupt can be difficult job if we use ping as a batch script. We may need to run ping some little time and use the output. In this situations we can set the packet count. Ping will only send specified count. In this example we will send only 3 ping or ICMP requests to the destination.

如前所述,如果没有ping中断,ping命令将无休止地工作。 如果我们使用ping作为批处理脚本,则提供此中断可能很困难。 我们可能需要运行一些时间并使用输出。 在这种情况下,我们可以设置数据包计数。 Ping将仅发送指定的计数。 在此示例中,我们将仅向目的地发送3个ping或ICMP请求。

$ ping -c 3 poftut.com
Set Packet Count
Set Packet Count
设置数据包计数

声音平(Audible Ping)

There are some alert mechanism in the ping command. Ping command can provided some voice alert if some change occur. This change can be the destination host is down or up. But keep in mind that this may not work in some terminals.

ping命令中有一些警报机制。 如果发生某些更改,Ping命令可以提供一些语音警报。 此更改可以是目标主机关闭还是启动。 但是请记住,这可能不适用于某些终端。

$ ping -a poftut.com
Audible Ping
Audible Ping
声音平

查找IP地址(Find IP Address)

The IP address will be printed in the first line of ping output if we specify the destination with its host name.

如果我们使用主机名指定目标,则将在ping输出的第一行中显示IP地址。

$ ping  poftut.com
Find IP Address
Find IP Address
查找IP地址

In this example host name is poftut.com and related IP address is 45.79.133.118

在此示例中,主机名是poftut.com ,相关的IP地址是45.79.133.118

更改Ping数据包大小 (Change Ping Packet Size)

Ping command uses ICMP packets and puts some meaningless data in the ICMP packet. This data size is 56 byte by default. This data size can be changed with -s parameter. In this example we will set the data size for ICMP packet 200.

Ping命令使用ICMP数据包,并将一些无意义的数据放入ICMP数据包。 默认情况下,此数据大小为56字节。 可以使用-s参数更改此数据大小。 在此示例中,我们将设置ICMP数据包200的数据大小。

$ ping -s 200  poftut.com
Change Ping Packet Size
Change Ping Packet Size
更改Ping数据包大小

设置生存时间或TTL(Set Time To Live or TTL)

IP packets have Time To Live count. This TTL will set how much hop the packet can transmitted. By using -t option TTL value can be set. In this example we will set TTL as 22 which is by default 52.

IP数据包具有生存时间计数。 该TTL将设置数据包可以传输多少跳。 通过使用-t选项,可以设置TTL值。 在此示例中,我们将TTL设置为22,默认情况下为52。

$ ping -t 22  poftut.com
Set Timeout or Time To Live
Set Timeout or Time To Live
设置超时或生存时间

设置超时(Set Timeout)

While sending ICMP request packets we wait for some amount of time for the ICMP response. This waiting time can be change with -w option. After the timeout value the ping command will exit. In this example we will set timeout value as 2 seconds.

发送ICMP请求数据包时,我们需要等待一段时间才能获得ICMP响应。 可以使用-w选项更改此等待时间。 在超时值之后,ping命令将退出。 在此示例中,我们将超时值设置为2秒。

$ ping -w 2  poftut.com
Set Timeout
Set Timeout
设置超时

设置Ping的路线或路径(Set Route or Path For Ping)

The ICMP packets send by ping command will be routed according to the default routes in the network. Sometimes this default routes will not enough for the test case. In this situations the route information can be provided to the ping command by adding them before the destination. In this example we will set 192.168.122.1 route byte hand. We want to ping destination poftut.com

ping命令发送的ICMP数据包将根据网络中的默认路由进行路由。 有时,这种默认路由对于测试用例而言还不够。 在这种情况下,可以通过在目的地之前添加路由信息来将其提供给ping命令。 在此示例中,我们将设置192.168.122.1路由字节指针。 我们要ping通目的地poftut.com

$ ping 192.168.122.239 192.168.122.1  poftut.com

But keep in mind that the network devices should be supported host provided routing. This can be a security implication and disabled in the network devices.

但是请记住,网络设备应支持主机提供的路由。 这可能是安全隐患,并且在网络设备中已禁用。

LEARN MORE  How To Download and Install Kali Security and Penetration Test Linux Distribution?
了解更多信息如何下载和安装Kali Security and Penetration Test Linux发行版?

在线Ping工具 (Online Ping Tool)

There are some online ping tools which provided the scale ability to select source host.

有一些在线ping工具提供了选择源主机的扩展能力。

https://asm.ca.com/en/ping.php

https://asm.ca.com/en/ping.php

泛洪ICMP数据包 (Flood ICMP Packets)

Flood is a term used to specify uncontrolled high level network traffic. Ping command can flood ICMP requests to the destination with -f option. This will generate mass ICMP requests without setting any interval or count. In order to flood we need root privileges.

泛洪是用于指定不受控制的高级网络流量的术语。 Ping命令可以使用-f选项将ICMP请求泛洪到目标。 这将生成大量ICMP请求,而无需设置任何间隔或计数。 为了泛滥,我们需要root特权。

$ ping -f poftut.com
Flood
Flood
洪水

As we can see from example there is no verbose information about the ICMP requests. There will be only a summary about the ping command.

从示例中可以看出,没有关于ICMP请求的详细信息。 只会有关于ping命令的摘要。

显示版本 (Show Version)

Ping command version information can be printed with -v parameter like below.

可以使用-v参数打印ping命令的版本信息,如下所示。

$ ping -V
Show Version
Show Version
显示版本

As we can see that ping utility is provided by iputils package which version is s20150815

我们可以看到iputils包提供了ping实用程序,其版本为s20150815

翻译自: https://www.poftut.com/linux-ping-command-tutorial-examples/

linux基本命令示例

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值