我使用过的Linux命令之ping - 测试与目标主机的连通性
我使用过的Linux命令之ping - 测试与目标主机的连通性
本文链接:http://codingstandards.iteye.com/blog/1125766 ? (转载请注明出处)
用途说明ping命令是常用的网络命令,它通常用来测试与目标主机的连通性,我们经常会说“ping一下某机器,看是不是开着”、不能打开网页时会说“你先ping网关地址192.168.1.1试试”。它通过发送ICMP ECHO_REQUEST数据包到网络主机(send ICMP ECHO_REQUEST to network hosts),并显示响应情况,这样我们就可以根据它输出的信息来确定目标主机是否可访问(但这不是绝对的)。有些服务器为了防止通过ping探测到,通过防火墙设置了禁止ping或者在内核参数中禁止ping,这样就不能通过ping确定该主机是否还处于开启状态。
??????????????? echo "$site is UP"?
示例九 ping一下公网上的主机在不能上网的时候,可以通过ping公网主机来确定能否上网。可以确定域名是否能解析,远程主机是否可访问等。
?
[root@jfht ~]# ping -c 4 en.wikipedia.org
PING text.pmtpa.wikimedia.org (208.80.152.2) 56(84) bytes of data.
64 bytes from rr.pmtpa.wikimedia.org (208.80.152.2): icmp_seq=1 ttl=43 time=258 ms
64 bytes from rr.pmtpa.wikimedia.org (208.80.152.2): icmp_seq=2 ttl=43 time=265 ms
64 bytes from rr.pmtpa.wikimedia.org (208.80.152.2): icmp_seq=3 ttl=43 time=266 ms
64 bytes from rr.pmtpa.wikimedia.org (208.80.152.2): icmp_seq=4 ttl=43 time=264 ms
--- text.pmtpa.wikimedia.org ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2998ms
rtt min/avg/max/mdev = 258.492/263.998/266.927/3.315 ms
[root@jfht ~]# ping -c 4 zh.wikipedia.org
PING text.pmtpa.wikimedia.org (208.80.152.2) 56(84) bytes of data.
64 bytes from rr.pmtpa.wikimedia.org (208.80.152.2): icmp_seq=1 ttl=43 time=258 ms
64 bytes from rr.pmtpa.wikimedia.org (208.80.152.2): icmp_seq=2 ttl=43 time=258 ms
64 bytes from rr.pmtpa.wikimedia.org (208.80.152.2): icmp_seq=3 ttl=43 time=259 ms
64 bytes from rr.pmtpa.wikimedia.org (208.80.152.2): icmp_seq=4 ttl=43 time=257 ms
--- text.pmtpa.wikimedia.org ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3000ms
rtt min/avg/max/mdev = 257.679/258.435/259.326/0.590 ms
[root@jfht ~]# ping -c 4 www.google.com
PING www.l.google.com (74.125.71.147) 56(84) bytes of data.
64 bytes from hx-in-f147.1e100.net (74.125.71.147): icmp_seq=1 ttl=48 time=74.6 ms
64 bytes from hx-in-f147.1e100.net (74.125.71.147): icmp_seq=2 ttl=48 time=74.4 ms
64 bytes from hx-in-f147.1e100.net (74.125.71.147): icmp_seq=3 ttl=48 time=74.3 ms
64 bytes from hx-in-f147.1e100.net (74.125.71.147): icmp_seq=4 ttl=48 time=77.4 ms
--- www.l.google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3003ms
rtt min/avg/max/mdev = 74.358/75.236/77.467/1.335 ms
[root@jfht ~]# ping -c 4 www.google.com.hk
PING www-hk.l.google.com (74.125.71.99) 56(84) bytes of data.
64 bytes from hx-in-f99.1e100.net (74.125.71.99): icmp_seq=1 ttl=48 time=74.5 ms
64 bytes from hx-in-f99.1e100.net (74.125.71.99): icmp_seq=2 ttl=48 time=74.3 ms
64 bytes from hx-in-f99.1e100.net (74.125.71.99): icmp_seq=3 ttl=48 time=74.7 ms
64 bytes from hx-in-f99.1e100.net (74.125.71.99): icmp_seq=4 ttl=48 time=74.9 ms
--- www-hk.l.google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3002ms
rtt min/avg/max/mdev = 74.366/74.657/74.987/0.411 ms
[root@jfht ~]# ping -c 4 www.g.cn
PING www.g.cn (203.208.46.144) 56(84) bytes of data.
64 bytes from 203.208.46.144: icmp_seq=1 ttl=50 time=109 ms
64 bytes from 203.208.46.144: icmp_seq=2 ttl=50 time=110 ms
64 bytes from 203.208.46.144: icmp_seq=3 ttl=50 time=95.5 ms
64 bytes from 203.208.46.144: icmp_seq=4 ttl=50 time=114 ms
--- www.g.cn ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 95.566/107.616/114.506/7.195 ms
[root@jfht ~]#
?
问题思考相关资料【1】中国IT实验室 Linux和Windows下ping命令详解
http://linux.chinaitlab.com/command/829332.html
【2】网络小筑 根据TTL值判断操作系统类型(转)
http://webtrados.llh4.com/post/375.html
【3】Blinux linux ping 测试本机和目标主机连通性
http://codingstandards.iteye.com/admin/blogs/new
【4】维基百科,自由的百科全书 ping
http://zh.wikipedia.org/wiki/Ping
【5】ping的原作者Mike的个人网站 The Story of the PING Program
http://ftp.arl.mil/~mike/ping.html
【6】xuelanghu.cublog.cn linux中c语言实现的ping程序
http://blogold.chinaunix.net/u2/62117/showart_1756522.html
【7】鸟哥的Linux私房菜 兩部主機兩點溝通: ping
http://linux.vbird.org/linux_server/0140networkcommand.php#ping
?
?
返回 我使用过的Linux命令系列总目录
?