ping
---------------
Linux系统的ping命令是常用的网络命令,用来测试与目标主机的连通性。通过
发送ICMP echo_request数据包到网络主机,并显示响应情况,这样就可以根据它
输出的信息来确定目标主机是否可以访问。
语法
ping (选项)(参数)
选项 -b:允许发送广播地址 -d:使用scoket的SO_DEBUG功能; -c:设置完成要求回应的次数 -f:极限检测,大量且快速地发送网络封包给一台机器,主机回应 -n:只输出数值 -q:不显示任何传送封包的信息,只显示最后的结果 -r:忽略普通的Routing Table,直接将数据包送到远端主机上.通常是查看 主机的网络接口是否有问题 -R:记录路由的过程 -v:详细显示指令的执行过程 -i:设定间隔几秒送一个网络封包给一台机器,预设值是一秒送一次 -c 数目:在发送指定数目的包后停止 -s 字节数:指定发送的数据字节数,默认值是56,加上8个字节的ICMP头,一共是64字节的ICMP数据字节
使用案例:
1.案例一:ping的通的情况
命令:ping 10.157.5.21
输出:
ping@ping:~/Desktop$ ping 10.157.16.16
PING 10.157.16.16 (10.157.16.16) 56(84) bytes of data.
64 bytes from 10.157.16.16: icmp_seq=1 ttl=200 time=53.2 ms
64 bytes from 10.157.16.16: icmp_seq=2 ttl=200 time=5.60 ms
64 bytes from 10.157.16.16: icmp_seq=3 ttl=200 time=5.78 ms
64 bytes from 10.157.16.16: icmp_seq=4 ttl=200 time=6.03 ms
--- 10.157.16.16 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 5.600/17.653/53.200/20.523 ms
2.案例二:ping网关
命令:ping -b 10.157.5.21
输出:
ping@ping:~/Desktop$ route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default 10.157.16.126 0.0.0.0 UG 600 0 0 wlp4s0 10.157.16.0 0.0.0.0 255.255.255.128 U 600 0 0 wlp4s0 192.168.4.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr2 192.168.100.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr1 192.168.110.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr3 192.168.120.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr4 ping@ping:~/Desktop$ ping -b 10.157.16.126 PING 10.157.16.126 (10.157.16.126) 56(84) bytes of data. 64 bytes from 10.157.16.126: icmp_seq=1 ttl=255 time=29.4 ms 64 bytes from 10.157.16.126: icmp_seq=2 ttl=255 time=49.9 ms 64 bytes from 10.157.16.126: icmp_seq=3 ttl=255 time=27.5 ms ^C --- 10.157.16.126 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms rtt min/avg/max/mdev = 27.500/35.648/49.979/10.165 ms
3.案例三:ping 指定次数
命令:ping -c 2 10.157.16.126
输出:
ping@ping:~/Desktop$ ping -c 2 10.157.16.126
PING 10.157.16.126 (10.157.16.126) 56(84) bytes of data.
64 bytes from 10.157.16.126: icmp_seq=1 ttl=255 time=24.8 ms
64 bytes from 10.157.16.126: icmp_seq=2 ttl=255 time=98.9 ms
--- 10.157.16.126 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 24.821/61.908/98.995/37.087 ms
4.案例四:ping 指定发送包大小
命令:ping -s 1500 10.157.16.126
输出:
ping@ping:~/Desktop$ ping -s 1500 10.157.16.16
PING 10.157.16.16 (10.157.16.16) 1500(1528) bytes of data.
1508 bytes from 10.157.16.16: icmp_seq=1 ttl=200 time=192 ms
1508 bytes from 10.157.16.16: icmp_seq=3 ttl=200 time=1043 ms
^C
--- 10.157.16.16 ping statistics ---
4 packets transmitted, 2 received, 50% packet loss, time 3043ms
rtt min/avg/max/mdev = 192.783/618.148/1043.514/425.366
5.案例五:ping 指定0.5秒时间发送ICMP包
命令:ping -i 0.5 10.157.16.126
输出:
ping@ping:~/Desktop$ ping -i 0.5 10.157.16.126
PING 10.157.16.126 (10.157.16.126) 56(84) bytes of data.
64 bytes from 10.157.16.126: icmp_seq=1 ttl=255 time=51.2 ms
64 bytes from 10.157.16.126: icmp_seq=2 ttl=255 time=32.4 ms
^C
--- 10.157.16.126 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 500ms
rtt min/avg/max/mdev = 32.456/41.852/51.248/9.396 ms