Router2配置文件:
R2#
R3#sh run
hostname R3
!
interface FastEthernet0/0
ip address 10.10.10.6 255.255.255.252
duplex auto
speed auto
!
interface FastEthernet0/1
ip address 10.10.10.9 255.255.255.252
duplex auto
speed auto
!
router ospf 200
log-adjacency-changes
network 10.10.10.4 0.0.0.3 area 0
network 10.10.10.8 0.0.0.3 area 0
!
ip classless
line con 0
line vty 0 4
login
!
!
!
end
Router3配置文件:
R3#
R4#sh run
!
hostname R4
!interface FastEthernet0/0
ip address 10.10.10.10 255.255.255.252
duplex auto
speed auto
!
router ospf 300
log-adjacency-changes
network 10.10.10.8 0.0.0.3 area 0
!
ip classless
ip route 10.10.10.0 255.255.255.252 10.10.10.9
end
R4#
实验一:静态路由重分发
注意到Router0跑了两种路由协议:OSPF和静态路由,一开始我没有在该路由器上开ospf路由进程,结果怎么配置静态路由协议都不通,最后才发现,没有开启OSPF路由进程就无法和Router1路由器的OSPF进程形成邻接关系,当然Router3、Router2路由器就无法学习到了。
因为Router4路由器位于接入层,我们不想让它跑OSPF协议,做个默认路由即可,又要和其他网络都联通,而且又不想再所有OSPF网络路由器一一配置到新增的这个网络的静态路由,怎么做呢?当然是在Router0上实施静态路由重分发了,即Router0路由器将到达135.136.137.192/26这个网络的静态路由都重分发到区域0的所有OSPF路由器中。
命令是:
router ospf 50
redistribute static subnets
然后我们就可以在跑ospf的路由器Router1、Router2和Router3上看到如下路由:
Router#sh 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, 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
10.0.0.0/30 is subnetted, 3 subnets
C 10.10.10.0 is directly connected, FastEthernet0/0
C 10.10.10.4 is directly connected, FastEthernet0/1
O 10.10.10.8 [110/2] via 10.10.10.6, 01:24:13, FastEthernet0/1
135.136.0.0/26 is subnetted, 1 subnets
O E2 135.136.137.192 [110/20] via 10.10.10.1, 01:05:02, FastEthernet0/0
实验二:直连路由重分发
还有一种情况,如果Router0路由器以后再加入了新的网络,那么是不是要管理员一条条宣告ospf直连路由呢?当然可以,但不是最好的办法;使用直连路由的重分发即可实现加入新网络后,OSPF路由器可以“自动地”宣告这条新增路由,使用直连路由重分发!
在Router0路由器上新增5个网络:
!
interface Loopback1
ip address 192.168.1.1 255.255.255.0
!
interface Loopback2
ip address 192.168.2.1 255.255.255.0
!
interface Loopback3
ip address 192.168.3.1 255.255.255.0
!
interface Loopback4
ip address 192.168.4.1 255.255.255.0
!
interface Loopback5
ip address 192.168.5.1 255.255.255.0
!
一般情况下,我们要在OSPF进程里一一宣告路由才能让其他路由学习到这5个网络,现在我们在Router上实施直连路由重分布
R1(config)#router os 50
R1(config-router)#redistribute connected subnets
现在我们看下Router3路由器的路由表:
R4#sh 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, 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
10.0.0.0/30 is subnetted, 3 subnets
S 10.10.10.0 [1/0] via 10.10.10.9
O 10.10.10.4 [110/2] via 10.10.10.9, 01:38:15, FastEthernet0/0
C 10.10.10.8 is directly connected, FastEthernet0/0
135.136.0.0/26 is subnetted, 1 subnets
O E2 135.136.137.192 [110/20] via 10.10.10.9, 01:19:04, FastEthernet0/0
172.16.0.0/24 is subnetted, 1 subnets
O E2 172.16.1.0 [110/20] via 10.10.10.9, 00:00:10, FastEthernet0/0
O E2 192.168.1.0/24 [110/20] via 10.10.10.9, 00:00:10, FastEthernet0/0
O E2 192.168.2.0/24 [110/20] via 10.10.10.9, 00:00:10, FastEthernet0/0
O E2 192.168.3.0/24 [110/20] via 10.10.10.9, 00:00:10, FastEthernet0/0
O E2 192.168.4.0/24 [110/20] via 10.10.10.9, 00:00:10, FastEthernet0/0
O E2 192.168.5.0/24 [110/20] via 10.10.10.9, 00:00:10, FastEthernet0/0
通常在企业或运营商网络中,我们会很频繁地使用静态路由和直连路由的重分发。理解它才是最重要的。