`
444878909
  • 浏览: 638432 次
文章分类
社区版块
存档分类
最新评论

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#

分享到:
评论

相关推荐

    linux必须的60个命令

    就必须从Linux命令学起,通过基础的命令学习可以进一步理解Linux系统。 不同Linux发行版的命令数量不一样,但Linux发行版本最少的命令也有200多个。这里笔者把比较重要和使用频率最多的命令,按照它们在系统中的作用...

    linux下ping程序的实现

    可实现ping命令的ICMP包发送,对于了解及学习网络编程很有帮助

    linux命令大全

    就必须从Linux命令学起,通过基础的命令学习可以进一步理解Linux系统。 不同Linux发行版的命令数量不一样,但Linux发行版本最少的命令也有200多个。这里笔者把比较重要和使用频率最多的命令,按照它们在系统中的作用...

    Ping 命令 可供参考和学习,希望对你有所帮助!

    Ping 命令,可供参考和学习,希望对你有所帮助!

    Linux必学的60个命令

    要想真正理解Linux系统,就必须从Linux命令学起,通过基础的命令学习可以进一步理 解Linux系统。 不同Linux发行版的命令数量不一样,但Linux发行版本最少的命令也有200多个。这里笔者 把比较重要和使用频率最多的...

    Linux常用命令超详细学习笔记.rar

    下面是一些常用的Linux命令及其简要介绍: ls:列出目录中的文件和子目录。 cd:切换当前工作目录。 pwd:显示当前工作目录的路径。 mkdir:创建新的目录。 rm:删除文件或目录。 cp:复制文件或目录。 mv:移动文件...

    常用 Linux 命令的基本使用.docx

    01. 学习 Linux 终端命令的原因 02. 常用 Linux 命令的基本使用 03. 自动补全 Linux 终端命令格式 01. 终端命令格式 02. 查阅命令帮助信息(知道) 2.1 --help 2.2 man 文件和目录常用命令 目标 01. 查看...

    学习Linux必备常用的60个命令

    ◆ 网络操作命令:ifconfig、ip、ping、netstat、telnet、ftp、route、rlogin、rcp、finger、mail、 nslookup; ◆ 系统安全相关命令:passwd、su、umask、chgrp、chmod、chown、chattr、sudo ps、who; ◆ 其它命令...

    Linux常用命令及操作技巧汇总

    我们可以学习各种各样的文本间移动或跳转的命令和其他的普通模式的编辑命令;同时VIM与很多快捷键设置和正则表达式类似,可以辅助记忆。2)文本与文件查找:grep和find命令将会很便利。3)系统管理篇:服务状态的...

    Linux命令搜索工具linux-command.zip

    Linux命令大全搜索工具,内容包含Linux命令手册、详解、学习、搜集。   Linux命令分类 这里存放Linux 命令大全并不全,你可以通过linux-command来搜索,它是把 command 目录里面搜集的...

    cmd操作命令和linux命令大全收集

    CMD命令:开始->运行->键入cmd或command(在命令行里可以看到系统版本、文件系统版本) 命令大全 1. gpedit.msc-----组策略 2. sndrec32-------录音机 3. Nslookup-------IP地址侦测器 ,是一个 监测网络中 DNS...

    入门学习Linux常用必会60个命令实例详解doc/txt

    要想真正理解Linux系统,就必须从Linux命令学起,通过基础的命令学习可以进一步理解Linux系统。 不同Linux发行版的命令数量不一样,但Linux发行版本最少的命令也有200多个。这里笔者把比较重要和使用频率最多的命令...

    ping_cap_set_proc报错分析.docx

    在Linux某种特殊情况下 ping命令报错cat_set_proc 该文档源码层级分析核心原因 帮忙学习Linux权限、用户等

    linux命令学习之10个网络命令和监控命令

    网络和监控命令类似于这些: hostname, ping, ifconfig, iwconfig, netstat, nslookup, traceroute, finger, telnet, ethtool 用于查看linux服务器ip地址,管理服务器网络配置 ,通过 telnet 和ethernet建立与linux...

    LINUX操作系统(电子教案,参考答案)

    芬兰青年Linus Torvalds和其杰作的传奇故事吸引了无数的电脑爱好者尝试去使用Linux,但他们中的大多数人却被Unix类操作系统传统的枯燥的字符界面、艰涩难懂的操作命令和数量庞大的基本概念以及基础知识所吓退。Linux...

    LINUX 24学时教程

    10.8.3 使用ping命令 176 10.8.4 使用route命令 177 10.8.5 查看系统登录记录 177 10.9 课时小结 178 10.10 专家答疑 178 10.11 练习题 179 第11学时 配置因特网电子邮件 180 11.1 初始化设置和获取电子邮件 180 ...

    pythonpdf教程-python基础教程pdf.pdf

    ⼀、 Python 学习的四个阶段 第⼀阶段 该阶段⾸先通过介绍不同领域的三种操作系统,操作系统的发展简史以及 Linux 系统的⽂件⽬录结构让⼤家对 Linux 系统有⼀个简单的认识, 同时知道为 什么要学习 Linux 命令。...

    嵌入式Linux应用程序开发详解

    1.1.4 如何学习Linux 4 1.2 Linux安装 5 1.2.1 基础概念 5 1.2.2 硬件需求 7 1.2.3 安装准备 7 1.2.4 安装过程 8 1.3 Linux文件及文件系统 11 1.3.1 文件类型及文件属性 11 1.3.2 文件系统...

Global site tag (gtag.js) - Google Analytics