知识的领域是无限的,我们的学习也是无限期的。这篇文章主要讲述Linux之ping命令相关的知识,希望能为你提供帮助。
命令格式
ping [参数] [主机名或IP地址]
命令功能
命令参数
- -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的大小。
>
ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: icmp_seq=0 ttl=106 time=255.389 ms
64 bytes from 8.8.8.8: icmp_seq=1 ttl=106 time=253.781 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=106 time=258.403 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=106 time=255.721 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=106 time=255.086 ms
64 bytes from 8.8.8.8: icmp_seq=5 ttl=106 time=255.165 ms
64 bytes from 8.8.8.8: icmp_seq=6 ttl=106 time=253.948 ms
...
ping不通的情况
>
ping 8.8.9.9
PING 8.8.9.9 (8.8.9.9): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
Request timeout for icmp_seq 3
Request timeout for icmp_seq 4
Request timeout for icmp_seq 5
Request timeout for icmp_seq 6
...
ping指定次数
>
ping -c 10 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: icmp_seq=0 ttl=106 time=256.369 ms
64 bytes from 8.8.8.8: icmp_seq=1 ttl=106 time=255.471 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=106 time=255.381 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=106 time=255.038 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=106 time=260.055 ms
64 bytes from 8.8.8.8: icmp_seq=5 ttl=106 time=255.733 ms
64 bytes from 8.8.8.8: icmp_seq=6 ttl=106 time=254.986 ms
64 bytes from 8.8.8.8: icmp_seq=7 ttl=106 time=254.084 ms
64 bytes from 8.8.8.8: icmp_seq=8 ttl=106 time=255.902 ms
64 bytes from 8.8.8.8: icmp_seq=9 ttl=106 time=256.121 ms--- 8.8.8.8 ping statistics ---
10 packets transmitted, 10 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 254.084/255.914/260.055/1.513 ms
时间间隔和次数限制的ping
>
ping -c 10 -i 0.5 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: icmp_seq=0 ttl=106 time=255.032 ms
64 bytes from 8.8.8.8: icmp_seq=1 ttl=106 time=256.937 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=106 time=255.129 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=106 time=256.560 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=106 time=264.229 ms
64 bytes from 8.8.8.8: icmp_seq=5 ttl=106 time=254.791 ms
64 bytes from 8.8.8.8: icmp_seq=6 ttl=106 time=254.212 ms
64 bytes from 8.8.8.8: icmp_seq=7 ttl=106 time=254.998 ms
64 bytes from 8.8.8.8: icmp_seq=8 ttl=106 time=255.029 ms
64 bytes from 8.8.8.8: icmp_seq=9 ttl=106 time=255.559 ms--- 8.8.8.8 ping statistics ---
10 packets transmitted, 10 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 254.212/256.248/264.229/2.771 ms
通过域名ping域名
>
ping -c 5 json.im
PING json.im (150.109.147.28): 56 data bytes
64 bytes from 150.109.147.28: icmp_seq=0 ttl=48 time=28.733 ms
64 bytes from 150.109.147.28: icmp_seq=1 ttl=48 time=28.412 ms
64 bytes from 150.109.147.28: icmp_seq=2 ttl=48 time=28.012 ms
64 bytes from 150.109.147.28: icmp_seq=3 ttl=48 time=31.498 ms
64 bytes from 150.109.147.28: icmp_seq=4 ttl=48 time=30.518 ms--- json.im ping statistics ---
5 packets transmitted, 5 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 28.012/29.435/31.498/1.341 ms
多参数使用
>
ping -i 1 -s 1024 -t 123 json.im
PING json.im (150.109.147.28): 1024 data bytes
1032 bytes from 150.109.147.28: icmp_seq=0 ttl=48 time=29.613 ms
1032 bytes from 150.109.147.28: icmp_seq=1 ttl=48 time=28.530 ms
1032 bytes from 150.109.147.28: icmp_seq=2 ttl=48 time=32.768 ms
1032 bytes from 150.109.147.28: icmp_seq=3 ttl=48 time=29.014 ms
1032 bytes from 150.109.147.28: icmp_seq=4 ttl=48 time=30.239 ms
1032 bytes from 150.109.147.28: icmp_seq=5 ttl=48 time=27.815 ms
1032 bytes from 150.109.147.28: icmp_seq=6 ttl=48 time=31.311 ms
1032 bytes from 150.109.147.28: icmp_seq=7 ttl=48 time=34.554 ms
1032 bytes from 150.109.147.28: icmp_seq=8 ttl=48 time=41.600 ms
1032 bytes from 150.109.147.28: icmp_seq=9 ttl=48 time=29.513 ms
1032 bytes from 150.109.147.28: icmp_seq=10 ttl=48 time=28.320 ms
1032 bytes from 150.109.147.28: icmp_seq=11 ttl=48 time=29.449 ms
1032 bytes from 150.109.147.28: icmp_seq=12 ttl=48 time=29.127 ms
1032 bytes from 150.109.147.28: icmp_seq=13 ttl=48 time=28.583 ms
1032 bytes from 150.109.147.28: icmp_seq=14 ttl=48 time=28.064 ms
指定源接口(网卡)
>
ping -I eth0 8.8.8.8
PING 8.8.8.8 (8.8.8.8) from 192.168.0.3 eth0: 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=2 ttl=109 time=201 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=109 time=201 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=109 time=200 ms
64 bytes from 8.8.8.8: icmp_seq=5 ttl=109 time=201 ms
64 bytes from 8.8.8.8: icmp_seq=6 ttl=109 time=201 ms
64 bytes from 8.8.8.8: icmp_seq=7 ttl=109 time=201 ms
64 bytes from 8.8.8.8: icmp_seq=9 ttl=109 time=201 ms
64 bytes from 8.8.8.8: icmp_seq=10 ttl=109 time=201 ms
...
指定Internet协议
ping -4 DESTINATION
ping -6 DESTINATION
>
ping -4 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=2 ttl=109 time=200 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=109 time=201 ms
64 bytes from 8.8.8.8: icmp_seq=5 ttl=109 time=200 ms
64 bytes from 8.8.8.8: icmp_seq=6 ttl=109 time=200 ms
64 bytes from 8.8.8.8: icmp_seq=8 ttl=109 time=201 ms
64 bytes from 8.8.8.8: icmp_seq=13 ttl=109 time=200 ms
64 bytes from 8.8.8.8: icmp_seq=16 ttl=109 time=201 ms
64 bytes from 8.8.8.8: icmp_seq=17 ttl=109 time=200 ms
64 bytes from 8.8.8.8: icmp_seq=19 ttl=109 time=200 ms
64 bytes from 8.8.8.8: icmp_seq=21 ttl=109 time=201 ms
...
原文链接:https://rumenz.com/rumenbiji/linux-ping.html
微信公众号:入门小站
【Linux之ping命令】
文章图片
推荐阅读
- Mongodb 数据库的简单使用
- 为什么在数据驱动的路上,AB 实验值得信赖()
- #yyds干货盘点# Kubernetes 搞定网络原来可以如此简单((25))
- (准备工作)
- 2小时速学大数据编程语言 Scala 秘籍
- MySQL临时文件案例--binlog cache临时文件
- 自编码器
- SpringBoot整合Redis实现简单的Pub/Sub(发布/订阅)
- Ubuntu系统上双节点部署OpenStack