Fork me on GitHub

Linux网络管路——网络相关命令ping、traceroute

ping

[root@51cto /]# ping www.baidu.com
PING www.a.shifen.com (61.135.169.121) 56(84) bytes of data.
64 bytes from 61.135.169.121: icmp_seq=1 ttl=128 time=71.7 ms
64 bytes from 61.135.169.121: icmp_seq=2 ttl=128 time=72.1 ms
64 bytes from 61.135.169.121: icmp_seq=3 ttl=128 time=133 ms
64 bytes from 61.135.169.121: icmp_seq=4 ttl=128 time=119 ms
^C
--- www.a.shifen.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3676ms
rtt min/avg/max/mdev = 71.735/99.181/133.310/27.659 ms

与Windows环境下ping不同,Linux环境下,如果不按Ctrl+C会一直ping下去。Windows ping只发4个数据包完事。

ttl生存时间,每过一个路由器ttl减一,ttl为0时就停止转发。这样可以防止数据包在网络上无限转发。

rtt代表往返时间

mdev代表(Mean Deviation)平均偏差,表示这些 ICMP 包的 RTT 偏离平均值的程度,这个值越大说明你的网速越不稳定。

 

-c 指定发送几个数据包

# ping 8.8.8.8 -c4
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=128 time=73.9 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=128 time=82.1 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=128 time=119 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=128 time=137 ms

--- 8.8.8.8 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3146ms
rtt min/avg/max/mdev = 73.913/103.372/137.647/26.263 ms

 -i 指定等待几秒钟 发送一个ping包

-w ping命令执行时间,单位是秒

-t 指定数据包TTL

# ping 8.8.8.8 -t 1
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
From 192.168.80.2 icmp_seq=1 Time to live exceeded
From 192.168.80.2 icmp_seq=2 Time to live exceeded
From 192.168.80.2 icmp_seq=3 Time to live exceeded
From 192.168.80.2 icmp_seq=4 Time to live exceeded
From 192.168.80.2 icmp_seq=5 Time to live exceeded
^C
--- 8.8.8.8 ping statistics ---
5 packets transmitted, 0 received, +5 errors, 100% packet loss, time 4261ms

通过设置ttl的值可以跟踪到目标地址的沿途路由器

-s 指定发送数据包大小,默认65字节

通过ping返回结果可以大概猜测对方是什么操作系统。如果主机A ping B,中间没有经过路由器,那么从ping返回结果上大概能猜出来B时windows还是Linux。Windows的ttl一般是128,linux的ttl一般是64。当然ttl可以在操作系统上设置,如果没设置的话,大概是可以猜出来对端是什么操作系统的。

traceroute

ping只能知道到目标主机之间的链路通还是不通,如果不通,并不知道具体是哪里断了。traceroute可以

如何安装traceroute参考方法二:【问题】This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

traceroute   www.google.com
traceroute to www.google.com (216.58.211.228), 30 hops max, 60 byte packets
 1  192.168.1.1 (192.168.1.1)  1.061 ms  1.709 ms  2.262 ms
 2  * * *
 3  10.103.5.41 (10.103.5.41)  41.594 ms  43.136 ms  44.617 ms
 4  172.29.24.33 (172.29.24.33)  50.849 ms  51.574 ms  52.316 ms
 5   (201.141.0.82)  2.705 ms  2.564 ms  2.680 ms
 6   (201.118.231.14)  5.375 ms  5.126 ms  5.252 ms
 7  * * *
 8  * * *
 9  * * *
10  * * *
11  * * *
12  * * *
13  * * *
14  * * *
15  * * *
16  * * *
17  * * *
18  * * *
19  * * *
20  * * *
21  * * *
22  * * *
23  * * *
24  * * *
25  * * *
26  * * *
27  * * *
28  * * *
29  * * *
30  * * *

traceroute工作原理?

通过发送一个UDP探测包,这个探测包带有很小的ttl,然后侦听来自网关的ICMP“超时”回复。开始时ttl为1,然后每次加1。每设置一个ttl值发送3个UDP探测包(用-q标志进行更改)。探测结果显示为一行,分别是网关,3次往返时间。如果在5秒之内,没有得到ICMP“超时”回复,每一个探测包用*表示(超时间隔用-w标志改变)。traceroute最多探测30个网关(使用-m标志增加最大跳数)。上面这个例子,我们最多只得到201.118.231.14的ICMP“超时”回复,后续节点直到最大跳数都没有回应ICMP数据包。

为什么在VMWare的NAT模式下无法使用traceroute?

如何在VMWare的NAT模式下使用traceroute(解析vmnat的行为)

 

posted @ 2018-05-31 19:26  克拉默与矩阵  阅读(931)  评论(0编辑  收藏  举报