ospf在企业网络中的应用

ospf简介:Ospf是open  shortest pash firet ,是开放的最短路径优先协议 ,是基于链路的链路状态协议,属于高端路由协议。

      特点 1  触发更新。当网络中拓扑结构发生改变是,而触发更新,但是,触发更新只发送增量。每30分钟检查一次更新 

                2:发布链路状态,只发布增量

                3:采用组播的形式发送报文,两个组播地址是224.0.0.5和224.0.0.6

                4:metrci:从带宽、延迟、负载、可靠度和mtu来计算metrci。计算方法:到达目标的所有出口的cost值相加,cost值为100/带宽
                5:适应范围:支持各种规模的网络,最多可支持几千台路由器。
                6:负载均衡:支持到同一目的的地址的多条等值路由,只支持等代价的。只有cisco设备支持非等代价负载均衡
                7:收敛速度:收敛速度快,在网络的拓扑结构发生变化后立即发送更新报文,在自治域里快速同步变化
                8 :不会形成路由环路:是高端路由协议不会形成路由环。Ospf根据收到的链路状体用最短路径树来计算路由,从算法上本身保证了 不会形成路由环
                9:支持验证:支持基于借口的报文验证以保证路由计算的安全性
               10:三张表格:1)邻居表格  2)链路状态数据库(lsdb) 3)路由表
               11:支持可变长子网掩码以及子网不连续
               12:体系化路由分区:区域划分,允许自治系统的网络被划分成分区来管理,区域间传送的路由信息被进一步抽象,从而减少了占用的网络带宽。区域划分为了解决网络的不稳定造成的路由信息一直修改以及lsdb条目比较多。      


 单区域ospf原理

     1. 处于同一区域的路由器之间通信,如果是广播多路,并且有多台路由器,他们必须首先建立邻居关系,建立邻居关系,是靠的发送的hello包,hello包包括routerid,neighbors,dr  ipadd,以及bdripadd。
Routera像routerb 发送一个hello包,b受到后,知道自己有a邻居。然后改写自己的邻居表格,然后应答a的hello   包。
建立邻居关系后。就是达到第一个标志性的状态:two—state状态

      2.之后就必须选举一个dr以及bdr,为了方便路由器,在路由器中选举 一个dr,然后没一个路由器与dr交流,dr再去通知链路上其他的路由器。
选举dr与bdr是根据router priority(路由优先级)p,p值越高就为dr次高的为bdr,
P值默认值为1,可以手动人为的改写p值来认定dr,p值为0的无权参加选举,(注意 若一个稳定的网络中一开始dr   p值是3 ,又重新进来一个路由器p值为10,则为了网络的稳定dr不变,若dr失效,则由bdr担当dr  只有到下一次选举的时候p值为10 的路由器才能成为dr)

        3.有了dr与bdr 然后dr首先向下边的所有的路由器发送自己的lsdb的描述法通过dbd包,下边路由器受到后 改写自己的数据链路数据库(lsdb),然后应答dr,将自己的lsdb描述符给dr。若routera没有 routerc的路由信息,a像dr请求完整的lsdb,然后达到一样的数据链路数据库。最后当他们的数据链路数据库一样时就达到了第二个标志性状态:full—state

      4.最后每个路由器根据自己的lsdb 利用spf计算出路由表  然后形成三张表格
Spf时一种固定的算法 , 是路由器自己执行的

       5.当网络发生变动时,a修改自己的lsdb,然后向dr发送自己的lsdb更新,通过组播地址:224.0.0.6,dr受到后改写自己的lsdb然后在通过组播地址224.0.0.5通知其他所有的路由器,所有路由器收到后,改写自己的lsdb,从而达到full—state状态点对点的链路,只连接两台路由器,没有dr与bdr  没有选举过程,只通过组播224.0.0.5发送路由信息。

   多区域网络
        1.当今网络越来越大,路由器数目越来越多,从而来区域划分。
        2.区域划分的目的:减少自己的lsdb的表项,以及路由表的表项,和网络的不稳定造成的而影响全局
         3.区域划分要求,1个核心区域,也是骨干区域 即是Area0区域,其他为默认区域 也叫标准区域,每一个标准区域必须与核心区域相连接 ,两个标准区域不能直接连在一起
         4.核心区域的选取, 1 稳定  2 速度快  3 其间路由器的数目越少越好    
         5.特殊的标准区域,末节区域,和完全末节区域。

 多区域路由器分类

      1.内部路由器 : 如果一台路由器上所有启用了OSPF的接口都在同一区域,那么这台路由器就是内部路由器。

      2. 骨干路由器 :骨干路由器是指至少有一个启用了OSPF的接口是和骨干区域(Area 0)相连的路由器。一台骨干路由器也可以同时是ABR或ASBR,如上图中的R2和R3。如果一台路由器上所有的接口都属于Area 0,那么这台路由器也是一台内部路由器。
 
       3.区域边界路由器 (abr)  区域界路由器是指连接一个或者多个区域到骨干区域的路由器。区域边界路由器必须至少有一个接口属于骨干区域。区域边界路由器为每一个与之相连的区域维护一份链路状态数据库,因此区域边界路由器需要比内部路由器更多的内存资源和更高性能的处理器

       4.自治系统边界路由器自治系统边界路由器(ASBR)用来把从其他路由协议(如BGP、EIGRP等)学习到的路由以路由重分发的方式注入到OSPF进程中,从而使得整个OSPF域内的路由器都可以学习到这些路由(除了末梢区域内的路由器)。一台ASBR可以是OSPF域内非末梢区域的任何路由器,它可以是内部路由器、区域边界路由器、骨干路由器。

       路由归纳必须在abr路由器上,
若 area1与area0相连,area2不能与area0 相连,只能与area1连接,但是违背区域划分要求,这样就把area1看成是一条链路 看成通过这条链路直接连在area0上

      非广播多路

     访问网络NBMA网络,如X.25、帧中继、ATM等,可以同时连接两台以上的路由器,但是这种网络没有广播数据包的能力。一台处于NBMA网络上的路由器发送的组播/广播数据包将不能被其他与之相连的路由器收到。在NBMA网络上需要选举DR和BDR,并且所有的OSPF数据包都是单播发送的 
 

案例

 

 

 

ospf在企业网中的应用

 

 

router1配置:

Router>en     
Router#conf t
Router(config)#hostname r1
r1(config)#
r1(config)#line c 0
r1(config-line)#no exec-timeout       
r1(config-line)#logging synchronous
r1(config-line)#exit
r1(config)#
r1(config)#int f0/0
r1(config-if)#no ip add
r1(config-if)#ip add 192.168.1.1 255.255.255.0    配置ip地址
r1(config-if)#no sh
r1(config)#int s 1/0
r1(config-if)#ip add 192.168.2.1 255.255.255.0
r1(config-if)#no sh
r1(config-if)#exit 
r1(config)#router ospf 100                                              开启ospf
r1(config-router)#
r1(config-router)#network  192.168.1.0 ?                     配置反掩码
  A.B.C.D  OSPF wild card bits
r1(config-router)#network  192.168.1.0 0.0.0.255 ?     反掩码=255.255.255.255—当前掩码
  area  Set the OSPF area ID
r1(config-router)#network  192.168.1.0 0.0.0.255 area ?
  <0-4294967295>  OSPF area ID as a decimal value
  A.B.C.D         OSPF area ID in IP address format
r1(config-router)#network  192.168.1.0 0.0.0.255 area 1 ?
  <cr>
r1(config-router)#network  192.168.1.0 0.0.0.255 area 1

r1(config-router)#network  192.168.2.0 0.0.0.255 area 1    配置ospf接口网段以及区域area1
r1(config-router)#int s 1/0
r1(config-if)#exit
r1(config)#

router2配置:

Router>en
Router#conf t
Router(config)#hostname r2
r2(config)#line c 0
r2(config-line)#no exec-t
r2(config-line)#no exec-timeout
r2(config-line)#logging synchronous
r2(config-line)#exit
r2(config)#
r2(config)#int s1/0
r2(config-if)#ip add 192.168.2.2 255.255.255.0
r2(config-if)#no sh
r2(config-if)#int s 1/1
r2(config-if)#ip add 192.168.3.1 255.255.255.0
r2(config-if)#no sh
r2(config-if)#exit
r2(config)#
r2(config)#int f0/0
r2(config-if)#no ip add
r2(config-if)#ip add 192.168.6.1 255.255.255.0
r2(config-if)#no sh
r2(config-if)#exit
r2(config)#
r2(config)#router ospf 100
r2(config-router)#network 192.168.2.0 0.0.0.255 a 1
r2(config-router)#^Z                              
r2#
r2#conf t
r2(config)#
r2(config)#router rip
r2(config-router)#net 192.168.6.0
r2(config-router)#^Z
r2#
r2#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
r2(config)#int f 0/0
r2(config-if)#no ip add
r2(config-if)#int s1/2
r2(config-if)#ip add 192.168.6.1 255.255.255.0
r2(config-if)#no sh
r2(config-if)#exit
r2(config)#
r2(config)#router ospf 100
r2(config-router)#redistribute rip m 
r2(config-router)#redistribute rip metric ?
  <0-16777214>  OSPF default metric
r2(config-router)#redistribute rip metric 2                           将rip重分发给ospf
r2(config-router)#exit
r2(config)#router rip
r2(config-router)#redistribute ospf 100 ? 
  match      Redistribution of OSPF routes
  metric     Metric for redistributed routes
  route-map  Route map reference
  vrf        ××× Routing/Forwarding Instance
  <cr>

r2(config-router)#redistribute ospf 100                                 将ospf重分发给rip
r2(config-router)#^Z
r2#
r2#show run
Building configuration...

Current configuration : 904 bytes
!
version 12.2
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
!
hostname r2
!
!
ip subnet-zero
!
!
!
!
!
!
interface FastEthernet0/0
 no ip address
 duplex auto
 speed auto
!
interface Serial1/0
 ip address 192.168.2.2 255.255.255.0
 no fair-queue
 serial restart-delay 0
!
interface Serial1/1
 ip address 192.168.3.1 255.255.255.0
 serial restart-delay 0
!
interface Serial1/2
 ip address 192.168.6.1 255.255.255.0
 serial restart-delay 0
!
interface Serial1/3
 no ip address
 shutdown
 serial restart-delay 0
!
router ospf 100
 log-adjacency-changes
 redistribute rip metric 2
 network 192.168.2.0 0.0.0.255 area 1
 network 192.168.3.0 0.0.0.255 area 0
 default-information originate
!
router rip
 redistribute ospf 100
 network 192.168.6.0
!
ip classless
ip http server
!
!
line con 0
 exec-timeout 0 0
 logging synchronous
line aux 0
line vty 0 4
!
end
r2#conf t
r2(config)#
r2(config)#router rip
r2(config-router)#red ?    
  bgp        Border Gateway Protocol (BGP)
  connected  Connected
  egp        Exterior Gateway Protocol (EGP)
  eigrp      Enhanced Interior Gateway Routing Protocol (EIGRP)
  igrp       Interior Gateway Routing Protocol (IGRP)
  isis       ISO IS-IS
  iso-igrp   IGRP for OSI networks
  metric     Metric for redistributed routes
  mobile     Mobile routes
  odr        On Demand stub Routes
  ospf       Open Shortest Path First (OSPF)
  rip        Routing Information Protocol (RIP)
  route-map  Route map reference
  static     Static routes
  <cr>
r2(config-router)#red ospf ?
  <1-65535>  Process ID

r2(config-router)#red ospf 100 ?
  match      Redistribution of OSPF routes
  metric     Metric for redistributed routes
  route-map  Route map reference
  vrf        ××× Routing/Forwarding Instance
  <cr>

r2(config-router)#red ospf 100 met
r2(config-router)#red ospf 100 metric ?
  <0-16>       Default metric
  transparent  Transparently redistribute metric

r2(config-router)#redistribute ospf 100 metric 2 

r2(config-router)#exit
r2(config)#re?
regexp  resume-string 
r2(config)#de?
default  default-value  define 
r2(config)#default-?
default-value 
r2(config)#router rip
r2(config-router)#
r2(config-router)#default-information o
r2(config-router)#default-information originate ?
  route-map  Route-map reference
  <cr>

r2(config-router)#default-information originate
r2(config-router)#exit
r2(config)#^Z
r2#show ip ro
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

O IA 192.168.4.0/24 [110/128] via 192.168.3.2, 00:20:08, Serial1/1
O IA 192.168.5.0/24 [110/129] via 192.168.3.2, 00:20:08, Serial1/1
C    192.168.6.0/24 is directly connected, Serial1/2
R    192.168.7.0/24 [120/1] via 192.168.6.2, 00:00:19, Serial1/2
O    192.168.1.0/24 [110/65] via 192.168.2.1, 00:20:08, Serial1/0
C    192.168.2.0/24 is directly connected, Serial1/0
C    192.168.3.0/24 is directly connected, Serial1/1
r2#show running-config
Building configuration...

Current configuration : 944 bytes
!
version 12.2
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
!
hostname r2
!
!
ip subnet-zero
!
!
!
!
!
!
interface FastEthernet0/0
 no ip address
 duplex auto
 speed auto
!
interface Serial1/0
 ip address 192.168.2.2 255.255.255.0
 no fair-queue
 serial restart-delay 0
!
interface Serial1/1
 ip address 192.168.3.1 255.255.255.0
 serial restart-delay 0
!
interface Serial1/2
 ip address 192.168.6.1 255.255.255.0
 serial restart-delay 0
!
interface Serial1/3
 no ip address
 shutdown
 serial restart-delay 0
!
router ospf 100
 log-adjacency-changes
 redistribute rip metric 2
 network 192.168.2.0 0.0.0.255 area 1
 network 192.168.3.0 0.0.0.255 area 0
 default-information originate
!
router rip
 redistribute ospf 100 metric 2
 network 192.168.6.0
 default-information originate
!
ip classless
ip http server
!
!
line con 0
 exec-timeout 0 0
 logging synchronous
line aux 0
line vty 0 4
!
end

r2#  

router3配置:

Router>en
Router#conf t
Router(config)#hostname r3
r3(config)#line c 0
r3(config-line)#no exec-timeout
r3(config-line)#logging sy
r3(config-line)#logging synchronous
r3(config-line)#exit
r3(config)#int s1/1
r3(config-if)#ip add 192.168.3.2 255.255.255.0
r3(config-if)#no sh
r3(config-if)#int s 1/0
r3(config-if)#ip add 192.168.4.1 255.255.255.0
r3(config-if)#no sh
r3(config-if)#exit
r3(config)#
r3(config)#router ospf 100
r3(config-router)#network 192.168.3.0 0.0.0.255 a 0
r3(config-router)#network 192.168.4.0 0.0.0.255 a 0
r3(config-router)#^Z
r3#ping 192.168.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 48/67/84 ms
r3#show ip rou
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

C    192.168.4.0/24 is directly connected, Serial1/0
O    192.168.5.0/24 [110/65] via 192.168.4.2, 00:28:01, Serial1/0
O E2 192.168.6.0/24 [110/2] via 192.168.3.1, 00:08:40, Serial1/1
O E2 192.168.7.0/24 [110/2] via 192.168.3.1, 00:08:40, Serial1/1
O IA 192.168.1.0/24 [110/129] via 192.168.3.1, 00:11:42, Serial1/1
O IA 192.168.2.0/24 [110/128] via 192.168.3.1, 00:11:42, Serial1/1
C    192.168.3.0/24 is directly connected, Serial1/1
r3#show run
Building configuration...

Current configuration : 786 bytes
!
version 12.2
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
!
hostname r3
!
!
ip subnet-zero
!
!
!
!
!
!
interface FastEthernet0/0
 no ip address
 shutdown
 duplex auto
 speed auto
!        
interface Serial1/0
 ip address 192.168.4.1 255.255.255.0
 no fair-queue
 serial restart-delay 0
!
interface Serial1/1
 ip address 192.168.3.2 255.255.255.0
 serial restart-delay 0
!
interface Serial1/2
 no ip address
 shutdown
 serial restart-delay 0
!
interface Serial1/3
 no ip address
 shutdown
 serial restart-delay 0
!
router ospf 100
 log-adjacency-changes
 network 192.168.3.0 0.0.0.255 area 0
 network 192.168.4.0 0.0.0.255 area 2
!
ip classless
ip http server
!
!
line con 0
 exec-timeout 0 0
 logging synchronous
line aux 0
line vty 0 4
!
end
r3#conf t
r3(config)#router ospf 100

r3(config-router)#int s1/0
r3(config-if)#rout?
r3(config)#exit
r3#
r3#conf t
r3(config)#router ospf 100
r3(config-router)#area 2 stub ?
  no-summary  Do not send summary LSA into stub area
  <cr>

r3(config-router)#area 2 stub n
r3(config-router)#area 2 stub no-summary   将area变成完全末节区域
r3(config-router)#

r3#show run  
Building configuration...

Current configuration : 810 bytes
!
version 12.2
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
!
hostname r3
!
!
ip subnet-zero
!
!
!
!
!
!
interface FastEthernet0/0
 no ip address
 shutdown
 duplex auto
 speed auto
!        
interface Serial1/0
 ip address 192.168.4.1 255.255.255.0
 no fair-queue
 serial restart-delay 0
!
interface Serial1/1
 ip address 192.168.3.2 255.255.255.0
 serial restart-delay 0
!
interface Serial1/2
 no ip address
 shutdown
 serial restart-delay 0
!
interface Serial1/3
 no ip address
 shutdown
 serial restart-delay 0
!
router ospf 100
 log-adjacency-changes
 area 2 stub no-summary
 network 192.168.3.0 0.0.0.255 area 0
 network 192.168.4.0 0.0.0.255 area 2
!
ip classless
ip http server
!
!
line con 0
 exec-timeout 0 0
 logging synchronous
line aux 0
line vty 0 4
!
end

r3#   show ip rou
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

C    192.168.4.0/24 is directly connected, Serial1/0
O    192.168.5.0/24 [110/65] via 192.168.4.2, 00:00:49, Serial1/0
O E2 192.168.6.0/24 [110/2] via 192.168.3.1, 00:00:49, Serial1/1
O E2 192.168.7.0/24 [110/2] via 192.168.3.1, 00:00:49, Serial1/1
O IA 192.168.1.0/24 [110/129] via 192.168.3.1, 00:00:49, Serial1/1
O IA 192.168.2.0/24 [110/128] via 192.168.3.1, 00:00:49, Serial1/1
C    192.168.3.0/24 is directly connected, Serial1/1
r3#

router4配置:Router>en
Router#conf t
Router(config)#hostname r4
r4(config)#
r4(config)#line c 0
r4(config-line)#
r4(config-line)#no exec-timeout
r4(config-line)#logging synchronous
r4(config-line)#exit
r4(config)#int s1/0
r4(config-if)#ip add 192.168.4.2 255.255.255.0
r4(config-if)#no sh
r4(config-if)#int f0/0
r4(config-if)#ip add 192.168.5.1 255.255.255.0
r4(config-if)#loop
r4(config-if)#no sh
r4(config-if)#exit
r4(config)#
r4(config)#router ospf 100           
r4(config-router)#network 192.168.4.0 0.0.0.255 a 2
r4(config-router)#network 192.168.5.0 0.0.0.255 a 2
r4(config-router)#^Z
r4#
r4#ping 192.168.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 88/110/144 ms
r4#show ip rou
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

C    192.168.4.0/24 is directly connected, Serial1/0
C    192.168.5.0/24 is directly connected, FastEthernet0/0
O E2 192.168.6.0/24 [110/2] via 192.168.4.1, 00:16:02, Serial1/0
O E2 192.168.7.0/24 [110/2] via 192.168.4.1, 00:16:02, Serial1/0
O IA 192.168.1.0/24 [110/193] via 192.168.4.1, 00:35:24, Serial1/0
O IA 192.168.2.0/24 [110/192] via 192.168.4.1, 00:35:24, Serial1/0
O IA 192.168.3.0/24 [110/128] via 192.168.4.1, 00:35:24, Serial1/0
r4#conf t
r4(config)#router ospf 100
r4(config-router)#ar
r4(config-router)#area 2 stub no
r4(config-router)#area 2 stub no-summary              将area2变成完全末节区域
r4(config-router)#^Z
r4#
r4#show ip rou
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 192.168.4.1 to network 0.0.0.0

C    192.168.4.0/24 is directly connected, Serial1/0
C    192.168.5.0/24 is directly connected, FastEthernet0/0
O*IA 0.0.0.0/0 [110/65] via 192.168.4.1, 00:00:09, Serial1/0
r4#show run  
Building configuration...

Current configuration : 820 bytes
!
version 12.2
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
!
hostname r4
!
!
ip subnet-zero
!
!
!
!
!
!
interface FastEthernet0/0
 ip address 192.168.5.1 255.255.255.0
 loopback
 duplex auto
 speed auto
!        
interface Serial1/0
 ip address 192.168.4.2 255.255.255.0
 no fair-queue
 serial restart-delay 0
!
interface Serial1/1
 no ip address
 shutdown
 serial restart-delay 0
!
interface Serial1/2
 no ip address
 shutdown
 serial restart-delay 0
!
interface Serial1/3
 no ip address
 shutdown
 serial restart-delay 0
!
router ospf 100
 log-adjacency-changes
 area 2 stub no-summary
 network 192.168.4.0 0.0.0.255 area 2
 network 192.168.5.0 0.0.0.255 area 2
!
ip classless
ip http server
!
!
line con 0
 exec-timeout 0 0
 logging synchronous
line aux 0
line vty 0 4
!
end

r4#

router5配置:

Router>
Router>en
Router#conf t
Router(config)#
Router(config)#hostname r5
r5(config)#line c 0
r5(config-line)#
r5(config-line)#no exec-timeout
r5(config-line)#logging sy
r5(config-line)#exit
r5(config)#
r5(config)#int s1/0
r5(config-if)#ip add 192.168.6.2 255.255.255.0
r5(config-if)#no sh
r5(config-if)#
r5(config-if)#int s1/1
r5(config-if)#ip add 192.168.7.1 255.255.255.0
r5(config-if)#no sh
r5(config-if)#exit
r5(config)#
r5(config)#router rip
r5(config-router)#net 192.168.6.0 ?
  <cr>

r5(config-router)#net 192.168.6.0
r5(config-router)#net 192.168.7.0
r5(config-router)#^Z
r5#ping 192.168.1.1

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.1, timeout is 2 seconds:
.....
r5#show run
Building configuration...

Current configuration : 724 bytes
!
version 12.2
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
!
hostname r5
!
!
ip subnet-zero
!
!
!
!
!
!
interface FastEthernet0/0
 no ip address
 shutdown
 duplex auto
 speed auto
!        
interface Serial1/0
 ip address 192.168.6.2 255.255.255.0
 no fair-queue
 serial restart-delay 0
!
interface Serial1/1
 ip address 192.168.7.1 255.255.255.0
 serial restart-delay 0
!
interface Serial1/2
 no ip address
 shutdown
 serial restart-delay 0
!
interface Serial1/3
 no ip address
 shutdown
 serial restart-delay 0
!
router rip
 network 192.168.6.0
 network 192.168.7.0
!        
ip classless
ip http server
!
!
line con 0
 exec-timeout 0 0
 logging synchronous
line aux 0
line vty 0 4
!
end

r5#ping 192.168.6.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.6.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 8/16/40 ms
r5
r5#show ip rout
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

C    192.168.6.0/24 is directly connected, Serial1/0
C    192.168.7.0/24 is directly connected, Serial1/1
r5#ping 192.168.6.1

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.6.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 20/32/44 ms
r5#show ip rout
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 192.168.6.1 to network 0.0.0.0

R    192.168.4.0/24 [120/2] via 192.168.6.1, 00:00:20, Serial1/0
R    192.168.5.0/24 [120/2] via 192.168.6.1, 00:00:20, Serial1/0
C    192.168.6.0/24 is directly connected, Serial1/0
C    192.168.7.0/24 is directly connected, Serial1/1
R    192.168.1.0/24 [120/2] via 192.168.6.1, 00:00:20, Serial1/0
R    192.168.2.0/24 [120/2] via 192.168.6.1, 00:00:20, Serial1/0
R    192.168.3.0/24 [120/2] via 192.168.6.1, 00:00:20, Serial1/0
R*   0.0.0.0/0 [120/1] via 192.168.6.1, 00:00:20, Serial1/0
r5#

router6配置:

Router>en
Router#conf t
Router(config)#hostname r6
r6(config)#
r6(config)#line c 0
r6(config-line)#no exec-t
r6(config-line)#logging sy
r6(config-line)#exit
r6(config)#int s1/1
r6(config-if)#ip add 192.168.7.2 255.255.255.0
r6(config-if)#exit
r6(config)#router rip
r6(config-router)#net 192.168.7.0
r6(config-router)#exit
r6(config)#e^Z
r6#
r6#conf t
r6(config)#int s1/1
r6(config-if)#no s
r6(config-if)#^Z
r6#ping 192.168.7.1
00:41:04: %SYS-5-CONFIG_I: Configured from console by console
r6#ping 192.168.7.1

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.7.1, timeout is 2 seconds:
.!!!!
Success rate is 80 percent (4/5), round-trip min/avg/max = 8/11/16 ms
r6#ping 192.168.6.1

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.6.1, timeout is 2 seconds:
.....
Success rate is 0 percent (0/5)
r6#ping 192.168.6.1

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.6.1, timeout is 2 seconds:
.!!!!
Success rate is 80 percent (4/5), round-trip min/avg/max = 16/37/52 ms
r6#ping 192.168.6.1

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.6.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 16/32/48 ms

r6#ping 192.168.2.2

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.2.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 60/84/128 ms
r6#
r6#
r6#