每日一linux命令(42)-------ping命令

CentOS: 网络连接故障排除 yum能正常动作,惯性认为是需要替换BaseURL,结果后来才发现是Gateway知什么时候被错误设定了,memo如下。 阅读详情


Linux系统的ping命令是常用的网络命令,它通常用来测试与目标主机的连通性,我们经常会说“ping一下某机器,看是不是开着”、不能打开网页时会说“你先ping网关地址192.168.1.1试试”。它通过发送ICMP ECHO_REQUEST数据包到网络主机(send ICMP ECHO_REQUEST to network hosts),并显示响应情况,这样我们就可以根据它输出的信息来确定目标主机是否可访问(但这不是绝对的)。有些服务器为了防止通过ping探测到,通过防火墙设置了禁止ping或者在内核参数中禁止ping,这样就不能通过ping确定该主机是否还处于开启状态。

linux下的ping和windows下的ping稍有区别,linux下ping不会自动终止,需要按ctrl+c终止或者用参数-c指定要求完成的回应次数

1.命令格式:

ping [参数] [主机名或IP地址]

2.命令功能:

ping命令用于:确定网络和各外部主机的状态跟踪和隔离硬件和软件问题测试、评估和管理网络。如果主机正在运行并连在网上,它就对回送信号进行响应。每个回送信号请求包含一个网际协议(IP)和 ICMP 头,后面紧跟一个 tim 结构,以及来填写这个信息包的足够的字节。缺省情况是连续发送回送信号请求直到接收到中断信号(Ctrl-C)。

ping 命令每秒发送一个数据报并且为每个接收到的响应打印一行输出。ping 命令计算信号往返时间和(信息)包丢失情况的统计信息,并且在完成之后显示一个简要总结。ping 命令在程序超时或当接收到 SIGINT 信号时结束。Host 参数或者是一个有效的主机名或者是因特网地址。

3.命令参数:

-d 使用Socket的SO_DEBUG功能。

-f  极限检测。大量且快速地送网络封包给一台机器,看它的回应。

-n 只输出数值。

-q 不显示任何传送封包的信息,只显示最后的结果。

-r 忽略普通的Routing Table,直接将数据包送到远端主机上。通常是查看本机的网络接口是否有问题。

-R 记录路由过程。

-v 详细显示指令的执行过程。

<p>-c 数目在发送指定数目的包后停止。

-i 秒数设定间隔几秒送一个网络封包给一台机器,预设值是一秒送一次。

-I 网络界面使用指定的网络界面送出数据包。

-l 前置载入设置在送出要求信息之前,先行发出的数据包。

-p 范本样式设置填满数据包的范本样式。

-s 字节数指定发送的数据字节数,预设值是56,加上8字节的ICMP头,一共是64ICMP数据字节。

-t 存活数值设置存活数值TTL的大小。

4.使用实例:

实例1:ping的通的情况

命令:

ping 192.168.120.205

输出:

复制代码
[root@localhost ~] #  ping 192.168.120.205
PING 192.168.120.205 (192.168.120.205) 56(84) bytes of data.
64 bytes from 192.168.120.205: icmp_seq=1 ttl=64 time=0.720 ms
64 bytes from 192.168.120.205: icmp_seq=2 ttl=64 time=0.181 ms
64 bytes from 192.168.120.205: icmp_seq=3 ttl=64 time=0.191 ms
64 bytes from 192.168.120.205: icmp_seq=4 ttl=64 time=0.188 ms
64 bytes from 192.168.120.205: icmp_seq=5 ttl=64 time=0.189 ms

--- 192.168.120.205 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4000ms
rtt min/avg/max/mdev = 0.181/0.293/0.720/0.214 ms
[root@localhost ~] #  
复制代码

说明:

 

实例2:ping不通的情况

命令:

ping 192.168.120.202

输出:

复制代码
[root@localhost ~] #  ping 192.168.120.202
PING 192.168.120.202 (192.168.120.202) 56(84) bytes of data.
From 192.168.120.204 icmp_seq=1 Destination Host Unreachable
From 192.168.120.204 icmp_seq=2 Destination Host Unreachable
From 192.168.120.204 icmp_seq=3 Destination Host Unreachable
From 192.168.120.204 icmp_seq=4 Destination Host Unreachable
From 192.168.120.204 icmp_seq=5 Destination Host Unreachable
From 192.168.120.204 icmp_seq=6 Destination Host Unreachable

--- 192.168.120.202 ping statistics ---
8 packets transmitted, 0 received, +6 errors, 100% packet loss, time 7005ms
, pipe 4
[root@localhost ~] #
复制代码

说明:

 

实例3:ping网关

命令:

ping -b 192.168.120.1

输出:

复制代码
[root@localhost ~] #  route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.120.0   *               255.255.255.0   U     0      0        0 eth0
192.168.0.0     192.168.120.1   255.255.0.0     UG    0      0        0 eth0
10.0.0.0        192.168.120.1   255.0.0.0       UG    0      0        0 eth0
default         192.168.120.240 0.0.0.0         UG    0      0        0 eth0
[root@localhost ~] #  ping -b 192.168.120.1
PING 192.168.120.1 (192.168.120.1) 56(84) bytes of data.
64 bytes from 192.168.120.1: icmp_seq=1 ttl=255 time=2.02 ms
64 bytes from 192.168.120.1: icmp_seq=2 ttl=255 time=1.83 ms
64 bytes from 192.168.120.1: icmp_seq=3 ttl=255 time=1.68 ms
64 bytes from 192.168.120.1: icmp_seq=4 ttl=255 time=1.98 ms
64 bytes from 192.168.120.1: icmp_seq=5 ttl=255 time=1.88 ms

--- 192.168.120.1 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4000ms
rtt min/avg/max/mdev = 1.682/1.880/2.020/0.129 ms
复制代码

说明:

 

实例4:ping指定次数

命令:

ping -c 10 192.168.120.206

输出:

复制代码
[root@localhost ~] #  ping -c 10 192.168.120.206
PING 192.168.120.206 (192.168.120.206) 56(84) bytes of data.
64 bytes from 192.168.120.206: icmp_seq=1 ttl=64 time=1.25 ms
64 bytes from 192.168.120.206: icmp_seq=2 ttl=64 time=0.260 ms
64 bytes from 192.168.120.206: icmp_seq=3 ttl=64 time=0.242 ms
64 bytes from 192.168.120.206: icmp_seq=4 ttl=64 time=0.271 ms
64 bytes from 192.168.120.206: icmp_seq=5 ttl=64 time=0.274 ms
64 bytes from 192.168.120.206: icmp_seq=6 ttl=64 time=0.295 ms
64 bytes from 192.168.120.206: icmp_seq=7 ttl=64 time=0.269 ms
64 bytes from 192.168.120.206: icmp_seq=8 ttl=64 time=0.270 ms
64 bytes from 192.168.120.206: icmp_seq=9 ttl=64 time=0.253 ms
64 bytes from 192.168.120.206: icmp_seq=10 ttl=64 time=0.289 ms

--- 192.168.120.206 ping statistics ---
10 packets transmitted, 10 received, 0% packet loss, time 9000ms
rtt min/avg/max/mdev = 0.242/0.367/1.251/0.295 ms
[root@localhost ~] #  
复制代码

说明:

 

实例5:时间间隔和次数限制的ping

命令:

ping -c 10 -i 0.5 192.168.120.206

输出:

复制代码
[root@localhost ~] #  ping -c 10 -i 0.5 192.168.120.206
PING 192.168.120.206 (192.168.120.206) 56(84) bytes of data.
64 bytes from 192.168.120.206: icmp_seq=1 ttl=64 time=1.24 ms
64 bytes from 192.168.120.206: icmp_seq=2 ttl=64 time=0.235 ms
64 bytes from 192.168.120.206: icmp_seq=3 ttl=64 time=0.244 ms
64 bytes from 192.168.120.206: icmp_seq=4 ttl=64 time=0.300 ms
64 bytes from 192.168.120.206: icmp_seq=5 ttl=64 time=0.255 ms
64 bytes from 192.168.120.206: icmp_seq=6 ttl=64 time=0.264 ms
64 bytes from 192.168.120.206: icmp_seq=7 ttl=64 time=0.263 ms
64 bytes from 192.168.120.206: icmp_seq=8 ttl=64 time=0.331 ms
64 bytes from 192.168.120.206: icmp_seq=9 ttl=64 time=0.247 ms
64 bytes from 192.168.120.206: icmp_seq=10 ttl=64 time=0.244 ms

--- 192.168.120.206 ping statistics ---
10 packets transmitted, 10 received, 0% packet loss, time 4499ms
rtt min/avg/max/mdev = 0.235/0.362/1.241/0.294 ms
[root@localhost ~] #  ping -c 10 -i 0.01 192.168.120.206
PING 192.168.120.206 (192.168.120.206) 56(84) bytes of data.
64 bytes from 192.168.120.206: icmp_seq=1 ttl=64 time=0.244 ms
64 bytes from 192.168.120.206: icmp_seq=2 ttl=64 time=0.195 ms
64 bytes from 192.168.120.206: icmp_seq=3 ttl=64 time=0.219 ms
64 bytes from 192.168.120.206: icmp_seq=4 ttl=64 time=0.204 ms
64 bytes from 192.168.120.206: icmp_seq=5 ttl=64 time=3.56 ms
64 bytes from 192.168.120.206: icmp_seq=6 ttl=64 time=1.93 ms
64 bytes from 192.168.120.206: icmp_seq=7 ttl=64 time=0.193 ms
64 bytes from 192.168.120.206: icmp_seq=8 ttl=64 time=0.193 ms
64 bytes from 192.168.120.206: icmp_seq=9 ttl=64 time=0.202 ms
64 bytes from 192.168.120.206: icmp_seq=10 ttl=64 time=0.211 ms

--- 192.168.120.206 ping statistics ---
10 packets transmitted, 10 received, 0% packet loss, time 90ms
rtt min/avg/max/mdev = 0.193/0.716/3.564/1.080 ms
[root@localhost ~] #  
复制代码

 

说明:

 

实例6:通过域名ping公网上的站点

命令:

ping -c 5 www.58.com

输出:

复制代码
peida-VirtualBox ~  #  ping -c 5 www.58.com
PING www.58.com (211.151.111.30) 56(84) bytes of data.
64 bytes from 211.151.111.30: icmp_req=1 ttl=49 time=14.7 ms
64 bytes from 211.151.111.30: icmp_req=2 ttl=49 time=16.4 ms
64 bytes from 211.151.111.30: icmp_req=3 ttl=49 time=15.2 ms
64 bytes from 211.151.111.30: icmp_req=4 ttl=49 time=14.6 ms
64 bytes from 211.151.111.30: icmp_req=5 ttl=49 time=19.9 ms

--- www.58.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 20101ms
rtt min/avg/max/mdev = 14.618/16.192/19.917/1.965 ms
peida-VirtualBox ~  #  
复制代码

说明:

 

实例7:多参数使用

命令:

ping -i 3 -s 1024 -t 255 192.168.120.206

输出:

复制代码
[root@localhost ~] #  ping -i 3 -s 1024 -t 255 192.168.120.206
PING 192.168.120.206 (192.168.120.206) 1024(1052) bytes of data.
1032 bytes from 192.168.120.206: icmp_seq=1 ttl=64 time=1.99 ms
1032 bytes from 192.168.120.206: icmp_seq=2 ttl=64 time=0.694 ms
1032 bytes from 192.168.120.206: icmp_seq=3 ttl=64 time=0.300 ms
1032 bytes from 192.168.120.206: icmp_seq=4 ttl=64 time=0.481 ms
1032 bytes from 192.168.120.206: icmp_seq=5 ttl=64 time=0.415 ms
1032 bytes from 192.168.120.206: icmp_seq=6 ttl=64 time=0.600 ms
1032 bytes from 192.168.120.206: icmp_seq=7 ttl=64 time=0.411 ms
1032 bytes from 192.168.120.206: icmp_seq=8 ttl=64 time=0.281 ms
1032 bytes from 192.168.120.206: icmp_seq=9 ttl=64 time=0.318 ms
1032 bytes from 192.168.120.206: icmp_seq=10 ttl=64 time=0.362 ms
1032 bytes from 192.168.120.206: icmp_seq=11 ttl=64 time=0.408 ms
1032 bytes from 192.168.120.206: icmp_seq=12 ttl=64 time=0.445 ms
1032 bytes from 192.168.120.206: icmp_seq=13 ttl=64 time=0.397 ms
1032 bytes from 192.168.120.206: icmp_seq=14 ttl=64 time=0.406 ms
1032 bytes from 192.168.120.206: icmp_seq=15 ttl=64 time=0.458 ms

--- 192.168.120.206 ping statistics ---
15 packets transmitted, 15 received, 0% packet loss, time 41999ms
rtt min/avg/max/mdev = 0.281/0.531/1.993/0.404 ms
[root@localhost ~] #  
ROS计划掉线 :for sheng from=1 to=253 do={[/interface pppoe-server remove [/interface pppoe-server find name=""]]} :for sheng from=1 to=253 do={[/interface pppoe-server remove [/interface pppoe-server find name=""... 阅读详情

相关推荐

CentOS 网络连接故障排除_centos 0 received, 100% packet loss

DNS正常设定,表明问题更加基础,应该在于网络完全没有被正确设定。果然8.8.8.8无法ping(img-6ZVo4VeE-1713289196680)]ip addr确认网络状况,状态如下。立即确认出GATEWAY设定有误。自身连接确认没有问题。

2401_84281748的博客 1150

每天linux命令(54):ping命令

Linux系统的ping命令是常用的网络命令,它常用来测试与目标主机的连性,我们经常会说“ping下某机器,看是是开着”、能打开网页时会说“你先ping网关地址192.168.1.1试试”。它过发送ICMP ECHO_REQUEST数据包到网络主机(send ICMP ECHO_REQUEST to network hosts),并显示响应情况,这样我们就可以根据它输出的信息来确定目标...

weixin_34378922的博客 2978

Linux每日智囊

每日分享三个Linux命令,悄悄培养读者的Linux技能。

HJ_blog 382

网络故障分析

故障分析报告 故障现象: PC-1 与 PC-2 无法互相 ping 故障根因定位 SW3 上存在 VLAN 12 故障分析 -故障重现: PC-1 >ping 192.168.20.1 Ping 192.168.20.1: 32 data bytes, Press Ctrl_C to break Request timeout! Request timeout! Request...

juney 2998

每日命令ping

Ping命令网络工具,用于测试两台计算机之间的网络连接。它过向目标计算机发送ICMP(Internet Control Message Protocol)回显请求消息并等待回复来工作。Ping命令的名称源自声纳系统发出的声音来探测物体的原理,因为它的工作方式类似于发送声音并听取回声。

theprogram111的博客 3716

[实验室每日题][20201123][Web]死亡ping命令

原题目:BUUCTF–[第二章 web进阶]死亡ping命令 前置基础(本题会用到的相关命令) liunx命令 ls命令 Linux ls(英文全拼:list files):命令用于显示指定工作目录下之内容(列出目前工作目录所含之文件及子目录)。 转自:菜鸟教程 cat命令 cat(英文全拼:concatenate):命令用于连接文件并打印到标准输出设备上。 转自:菜鸟教程 curl命令 curl(英文全拼:CommandLine Uniform Resource Locator):curl 是常用的命令

m0_50317371的博客 4413

linux host命令超时,Linux中的PING命令每日个小知识。怕学

PING(数据包Internet Groper)命令用于检查主机与服务器/主机之间的网络连接。该命令以IP地址或URL为输入,并过消息“ PING”将数据包发送到指定的地址,并记录下这次从服务器/主机获得的响应,这称为等待时间。快速ping低延迟意味着更快的连接。如果该主机可用,则Ping使用ICMP(Internet控制消息协议)向指定的主机发送ICMP回显消息,然后它发送ICMP答复消息。P...

weixin_34358799的博客 509

Linux命令每日学之Ping

Ping命令是常用的linux命令常用于测试两台机器之间是否网络,其原理是过ICMP报文实现。 注意:linux下的ping和windows下的ping稍有区别,linuxping会自动终止,需要按ctrl+c终止或者用参数-c指定要求完成的回应次数。 命令格式 ping [参数] [主机名/IP] 命令功能ping 命令每秒发送个数据报并且为每个接收到的响应打印行输出。pin

魔幻世界 400

L68.linux命令每日-- 第十章 Linux网络管理命令 -- ping和traceroute

​ **说明:**在traceroute命令及后面的选项里,每个元素直接都至少要有个空格。​ **说明:**在ping命令及后面的选项和目标主机里,每个元素直接都至少要有个空格。​ **范例10-35:**使用ping参数的同组合的例子。​ **范例10-33:**测试到目标主机的网络性。​ **范例10-34:**网络故障时的ping结果。​ **范例10-37:**加快查询时间。​ **范例10-36:**查看某主机的路由状况。​ 命令结果说明具体如下。

Raymond的博客 735

每日linux——网络命令1

ifconfig命令 对照windows下的ipconfig,Linux下的ifconfig用来查看和配置网络设备。当网络环境发生改变时可过此命令网络进行相应的配置。 ifconfig [网络设备] [参数] 命令参数 up 启动指定网络设备/网卡。 down 关闭指定网络设备/网卡。该参数可以有效地阻止过指定接口的IP信息流,如果想永久地关闭个接口,我们还需要从核心路由表中将该接口的路由信息全部删除。 arp 设置指定网卡是否支持ARP协议。 -promisc 设置是否支持网卡的promiscu

qq_40986693的博客 156

linux命令每日

linux命令 1、netstat -lntp #查看监听的端口,监听状态可以理解为端口是否激活,可用状态 2、curl -i -X POST url #在Linux系统下可以用curl和wget命令来模拟Http的请求 #我们可以使用 cURL 来完成这 POST 请求,-d 用于指定发送的数据,-X 用于指定发送数据的方式 curl -d “us...

大白的博客 470

linux ping 端口_教你排除linux网络故障问题

php中文网课程每日17点准时技术干货分享本文为php中文网认证作者:“齐天大圣”投稿。如果公司网站打开了,假如是因为网络问题,你该如何去进行排查。又比如,远程连接工具连上服务器或mysql数据库连上,会会是因为网络问题。日常工作或学习中,我们经常会遇到各种各样的网络问题(因为计算机网络实在太复杂了)。现在我们来看看,如果linux服务器出现了网络问题,该如何去排查。ping首先...

weixin_39760919的博客 700

[每日学] Ping测试脚本

ping为常用网络命令,但要测试整个集群的连性,手动测试过于麻烦,我们借助bash中的list与for循环来实现集群连性测试。下面是测试10.63.117.5~7 和 10.63.13.3~100次性测试连性。

qq_46343124的博客 236

Linux每日练第2天 | Linux 基础命令学习心得

这里写自定义目录标题第二天:Linux 基础命令学习收获课后作业相关链接 第二天:Linux 基础命令 学习收获 今天学习《每日练:三天入门Linux系统》第二天课程:Linux基础命令,大部分命令都用过,相对比较简单,经过分类之后更清晰些,有几个命令太常用,特别操作练习了,加深印象~ 课后作业 1.用户、文件操作 useradd test su - test mkdir -p test/dir1 cd test/dir1 touch testfile.txt echo "Today is Frid

tjslp2的博客 1252

Linux禁止ping以及开启ping的方法

点击上方 "程序员小乐"关注,星标或置顶起成长每天凌晨0000分,第时间与你相约每日英文You can't just sit there and wai...

程序员小乐 1551

shell脚本-每日-记录ping的结果

要求:使用ping命令,后台执行,每ping100次记录ping的结果 后台运行进程指令:nohup ping -c 100 www.baidu.com > ping-log  2 > &1  & nohup:将进程放到后台执行 ping -c 100 :表示ping 100次之后结束ping >ping-log  :将输出重定向到ping-log中,>是以覆盖的方式放入文件,

qq_31318535的博客 3364

14.每日Linux命令----tail

描述:用于显示指定文件末尾内容,指定文件时,作为输入信息进行处理。常用查看日志文件。 用法:tail [option] file 常用参数: -f循环读取 -c<数目>显示的字节数 -n<行数>显示行数 --pid=PID与-f合用,表示在进程ID...

chouzhaoming3021的博客 123
上一篇: 每日一linux命令(41)-------route命令
下一篇: 每日一linux命令(43)-------traceroute命令
你所有承诺
博客等级 码龄14年 538粉丝 306原创
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值