linux ping命令学习

ping命令用来测试与目标主机的连通性,它通过发送ICMP ECHO_REQUEST数据包到目标主机,
并显示响应情况,以确定目标主机是否可访问。


通常我们使用ping命令进行基本的网络问题确认。
关于linux网络相关问题的基本排查方法,请参考下面博文:
http://blog.csdn.net/boyxulin1986/article/details/11526751

关于ping命令的参数使用,就不多说了,有需要的话自行学习。
sh-# ifconfig
eth0 Link encap:Ethernet HWaddr 00:00:00:00:FF:95
inet addr:192.168.102.68 Bcast:192.168.102.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:5585 errors:0 dropped:144 overruns:0 frame:0
TX packets:3549 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6410537 (6.1 Mb) TX bytes:270902 (264.5 Kb)
Interrupt:40 Base address:0x2000

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:81 errors:0 dropped:0 overruns:0 frame:0
TX packets:81 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:5152 (5.0 Kb) TX bytes:5152 (5.0 Kb)

sh-# ping -I eth0 -i 3 -c 4 -s 100 www.google.com
PING www.google.com (74.125.239.146) from 192.168.102.68 eth0: 100(128) bytes of data.
108 bytes from nuq05s02-in-f18.1e100.net (74.125.239.146): icmp_req=1 ttl=53 time=290 ms
108 bytes from nuq05s02-in-f18.1e100.net (74.125.239.146): icmp_req=2 ttl=53 time=294 ms
108 bytes from nuq05s02-in-f18.1e100.net (74.125.239.146): icmp_req=3 ttl=53 time=288 ms
108 bytes from nuq05s02-in-f18.1e100.net (74.125.239.146): icmp_req=4 ttl=53 time=290 ms

--- www.google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 9015ms
rtt min/avg/max/mdev = 288.843/290.907/294.119/1.954 ms

sh-# ping -c 4 192.168.0.1
PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.
64 bytes from 192.168.0.1: icmp_req=1 ttl=255 time=4.86 ms
64 bytes from 192.168.0.1: icmp_req=2 ttl=255 time=2.19 ms
64 bytes from 192.168.0.1: icmp_req=3 ttl=255 time=1.53 ms
64 bytes from 192.168.0.1: icmp_req=4 ttl=255 time=4.32 ms

--- 192.168.0.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3016ms
rtt min/avg/max/mdev = 1.536/3.230/4.861/1.398 ms

sh-# ping -I eth0 -c 4 www.google.com
PING www.google.com (74.125.239.148) from 192.168.0.153 eth0: 56(84) bytes of data.
From 192.168.0.153 icmp_seq=1 Destination Host Unreachable
From 192.168.0.153 icmp_seq=2 Destination Host Unreachable
From 192.168.0.153 icmp_seq=3 Destination Host Unreachable
From 192.168.0.153 icmp_seq=4 Destination Host Unreachable

--- www.google.com ping statistics ---
4 packets transmitted, 0 received, +4 errors, 100% packet loss, time 4076ms
pipe 3

sh-# ping -I eth0 -i 3 -s 100 www.google.com
PING www.google.com (74.125.239.144) from 192.168.0.153 eth0: 100(128) bytes of data.
108 bytes from nuq05s02-in-f16.1e100.net (74.125.239.144): icmp_req=1 ttl=53 time=289 ms
108 bytes from nuq05s02-in-f16.1e100.net (74.125.239.144): icmp_req=2 ttl=53 time=297 ms
108 bytes from nuq05s02-in-f16.1e100.net (74.125.239.144): icmp_req=3 ttl=53 time=349 ms
108 bytes from nuq05s02-in-f16.1e100.net (74.125.239.144): icmp_req=5 ttl=53 time=304 ms
^C
---
www.google.com ping statistics ---
6 packets transmitted, 4 received, 33% packet loss, time 17698ms
rtt min/avg/max/mdev = 289.230/310.141/349.551/23.385 ms

1. 通过ping本机测试网卡是否正常,
sh-# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:00:00:00:FF:95
inet addr:192.168.102.68 Bcast:192.168.102.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:11752 errors:0 dropped:441 overruns:0 frame:0
TX packets:7364 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:15719209 (14.9 Mb) TX bytes:552988 (540.0 Kb)
Interrupt:40 Base address:0x2000

sh-# ping 192.168.102.68
PING 192.168.102.68 (192.168.102.68) 56(84) bytes of data.
64 bytes from 192.168.102.68: icmp_req=1 ttl=64 time=0.051 ms
64 bytes from 192.168.102.68: icmp_req=2 ttl=64 time=0.046 ms
64 bytes from 192.168.102.68: icmp_req=3 ttl=64 time=0.046 ms
64 bytes from 192.168.102.68: icmp_req=4 ttl=64 time=0.051 ms
64 bytes from 192.168.102.68: icmp_req=5 ttl=64 time=0.048 ms
^C
--- 192.168.102.68 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 3996ms
rtt min/avg/max/mdev = 0.046/0.048/0.051/0.006 ms

2. 通过ping网关来确认本机与网关的连通情况,
sh-# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.102.254 0.0.0.0 UG 0 0 0 eth0
192.168.102.0 * 255.255.255.0 U 0 0 0 eth0
sh-# ping 192.168.102.254
PING 192.168.102.254 (192.168.102.254) 56(84) bytes of data.
64 bytes from 192.168.102.254: icmp_req=1 ttl=64 time=0.259 ms
64 bytes from 192.168.102.254: icmp_req=2 ttl=64 time=0.255 ms
64 bytes from 192.168.102.254: icmp_req=3 ttl=64 time=0.249 ms
^C
--- 192.168.102.254 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1998ms
rtt min/avg/max/mdev = 0.249/0.254/0.259/0.013 ms

3. 通过ping外网测试本机与外网连通情况,
sh-# ping
www.google.com
PING www.google.com (74.125.239.146) 56(84) bytes of data.
64 bytes from nuq05s02-in-f18.1e100.net (74.125.239.146): icmp_req=1 ttl=54 time=259 ms
64 bytes from nuq05s02-in-f18.1e100.net (74.125.239.146): icmp_req=2 ttl=54 time=309 ms
^C
---
www.google.com ping statistics ---
3 packets transmitted, 2 received, 33% packet loss, time 2009ms
rtt min/avg/max/mdev = 259.379/284.522/309.665/25.143 ms

2013/10/02增加:
ficonfig结果里面有一个lo的网卡,实际上这不是一个真正的网卡。
通常通过ping loopback来测试linux网络配置是否正确。
sh-# ifconfig
eth0 Link encap:Ethernet HWaddr 00:00:00:00:FF:95
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
Interrupt:40 Base address:0x2000

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:24 errors:0 dropped:0 overruns:0 frame:0
TX packets:24 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2080 (2.0 Kb) TX bytes:2080 (2.0 Kb)

sh-3.2# ping 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_req=1 ttl=64 time=0.052 ms
64 bytes from 127.0.0.1: icmp_req=2 ttl=64 time=0.048 ms
64 bytes from 127.0.0.1: icmp_req=3 ttl=64 time=0.048 ms
64 bytes from 127.0.0.1: icmp_req=4 ttl=64 time=0.048 ms
^C
--- 127.0.0.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3001ms
rtt min/avg/max/mdev = 0.048/0.049/0.052/0.002 ms

sh-3.2#

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值