0spf原理

OSPF(Open Shortest Path First,开放式最短路径优先)协议,是目前网络中应用比较广泛的路由协议之一。属于内部网关协议,能够适应各种规模的网络环境,是链路状态(link-state)的路由协议。OSPF属于无类路由协议,支持VLSM(变长子网掩码)

OSPF特点:

链路状态路由协议

全局拓扑、无路由环路

触发更新

快速收敛

组播

支持区域划分

适应范围广,可适应大规模网络(1000台路由器)

支持可变长子网掩码,不连续子网

 

三张表格

邻居表 通过hello报文发现并形成邻居关系,形成邻居表。

链路状态数据库 邻居路由器之间交换LSA和对接收方的确认经行同步LSDB,通过DBDLSRLSAck辅助LSA的同步

路由表 LSDB同步后。每台路由器独立进行SPF运算,把最佳路由信息放进路由表。

网络类型

Broadcast  非广播多点可达网络  点到点网络  点到多点

 

 

案例1

 

Ospfeigrp路由重分发

由于不同端口和网段的路由协议不同,所以有的路径在整个网络中不一定能相互通信,就需要在属于不同协议下的端口配置另一个协议实现双向发布从而实现互通,并且拥有不同的路由限制和权限。

 

拓扑图

 

 

 

配置步骤

步骤一 配置路由器接口

R1

R1(config)#inter fastEthernet 0/0

R1(config-if)#ip add 192.168.1.1 255.255.255.224

R1(config-if)#no shutdown

R1(config-if)#

 

R1(config)#int serial 1/0

R1(config-if)#ip add 192.168.4.2 255.255.255.252

R1(config-if)#no shutdown

R1(config-if)#

 

R1(config-if)#int serial 1/1

R1(config-if)#ip add 192.168.5.1 255.255.255.252

R1(config-if)#no shutdown

R1(config-if)#

 

R2

R2(config)#int fastEthernet 0/0

R2(config-if)#ip add 192.168.2.1 255.255.255.224

R2(config-if)#loopback

R2(config-if)#no shutdown

R2(config-if)#

 

R2(config-if)#int ser 1/0

R2(config-if)#ip add 192.168.4.2 255.255.255.252

R2(config-if)#no shut

 

 

R3

R3(config)#int fastEthernet 0/0

R3(config-if)#ip add 192.168.3.1 255.255.255.224

R3(config-if)#loop

R3(config-if)#no shutdown

R3(config-if)#

 

 

R3(config-if)#int ser 1/1

R3(config-if)#ip add 192.168.5.2 255.255.255.252

R3(config-if)#no shut

R3(config-if)#

 

 

步骤二 配置eigrp ospf

 

R1

R1(config)#router ospf 10

R1(config-router)#net 192.168.1.0 0.0.0.3 area 0

R1(config-router)#net 192.168.5.0 0.0.0.3 area 0

R1(config-router)#net 192.168.1.0 0.0.0.31 area 0

 

R2

 

R2(config)#router eigrp 100

R2(config-router)#net 192.168.2.0

R2(config-router)#net 192.168.4.0

R2(config-router)#no auto-summary

 

R3

R3(config)#router ospf 10

R3(config-router)#net 192.168.3.0 0.0.0.31 area 0

R3(config-router)#net 192.168.1.0 0.0.0.3 area 0

步骤三

r1上配置路由重分发

 

R1(config)#router eigrp 100

R1(config-router)# redistribute ospf 100 metric 3 10 100 100 100

 

配置一条默认路由

R1(config)#int null 0

R1(config-if)#ip route 0.0.0.0 0.0.0.0 null 0

 

 

 

 

 

 

 

 

 

 

 

案例2

 

ospf多区域配置

为了更好地管理可把路由器较多的网络分为几个ospf区域,避免路由任务太重而引起网络问题,降低路由器的工作量,还能增加路由末节区域,在此区域内只能得到一条默认路由,能防止一些大规模的公司对小规模公司带来的网络堵塞。

 

 

 

 

拓扑

 

 

 

 

 

 

R1配置

 

R1

interface FastEthernet0/0

 ip address 192.168.1.1 255.255.255.0

 loopback

interface Serial1/0

 ip address 192.168.2.1 255.255.255.0

 

router ospf 10

network 192.168.1.0 0.0.0.255 area 1

 network 192.168.2.0 0.0.0.255 area 1

 

r2配置

interface Serial1/0

 ip address 192.168.2.2 255.255.255.0

 

interface Serial1/1

 ip address 192.168.3.1 255.255.255.0

interface Serial1/2

 ip address 192.168.6.1 255.255.255.0

 

router ospf 10

 

 redistribute static

 redistribute rip metric 10 subnets

 network 192.168.2.0 0.0.0.255 area 1

 network 192.168.3.0 0.0.0.255 area 0

ip route 0.0.0.0 0.0.0.0 Null0

 

 

 

 

R3的配置

interface Serial1/0

 ip address 192.168.4.1 255.255.255.0

interface Serial1/1

 ip address 192.168.3.2 255.255.255.0

 

router ospf 10

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

 

R4的配置

 

interface FastEthernet0/0

 ip address 192.168.5.1 255.255.255.0

interface Serial1/0

 ip address 192.168.4.2 255.255.255.0

 

router ospf 10

 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

 

 

 

R5的配置

 

interface FastEthernet0/0

 ip address 192.168.7.1 255.255.255.0

 

interface Serial1/2

 ip address 192.168.6.2 255.255.255.0

 

router rip

 network 192.168.6.0

 network 192.168.7.0