linux中查询路由器信息可以使用traceroute命令和route命令:
在大多数情况下,我们会在linux主机系统下,直接执行命令行:traceroute hostname返回的是路由信息。
执行命令route或route -n,则可以查看本机路由条目。
详细见实例:
route:
[xuwangcheng14@root]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 112.126.83.247 0.0.0.0 UG 0 0 0 eth1
10.0.0.0 10.51.63.247 255.0.0.0 UG 0 0 0 eth0
10.51.56.0 * 255.255.248.0 U 0 0 0 eth0
100.64.0.0 10.51.63.247 255.192.0.0 UG 0 0 0 eth0
112.126.80.0 * 255.255.252.0 U 0 0 0 eth1
172.16.0.0 10.51.63.247 255.240.0.0 UG 0 0 0 eth0
192.168.0.0 10.51.63.247 255.255.0.0 UG 0 0 0 eth0
traceroute www.baidu.com
[xuwangcheng14@root]# traceroute
www.baidu.comtraceroute to
www.baidu.com (220.181.112.244), 30 hops max, 60 byte packets
1 112.126.83.247 (112.126.83.247) 0.560 ms 1.236 ms 2.032 ms
2 10.87.88.37 (10.87.88.37) 7.251 ms 10.87.88.153 (10.87.88.153) 6.874 ms 10.87.80.145 (10.87.80.145) 0.849 ms
3 10.87.88.70 (10.87.88.70) 1.047 ms 10.87.72.206 (10.87.72.206) 1.660 ms 10.87.64.190 (10.87.64.190) 25.504 ms
4 123.56.34.90 (123.56.34.90) 5.946 ms 123.56.34.82 (123.56.34.82) 0.776 ms 123.56.34.86 (123.56.34.86) 1.334 ms
5 180.149.140.41 (180.149.140.41) 1.008 ms 180.149.140.53 (180.149.140.53) 1.082 ms 180.149.140.25 (180.149.140.25) 1.159 ms
6 180.149.128.105 (180.149.128.105) 5.205 ms 218.30.25.221 (218.30.25.221) 1.906 ms 180.149.128.105 (180.149.128.105) 2.793 ms
7 * * 218.30.112.137 (218.30.112.137) 759.826 ms
8 * * *
9 220.181.17.150 (220.181.17.150) 2.690 ms 220.181.17.146 (220.181.17.146) 3.021 ms 220.181.182.34 (220.181.182.34) 3.116 ms
10 * * *
11 * * *
12 * * *
13 * * *
14 * * *
15 * * *
16 * * *
17 * * *
18 * * *
19 * * *
20 * * *
21 * * *
22 * * *
23 * * *
24 * * *
25 * * *
26 * * *
27 * * *
28 * * *
29 * * *
30 * * *
说明:
记录按序列号从1开始,每个纪录就是一跳 ,每跳表示一个网关,我们看到每行有三个时间,单位是 ms,其实就是-q的默认参数。探测数据包向每个网关发送三个数据包后,网关响应后返回的时间;如果您用 traceroute -q 4 www.58.com ,表示向每个网关发送4个数据包。
有时我们traceroute 一台主机时,会看到有一些行是以星号表示的。出现这样的情况,可能是防火墙封掉了ICMP的返回信息,所以我们得不到什么相关的数据包返回数据。