返回顶部

思科CCNA中文教程--第五章IP路由(上)

第五章 IP路由

5.1 查找路由条目

提问 在路由表中查找特定的路由条目

回答

Router>show ip route 172.25.100.15

Routing entry for 172.25.100.0/24

Known via "ospf 55",distance 110,metric 11,type inter area

Redistributing via ospf 55

Last update from 172.25.1.1 on Ethernet0,2d12h ago

Routing Descriptor Blocks:

*172.25.1.1,from 172.25.1.1,2d12h ago,via Ethernet0

Route metric is 11,traffic share count is 1

注释 路由器在路由表中查找路由条目的原则是最长匹配,所以例子中虽然查找的是172.25.200.15但是由于没有这条特定的路由,显示的结果是最长匹配的172.15.100.024。如果没有任何一条匹配只能使用缺省路由,会出现下面信息

Router>show ip route 172.15.101.5

% Network not in table

注意的是这里都是无类路由,如果有类的就不一样了

5.2 查找特定类型的路由条目

提问 在路由表中查找相同类型的路由条目

回答

Router>show ip route static

192.168.1.0/32 is subnetted,1 subnets

S 192.168.1.1[1/0] via 172.25.1.4

还有一个更有用的命令

Router>show ip route summary

IP routing table name is Default-IP-Routing-Table(0)

Route Source Networks Subnets Overhead Memory (bytes)

connected 0 3 328 432

static 1 0 64 144

ospf 55 1 3 256 576

Intra-area:1 Inter-area:2 External-1:1 External-2:0

NSSA External-l:0 NSSA External-2:0

internal 2 2328

Total 4 6 648 3480

注释 通过显示路由表的统计情况来了解当前路由器的路由条目,也可以用来以后的比对

5.3 各种掩码的转换

注释 脚本略去,建议使用Boson提供的免费转换工具

5.4 使用静态路由

提问 配置静态路由

回答

Router#configure terminal

Enter configuration commands,one per line.End with CNTL/Z.

Router(config)#ip route 10.35.15.5 255.255.255.255 Ethernet0 (permanent选项可以使此条目一直存在于路由表中,而不管下一跳的可达性)

Router(config)#ip route 172.16.0.0 255.255.0.0 10.35.6.1 2(permanent)

Router(config)#end

Router#

也可以给路由条目打上标签

Router#configure terminal

Enter configuration commands,one per line.End with CNTL/Z.

Router(config)#ip route 172.16.0.0 255.255.0.0 10.35.6.1 2 tag 36291

Router(config)#end

Router#

注释 在类似以太网这种多路访问的网络中建议使用下一跳为地址而不是接口。正常情况下路由器对静态路由的下一跳有效的检查是一分钟,在12.3(10)以后增加了下面的命令可以对此时间进行调整Router(congfig)#ip route static adjust-time 30.对静态路由打tag用于路由再发布时的区分

5.5 浮动静态路由

提问 当动态路由出问题的时候使用静态路由作为备份

回答

Router#configure terminal

Enter configuration commands,one per line.End with CNTL/Z.

Router(congif)#ip route 10.0.0.0 255.0.0.0 172.16.1.1 190(下一跳也可以触发一个拨号接口)

Router(config)#end

Router#

注释 通过调整管理距离的方式来进行路由备份,不过要注意的是管理距离只适合在相同路由的情况下,路由条目的最长匹配是第一位的。另外在不同厂商设备互联的时候,调整管理距离一定要设置合理。

5.6 基于源地址的策略路由

提问 根据地址的不同选择不同的路径

回答

Router#configure terminal

Enter configuration commands,one per line.End with CNTL/Z.

Router(config)#access-list 1 permit 10.15.35.0 0.0.0.255

Router(config)#access-list 2 permit 10.15.36.0 0.0.0.255

Router(config)#interface Ethernet0

Router(config-if)#ip address 10.15.22.7 255.255.255.0

Router(config-if)#ip policy route-map Engineers

Router(config-if)#ip route-cache policy

Router(config-if)#exit

Router(config)#route-map Engineers permit 10

Router(config-route-map)#match ip address 1

Router(config-route-map)#set ip next-hop 10.15.27.1

Router(config-route-map)#exit

Router(config)#route-map Engineers permit 20

Router(config-route-map)#match ip address 2

Router(config-route-map)#set interface Ethernet1

Router(config-route-map)#end

Router#

注释 缺省情况下route map 的最后一句都是deny all,这样不符合route map规则的数据包都会按照正常的路由表进行转发。set ip next-hop verify-availability命令提供了对下一跳的验证,不过是基于CDP的,所以如果使用此命令需要打开CDP,最好同时调整时长,毕竟缺省是180秒。在使用策略路由时会在排错时增加难度,因为缺省对于本路由器发出的数据包可以绕过route map这样造成错觉。

5.7基于应用的策略路由

提问 根据不同的应用来选择不同的路径

回答

Router#configure terminal

Enter configuration commands,one per line.End with CNTL/Z

Router(config)#access-list 101 deny tcp 10.15.25.0 0.0.0.255 any eq www

Router(config)#access-list 101 permit tcp any any eq www

Router(config)#interface Ethernet0

Router(config-if)#ip address 10.15.22.7 255.255.255.0

Router(config-if)#ip policy route-map Websurfers

Router(config-if)#ip route-cache policy

Router(config-if)#exit

Router(config)#route-map Websurfers permit 10

Router(config-route-map)#match ip address 101

Router(config-route-map)#set ip next-hop 10.15.27.1

Router(config-route-map)#exit

Router(config)#route-map Websurfers permit 20

Router(config-route-map)#set ip default next-hop 10.15.26.1

Router(config-route-map)#end

Router#

对于本设备的发出的数据包也使用策略路由

Router#configure terminal

Enter configuration commands,one per line.End with CNTL/Z.

Router(config)#ip local policy route-map dlswtraffic

Router(config)#access-list 103 permit tcp any any eq 2065

Router(config)#access-list 103 permit tcp any eq 2065 any

Router(config)#route-map dlswtraffic permit 10

Router(config-route-map)#match ip address 103

Router(config-route-map)#set ip next-hop 10.15.27.3

Router(config-route-map)#end

Router#

注释 正常情况下如果所有定义的下一跳都不存在的情况下会使用路由表来查询,如果路由表没有此定义会使用缺省路由,这时候你可以使用set ip default next-hop来定义一个不同的缺省路由



400-0806-056