一、按需路由选择原理
 
       静态路由的缺点是,必须手工配置,同时在网络拓扑变化后需要手工更新;动态路由选择协议的缺点是,它们需要占用网络带宽和路由器资源。在包含数百个分支点的中央-分支网络中,采用静态路由时配置工作量将非常大;而采用动态路由选择协议时将占用大量的资源。
 
       在这种情况下,可采用第三种方式:按需路由选择(ODR)。ODR使用Cisco发现协议(CDP)来在分支(末节)路由器和中央路由器之间传输网络信息。与动态路由选择协议相比,ODR提供IP路由选择信息的开销非常小;而与静态路由相比,ODR的手工配置量更少。
 
       ODR只适合用于中央-分支拓扑。在这种拓扑中,每台分支路由器只与中央路由器相邻。分支路由器也被称为末节路由器。末节路由器可能连接了几个LAN,但通常只有一条到中央路由器的WAN连接。中央路由器需要获悉每台分支路由器连接的网络,而分支路由器只需要一条指向中央路由器的默认路由。
 
       配置ODR后,末节路由器使用CDP将IP前缀信息发送给中央路由器。末节路由器发送其所有直连网络的前缀信息。ODR报告子网掩码,因此支持变长子网掩码(VLSM)。
 
       ODR依赖于CDP在中央路由器和分支路由器之间传输信息,因此在中央路由器和分支路由器之间的所有链路上都必须启用CDP。默认情况下,Cisco路由器全局地启用CDP,并在各个接口上启用CDP。然而,在有些WAN链路(如ATM)上,必须显式地启用CDP。
 
       中央路由器将一条指向自己的默认路由发送给分支路由器,并将ODR报告的末节网络加入到路由选择表中,可对中央路由器进行配置,使之将这些网络重分发给动态路由选择协议。中央路由器将ODR报告分支路由器的IP地址用作下一跳地址。
 
       ODR并非一种路由选择协议,因为它交换的信息仅限于IP前缀和默认路由。ODR不报告度量值,对于ODR报告的所有路由,中央路由器都将其度量值设置为1跳。然而,使用ODR,可以动态地获悉有关末节网络的路由选择信息,而不存在动态路由选择协议所需的开销;同时,无需手工配置,就能够给末节路由器提供一条默认路由。
 
二、配置ODR
 
1、在中央路由器上,使用全局命令router odr 配置ODR。
 
2、在末节路由器上,无需配置任何IP路由选择协议。事实上,从ODR的角度看,没有配置任何路由选择协议的路由器自动被视为末节路由器。
 
3、下图是一个中央-分支拓扑的网络:
 
 
4、RA的配置如下:
 
Router(config)#hostname RA
RA(config)#interface E0/0
RA(config-if)#ip address 10.2.1.1 255.255.0.0

RA(config-if)#no shutdown
RA(config-if)#exit
 
RA(config)#interface S1/0
RA(config-if)#ip address 200.200.10.1 255.255.255.252
RA(config-if)#clock rate 64000
RA(config-if)#cdp enable
RA(config-if)#no shutdown
RA(config-if)#exit
 
RA(config)#interface S1/1
RA(config-if)#ip address 200.200.20.1 255.255.255.252
RA(config-if)#clock rate 64000
RA(config-if)#cdp enable
RA(config-if)#no shutdown
RA(config-if)#exit
RA(config)#interface S1/2
RA(config-if)#ip address 200.200.30.1 255.255.255.252
RA(config-if)#clock rate 64000
RA(config-if)#cdp enable
RA(config-if)#no shutdown
RA(config-if)#exit
 
RA(config)#interface S1/3
RA(config-if)#ip address 192.168.1.1 255.255.255.252
RA(config-if)#clock rate 64000
RA(config-if)#cdp enable
RA(config-if)#no shutdown
RA(config-if)#exit
 
RA(config)#router odr
RA(config-router)#network 10.0.0.0
RA(config-router)#network 200.200.10.0
RA(config-router)#network 200.200.20.0
RA(config-router)#network 200.200.30.0
RA(config-router)#network 192.168.1.0
RA(config-router)#exit
 
5、RB的配置如下:
 
Router(config)#hostname RB
RB(config)#interface E0/0
RB(config-if)#ip address 172.16.1.1 255.255.255.0
RB(config-if)#no shutdown
RB(config-if)#exit
RB(config)#interface S1/0
RB(config-if)#ip address 200.200.10.2 255.255.255.252
RB(config-if)#cdp enable
RB(config-if)#no shutdown
RB(config-if)#exit
 
6、RC的配置如下:
 
Router(config)#hostname RC
RC(config)#interface E0/0
RC(config-if)#ip address 172.16.2.1 255.255.255.0
RC(config-if)#no shutdown
RC(config-if)#exit
RC(config)#interface S1/1
RC(config-if)#ip address 200.200.20.2 255.255.255.252
RC(config-if)#cdp enable
RC(config-if)#no shutdown
RC(config-if)#exit
 
7、RD的配置如下:
 
Router(config)#hostname RD
RD(config)#interface E0/0
RD(config-if)#ip address 172.16.3.1 255.255.255.0
RD(config-if)#no shutdown
RD(config-if)#exit
RD(config)#interface S1/2
RD(config-if)#ip address
200.200.30.2 255.255.255.252
RD(config-if)#cdp enable
RD(config-if)#no shutdown
RD(config-if)#exit
 
8、Internet的配置如下:
 
Router(config)#hostname Internet
Internet(config)#interface L0
Internet(config-if)#ip address 172.16.4.1 255.255.255.0
Internet(config-if)#exit
 
Internet(config)#interface S0/0
Internet(config-if)#ip address 192.168.1.2 255.255.255.252
Internet(config-if)#cdp enable
Internet(config-if)#no shutdown
Internet(config-if)#exit
 
9、在RA上查看路由表:
RA#show ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
 
172.16.0.0/16 is subnetted , 4 subnets
o     172.16.1.0/24 [160/1] via 200.200.10.2, 00:00:49, Serial1/0
o     177.16.2.0/24 [160/1] via 200.200.20.2, 00:00:13, Serial1/1
o     172.16.3.0/24 [160/1] via 200.200.30.2, 00:00:15, Serial1/2
o     172.16.4.0/24 [160/1] via 192.168.1.2, 00:00:01, Serial1/3

C    10.2.0.0/16 is directly connected, Ethernet0/0
C    200.200.10.0/24 is directly connected, Serial1/0
C    200.200.20.0/24 is directly connected, Serial1/1
C    200.200.30.0/24 is directly connected, Serial1/2
C    192.168.1.0/24 is directly connected, Serial1/3
 
每台分支路由器的路由表中只包含其直连网络和来自中央路由器的ODR默认静态路由。