1、linux 路由表功能解析linux 路由表功能解析 linux 路由表功能解析分类: 网络2013-11-16 18:23 1268人阅读 评论(0) 收藏 举报网络局域网路由器linux 路由表功能解析 本文,简单描述一下路由的作用.简单来说,路由器就是一个公交站台,公交站台上面有很多路公交.每条线路公交车又有很多站台(路由器),你就会选择最近的一条公交出行方案,当然啦,站牌上面的路线是会经常更新,更新的事,有当地部门更新.这就是路由.一台电脑主机有路由表,路由器也有路由表,一般来说,一台主机电脑如果只有一个网卡的话,应该会有最少两条路由信息,一条是公网路由,一条是局域网路由(它是不会经过
2、路由器的路由表的,因为它走的是链路层,所以可以解析我们在局域网内传数据,速度是很快的). 测试环境:主机(linux): ip:192.168.168.1.119 netmask:255.255.0.0另一台主机(xp): ip:192.168.1.133 netmask:255.255.0.0 网关: ip:192.168.0.3 netmask: 255.255.248.0 一, 我们可以查看一下路由表.(route 命令)user:dvr_linux routeKernel IP routing tableDestination Gateway Genmask Flags Metric
3、Ref Use Ifacedefault 192.168.0.3 0.0.0.0 UG 0 0 0 eth0 /公网路由信息 /U Up, G Gateway, H Host192.168.0.0 * 255.255.0.0 U 0 0 0 eth0 /局域网路由信息.user:dvr_linux Flags 可能出现的标志有: U (route is up) 路由正常 H (target is a host) 主机路由 G (use gateway) 使用网关的间接路由 R (reinstate route for dynamic routing) 为动态选路恢复路由 D (dynamica
4、lly installed by daemon or redirect) 该路由由选路进程或重定向动态创建 M (modified from routing daemon or rederict) 该路由已由选路进程或重定向修改 ! (reject route) 阻塞路由 1.1 测试公网路由(切换到root用户下):root:dvr_linux route /打印路由表Kernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Ifacedefault 192.168.0.3 0.0.0.0 UG 0 0 0
5、 eth0192.168.0.0 * 255.255.0.0 U 0 0 0 eth0root:dvr_linux ping 8.8.8.8 / 8.8.8.8是google公司的dns.PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.64 bytes from 8.8.8.8: icmp_req=2 ttl=48 time=10.4 ms64 bytes from 8.8.8.8: icmp_req=3 ttl=48 time=10.0 ms /正常C- 8.8.8.8 ping statistics -3 packets transmitted, 2
6、 received, 33% packet loss, time 2013msrtt min/avg/max/mdev = 10.024/10.222/10.421/0.222 msroot:dvr_linux route del default dev eth0 /删除默认路由,也就公网路由,因为有网关.root:dvr_linux routeKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface192.168.0.0 * 255.255.0.0 U 0 0 0 eth0root:dvr_li
7、nux ping 8.8.8.8connect: Network is unreachable /ping 不通,没找到路由信息.数据包出不去.root:dvr_linux route add default dev eth0 /增加默认路由,没加网关.root:dvr_linux routeKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Ifacedefault * 0.0.0.0 U 0 0 0 eth0192.168.0.0 * 255.255.0.0 U 0 0 0 eth0root:dvr
8、_linux ping 8.8.8.8 PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.From 192.168.1.119 icmp_seq=1 Destination Host Unreachable /ping 不通,找到路由信息.但是找不到去8.8.8.8胡线路,数据包出不去.From 192.168.1.119 icmp_seq=2 Destination Host UnreachableFrom 192.168.1.119 icmp_seq=3 Destination Host UnreachableC- 8.8.8.8 ping stati
9、stics -5 packets transmitted, 0 received, +3 errors, 100% packet loss, time 4010mspipe 3root:dvr_linux route del default dev eth0root:dvr_linux routeKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface192.168.0.0 * 255.255.0.0 U 0 0 0 eth0root:dvr_linux route add default gw
10、192.168.0.3 dev eth0root:dvr_linux routeKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Ifacedefault 192.168.0.3 0.0.0.0 UG 0 0 0 eth0192.168.0.0 * 255.255.0.0 U 0 0 0 eth0root:dvr_linux ping 8.8.8.8PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.64 bytes from 8.8.8.8: icmp_req=1
11、 ttl=48 time=11.0 ms /重新添加带网关的路由信息后,又能ping 通了.64 bytes from 8.8.8.8: icmp_req=3 ttl=48 time=10.0 ms64 bytes from 8.8.8.8: icmp_req=4 ttl=48 time=10.3 msC- 8.8.8.8 ping statistics -4 packets transmitted, 3 received, 25% packet loss, time 3015msrtt min/avg/max/mdev = 10.037/10.496/11.071/0.445 msroot:
12、dvr_linux 1.2 测试局域网路由(切换到root用户下):root:dvr_linux routeKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Ifacedefault 192.168.0.3 0.0.0.0 UG 0 0 0 eth0192.168.0.0 * 255.255.0.0 U 0 0 0 eth0root:dvr_linux ping 192.168.1.133PING 192.168.1.133 (192.168.1.133) 56(84) bytes of data.6
13、4 bytes from 192.168.1.133: icmp_req=1 ttl=64 time=2.13 ms64 bytes from 192.168.1.133: icmp_req=2 ttl=64 time=0.450 ms /正常通过.C- 192.168.1.133 ping statistics -2 packets transmitted, 2 received, 0% packet loss, time 1003msrtt min/avg/max/mdev = 0.450/1.290/2.131/0.841 msroot:dvr_linux route del -net
14、192.168.0.0/16 dev eth0 /删除局域网路由root:dvr_linux routeKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Ifacedefault 192.168.0.3 0.0.0.0 UG 0 0 0 eth0root:dvr_linux ping 192.168.1.133PING 192.168.1.133 (192.168.1.133) 56(84) bytes of data.64 bytes from 192.168.1.133: icmp_req=1 t
15、tl=64 time=5.06 msFrom 192.168.0.3: icmp_seq=1 Redirect Host(New nexthop: 192.168.1.133) /数据包通过了默认路由信息发到了路由器,再查路由器的路由表找到了192.168.1.133的路由.再由网关发回来给192.168.1.133了.64 bytes from 192.168.1.133: icmp_req=2 ttl=64 time=0.477 ms64 bytes from 192.168.1.133: icmp_req=3 ttl=64 time=0.302 ms64 bytes from 192.1
16、68.1.133: icmp_req=4 ttl=64 time=0.285 ms64 bytes from 192.168.1.133: icmp_req=5 ttl=64 time=0.478 ms64 bytes from 192.168.1.133: icmp_req=6 ttl=64 time=0.408 msC- 192.168.1.133 ping statistics -6 packets transmitted, 6 received, 0% packet loss, time 5002msrtt min/avg/max/mdev = 0.285/1.169/5.066/1.
17、744 msroot:dvr_linux routeKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Ifacedefault 192.168.0.3 0.0.0.0 UG 0 0 0 eth0root:dvr_linux route del default eth0 /把默认路由都删掉的话,这就完全找不到路由信息了,也就是没网络了.root:dvr_linux routeKernel IP routing tableDestination Gateway Genmask Flags Metric R
18、ef Use Ifaceroot:dvr_linux ping 192.168.1.133connect: Network is unreachableroot:dvr_linux 在这个时候,192.168.1.133的xp主机去ping 192.168.1.119的话.也就ping 不通的.C:Documents and SettingsAdministrator>ping 192.168.1.119 -tPinging 192.168.1.119 with 32 bytes of data:Request timed out.Request timed out.Request ti
19、med out.Request timed out.Request timed out.Request timed out.Request timed out.Request timed out.Request timed out.Request timed out.Request timed out.Request timed out.Request timed out.Request timed out.Request timed out.Request timed out. root:dvr_linux service networking restart /重启一下网络.warn Ru
20、nning /etc/init.d/networking restart is deprecated because it may not re-enable some interfaces . (warning). Reconfiguring network interfaces.RTNETLINK answers: No such processdone.root:dvr_linux root:dvr_linux routeKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Ifacedefault
21、 192.168.0.3 0.0.0.0 UG 0 0 0 eth0192.168.0.0 * 255.255.0.0 U 0 0 0 eth0root:dvr_linux 在这个时候,192.168.1.133的xp主机去ping 192.168.1.119的话.网络恢复了.C:Documents and SettingsAdministrator>ping 192.168.1.119 -tPinging 192.168.1.119 with 32 bytes of data:Request timed out.Request timed out.Request timed out.R
22、equest timed out.Request timed out.Reply from 192.168.1.119: bytes=32 time=2ms TTL=64Reply from 192.168.1.119: bytes=32 time<1ms TTL=64Reply from 192.168.1.119: bytes=32 time<1ms TTL=64Reply from 192.168.1.119: bytes=32 time<1ms TTL=64Reply from 192.168.1.119: bytes=32 time<1ms TTL=64Reply from 192.168.1.119: bytes=32 time<1ms TTL=64Reply from 192.168.1.119: bytes=32 time=6ms TTL=63Reply from 192.168.1.119: bytes=32 time<1ms TTL=64Reply from 192.168.1.119: bytes=32 time<1ms TTL=64Reply from 192.168.1.119: bytes=32 time<1ms TTL=64
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2