现在的企业网络搭建中经常会用到OSPF,在此对该协议做一些阐述。
ospf 称为开放最短路径优先协议,所有设备厂商都支持的一种协议属于链路状态路由协议,适用于大型园区企业网络当中。
 OSPF具有很多优点,1.采用触发更新路由,只要网络拓扑结构一旦发生变化,立即会触发更新路由表。2.根据链路状态来发送一些路由。3.采用组播发送路由协议。共有两个可用的组播ip地址224.0.0.5、224.0.0.6。5.适用的网络规模很大,几乎没有规模的限制6.metric cost。7.收敛速度比较快,而且不会造成路由环路8.有三张表格:(1)邻居表格通过发送HELLO包来与邻居交换机互换信息(2)链路状态数据库又称为LSDB(3)根据lsdb数据库运算出整个路由表(9)支持可变长子网掩码和子网不连续。而这些优点都是其它低端路由协议所不具备的。(10)支持到同一个目的地址的多条等代价路由。
OSPF路由表的产生过程:
每个路由器根据链路状态向其他路由器发送LSA(数据链路状态数据库),然后网络中的路由器将受到的所有LSA汇总成一个LSDB(链路状态数据库)。然后每台路由器使用SPF算法计算出一张最短路由的路径树状结构,从而得到各个节点的路由,产生路由表。
ospf可划分为单区域配置和多区域配置,单区域常应用于一些小型的网络中。
在企业网络中大部分使用的是多区域ospf,整个网络可以看做由多个自制系统组成。在ospf的不同区域中,area 0为骨干区域,在骨干区域中,为了保障数据包转发的速度,路由器的数量越少越好,而且作为area 0中的路由器,稳定性要非常强,传输速度越快越好。
area1 为标准区域,每个标准区域都必须与骨干区域(area 0)用路由器相连,而且在标准区域之间是不能直连的。
Stub区域通常位于自制系统边界,又称为末节区域。
完全Stub区域又称为完全末节区域。这种区域中,没有去往任何其他自制系统的路由。
ospf模型中根据路由器所处的位置不同,所起到的作用和名称也不尽相同;路由器的端口被分配到多个区域中去,那么这个路由器称为ABR(区域边界路由器)。ABR均为骨干区域的边界路由。连接自制系统的路由器称为ASBR(自制系统边界路由器)。由于二者之间大部分运行的路由协议不同,所以通常需要对该路由进行重分发,才能实现自治区域与其他网络的通信。
 
关于OSPF多区域配置:
设备需求:6台路由器,其中ROUTER24SERIAL接口。
实验目的:
其中R1R2R3R4在不同的区域内运行ospf协议;
R1area 1作为Stub区域,R4area 2作为完全Stub区域。
R5R6在自制区域内运行RIP v1,实现全网互通。
RIP中学习一条默认路由与OSPF进行通信;
OSPF area0区域学习到所有详细的路由表
area 2区域中只学到一条默认路和本区域内网络设备的路由表由向全网各个网络设备之间实现通信
CISCO路由器为例:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

下面为配置信息:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1111111111111111111111111111
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Router>en 15[进入路由器管理级别15]

Router#conf ter

Router(config)#hostname R1[为路由器起别名]

R1(config)#INT F0/0【进入接口配置IP地址

R1(config-if)#ip addres 192.168.1.1 255.255.255.0  

R1(config-if)#no shut

R1(config-if)#int s1/0

R1(config-if)#ip add 192.168.2.1 255.255.255.0

R1(config-if)#no shut

R1(config-if)#router ospf 10【为R1配置】

R1(config-router)#network 192.168.1.0 0.0.0.255 area 1 ospf的网段写法,首先写出该网段的IP 地址,然后跟上该网段的反掩码,最后跟上该网段所属的area x区域】

R1(config-router)#network 192.168.2.0 0.0.0.255 area 1

R1(config-router)#exit【R1路由配置完毕】
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~
2222222222222222222222222222
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Router>en 15

Router#conf ter

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

Router(config)#hostna R2 

R2(config)#int s1/0

R2(config-if)#ip add 192.168.2.2 255.255.255.0

R2(config-if)#no shut

R2(config-if)#int s1/1

R2(config-if)#ip add 192.168.3.1 255.255.255.0

R2(config-if)#no shut

R2(config)#int s1/2

R2(config-if)#ip add 192.168.6.1 255.255.255.0

R2(config-if)#no shut

R2(config)#router ospf 10【配置ospf协议】

R2(config-router)#network 192.168.2.0 0.0.0.255 area 1

R2(config-router)#network 192.168.3.0 0.0.0.255 area 0

R2(config)#router rip【配置RIP

R2(config-router)#network 192.168.6.0

R2(config)#router ospf 10

R2(config-router)#redistribute rip subnets 【对rip协议进行重分发,在ospf 区域中学习到各个区域中的详细路由表】

R2(config)#route RIP【下面的rip区域中学习到默认路由】

R2(config-router)#redistribute static

R2(config)#int null 0【注入一条默认路由】

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

R2(config)#

R2(config)#

R2(config)#exit【R2路由配置完毕】
~~~~~~~~~~~~~~~~~~~~
333333333333
~~~~~~~~~~~~~~~~~~~~
Router>en 15

Router#conf ter

Router(config)#int s1/1

Router(config-if)#ip ad 192.168.3.2 255.255.255.0

Router(config-if)#no shut

Router(config)#int s1/0

Router(config-if)#ip add 192.168.4.1 255.255.255.0

Router(config-if)#no shut

Router(config-if)#router ospf 10【配置OSPF

Router(config-router)#network 192.168.3.0 0.0.0.255 area 0

Router(config-router)#network 192.168.4.0 0.0.0.255 area 2

Router#conf ter 

Router(config)#router ospf 10   【作为完全Stub区域的边界路由器,需要在Stub 中声明不要自动汇总路由表,这样能够提高早area 2的各个网络设备之间的速度,需要注意的是末节区域需要在该区域的所有路由器上都声明 area x stub

Router(config-router)#area 2 stub no-summary 【R3路由配置完毕】
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4444444444444444444444
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Router>en 15

Router#conf ter

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

Router(config)#int s1/0

Router(config-if)#ip add 192.168.4.2 255.255.255.0

Router(config-if)#no shut

Router(config-if)#hostname R4

R4(config)#int f0/0

R4(config-if)#ip add 192.168.5.1 255.255.255.0

R4(config-if)#no shut

R4(config-if)#loop

R4(config)#router ospf 10

R4(config)#router ospf 10  [ospf路由协议的配置方法]

R4(config-router)#network 192.168.4.0 0.0.0.255 area 2

R4(config-router)#network 192.168.5.0 0.0.0.255 area 2

R4(config-router)#exit

R4(config-router)#area 2 stub【设置末节区域】

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55555555555555555555555555555
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Router>en 15

Router#conf ter

Router(config)#hostname R5

R5(config)#int s1/2

R5(config-if)#ip add 192.168.6.2 255.255.255.0

R5(config-if)#no shut

R5(config-if)#int s1/0

R5(config-if)#ip add 192.168.7.1 255.255.255.0

R5(config-if)#no shut

R5(config-router)#router rip

R5(config-router)#network 192.168.6.0

R5(config-router)#network 192.168.7.0

R5(config-router)#

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
666666666666666666666666666666
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Router>en 15

Router#conf ter

Router(config)#int s1/0

Router(config-if)#ip add 192.168.7.2 255.255.255.0

Router(config-if)#no shut

Router(config-if)#

Router(config-if)#int f0/0

Router(config-if)#ip add 192.168.8.1 255.255.255.0

Router(config-if)#no shut

Router(config-if)#loop

Router(config-if)#

Router(config-if)#exit

Router(config)#router ripRIP的路由协议配置】

Router(config-router)#network 192.168.7.0【跟上直连的网段】

Router(config-router)#network 192.168.8.0

Router(config-router)#【R6配置完毕】
试验完成
观察R2上的路由表
Gateway of last resort is 0.0.0.0 to network 0.0.0.0

 

R    192.168.8.0/24 [120/2] via 192.168.6.2, 00:00:22, Serial1/2
O IA 192.168.4.0/24 [110/128] via 192.168.3.2, 00:31:30, Serial1/1
O IA 192.168.5.0/24 [110/129] via 192.168.3.2, 00:02:02, 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:22, Serial1/2
O    192.168.1.0/24 [110/65] via 192.168.2.1, 00:31:30, Serial1/0
C    192.168.2.0/24 is directly connected, Serial1/0
C    192.168.3.0/24 is directly connected, Serial1/1
S*   0.0.0.0/0 is directly connected, Null0
R2#
观察R4上的路由表
R4为完全末节区域,学习到的路由表只有自己本区域和一条直连路由。
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:02:18, Serial1/0
R4#
 
观察R5上的路由表
R5为RIP区域,在小型网络中应用,外界的路由太多会影响本区域内网络设备的通信速度,因此学习除了本区域,外部区域的路由均为静态默认路由
Gateway of last resort is 192.168.6.1 to network 0.0.0.0

 

R    192.168.8.0/24 [120/1] via 192.168.7.2, 00:00:19, Serial1/0
C    192.168.6.0/24 is directly connected, Serial1/2
C    192.168.7.0/24 is directly connected, Serial1/0
R*   0.0.0.0/0 [120/1] via 192.168.6.1, 00:00:08, Serial1/2
R5#