OSPFv2协议

OSPF概念

OSPF是Open Shortest Path First的简称
OSPF是一种基于SPF算法的链路状态协议,同时OSPF也是一种内部网关协议。。
开放式最短路径优先OSPF(Open Shortest Path First)是IETF组织开发的一个基于链路状态的内部网关协议(Interior Gateway Protocol)。

Router ID

• 手工指定是最优先的,若第一次手工指定完成以后,再重新手工指定第二次,则此时默认情况下是不会生效的,必须重启OSPF进程才能使新指定的Router ID生效。
配置命令:reset ospf 1 process
• 接口UP/Down的选择性:
• 优选逻辑接口地址大的Router ID,无论是否UP;
• 优选物理接口地址大的为Router ID,无论是否UP;
• Router-ID冲突自动恢复(auto-recover)
• 如果OSPF区域内存在Router ID冲突,则系统可以自动重新选择新的Router ID。
可以通过ospf router id auto-recover disable关闭
ospf router-id auto-recover disable命令用来禁止检测到Router ID冲突后的自动恢复功能。
undo ospf router-id auto-recover disable命令用来使能检测到Router ID冲突后的自动恢复功能。
缺省情况下,Router ID发生冲突后,系统会自动恢复。

•使能Router ID冲突自动恢复功能后,如果OSPF区域内非直连路由存在Router ID冲突,会自动生成一个Router ID,即使用户手动配置的Router ID也会被修改。
更改Router ID后,如果OSPF区域内依然存在Router ID冲突,默认最多重新选择3次。

相同的OSPF区域不同网段的相同Router ID,会导致LSA的序列号一直刷新。
在这里插入图片描述

路由器分类

路由器的分类:
BR(Border Router):骨干路由
ABR(area border router):区域边界路由器(至少有一端链接AREA 0)交互非骨干LSA,具有ABR的特性(LSA的传递,ABR的防环原则)
真正属于ABR的要求是:
1.至少一个接口属于AREA 0,宣告(network)AREA 0
2.宣告进area 0的接口要建立FULL的邻接关系
IR(Internal router ):内部路由,只属于非骨干区域的路由器
ASBR(AS Border router):自治系统边界路由器,一端属于OSPF,另一端连接外部路由,向区域内发送LSA5,LSA7时,就会成为ASBR,运行了路由重分发(Redistribute)的OSPF router(强制的将其他路由引入进OSPF)。

OSPF网络类型

广播(Broadcast):数据链路层是Ethernet。
当链路层协议是Ethernet、FDDI时,缺省情况下,OSPF认为网络类型是Broadcast。在该类型的网络中,通常以组播形式发送Hello报文、LSU报文和LSAck报文。其中,224.0.0.5的组播地址为OSPF路由器的预留IP组播地址;224.0.0.6的组播地址为OSPF DR的预留IP组播地址,以单播形式发送DD报文和LSR报。

非广播多路访问-NBMA(Non-broadcast multiple access):数据链路层是帧中继。
当链路层协议是ATM时,缺省情况下,OSPF认为网络类型是NBMA。在该类型的网络中,以单播形式发送协议报文(Hello报文、DD报文、LSR报文、LSU报文、LSAck报文。

点到点P2P:数据链路层是PPP、HDLC。
当链路层协议是PPP、HDLC时,缺省情况下,OSPF认为网络类型是P2P。在该类型的网络中,以组播形式(224.0.0.5)发送协议报文(Hello报文、DD报文、LSR报文、LSU报文、LSAck报文)

点到多点P2MP(Point-to-Multipoint)需手工配置。
没有一种链路层协议会被缺省的认为是Point-to-Multipoint 类型。点到多点必须是由其他的网络类型强制更改的。常用做法是将非全连通的NBMA改为点到多点的网络。在该类型的网络中以组播形式(224.0.0.5)发送Hello报文,以单播形式发送其他协议报文(DD报文、LSR报文、LSU报文、LSAck报文)

指定路由器DR和备份指定路由器BDR

作用:减少邻居关系的数量,从而减少链路状态信息和路由信息的次数。Drother只与DR/BDR建立完全邻接关系。DR与BDR之间建立完全邻接关系。
DR产生网络LSA来描述NBMA网段或者广播网段信息。

选举原则:
DR/BDR由OSPF的Hello协议选举,选举是根据端口的路由器优先级(Router Priority)进行的。
如果Router Priority被设置为0,那么该路由器将不允许被选举成DR或者BDR。
Router Priority越大越优先。如果相同,Router ID大者优先。
DR/BDR不能抢占。
如果当前DR故障,当前BDR自动成为新的DR,网络中重新选举BDR;如果当前BDR故障,则DR不变,重新选举BDR。

实操配置

在这里插入图片描述

实验配置步骤

1.IP地址配置。

<Huawei>system-view 	
[Huawei]sysname  AR1
[AR1]interface  GigabitEthernet 0/0/0
[AR1-GigabitEthernet0/0/0]ip address  10.1.12.1 24
[AR1-GigabitEthernet0/0/0qui	
[AR1]interface  LoopBack 0	
[AR1-LoopBack0]ip address  1.1.1.1 32
[AR1-LoopBack0]quit

<Huawei>system-view 
[Huawei]sysname  AR2	
[AR2]interface  GigabitEthernet 0/0/1
[AR2-GigabitEthernet0/0/1]ip address  10.1.23.2 24
[AR2-GigabitEthernet0/0/1]quit
[AR2]interface  GigabitEthernet 0/0/0
[AR2-GigabitEthernet0/0/0]ip address  10.1.12.2 24
[AR2-GigabitEthernet0/0/0]quit
[AR2]interface  LoopBack 0	
[AR2-LoopBack0]ip address 2.2.2.2 32

<Huawei>system-view 
[Huawei]sysname  AR3
[AR3]interface  GigabitEthernet 0/0/1
[AR3-GigabitEthernet0/0/1]ip address  10.1.23.3 24	
[AR3-GigabitEthernet0/0/1]quit
[AR3]int GigabitEthernet 0/0/2
[AR3-GigabitEthernet0/0/2]ip address  10.1.34.3 24
[AR3-GigabitEthernet0/0/2]quit
[AR3]interface  LoopBack 0
[AR3-LoopBack0]ip address  3.3.3.3 32
[AR3-LoopBack0]quit

<Huawei>system-view 
[Huawei]sysname  AR4
[AR4]interface  GigabitEthernet 0/0/2
[AR4-GigabitEthernet0/0/2]ip address  10.1.34.4 24
[AR4-GigabitEthernet0/0/2]quit
[AR4]interface  LoopBack 0
[AR4-LoopBack0]ip address  4.4.4.4 32
[AR4-LoopBack0]quit

2.配置OSPF协议,将各设备的物理接口和逻辑接口网段通告。

[AR1]ospf 1 router-id  1.1.1.1
[AR1-ospf-1]area 1
[AR1-ospf-1-area-0.0.0.1]network 10.1.12.0 0.0.0.255
[AR1-ospf-1-area-0.0.0.0]network  1.1.1.1 0.0.0.0
[AR1-ospf-1-area-0.0.0.1]quit
[AR1-ospf-1]

[AR2]ospf 1 router-id  2.2.2.2
[AR2-ospf-1]area  1
[AR2-ospf-1-area-0.0.0.1]network  10.1.12.0 0.0.0.255	
[AR2-ospf-1-area-0.0.0.1]qui
[AR2-ospf-1]area  0
[AR2-ospf-1-area-0.0.0.0]network  10.1.23.0 0.0.0.255	
[AR2-ospf-1-area-0.0.0.0]network  2.2.2.2 0.0.0.0
[AR2-ospf-1-area-0.0.0.0]quit

[AR3]ospf 1 router-id  3.3.3.3
[AR3-ospf-1]area  2
[AR3-ospf-1-area-0.0.0.2]network  10.1.34.0 0.0.0.255
[AR3-ospf-1-area-0.0.0.2]quit
[AR3-ospf-1]area  0	
[AR3-ospf-1-area-0.0.0.0]network  3.3.3.3 0.0.0.0	
[AR3-ospf-1-area-0.0.0.0]network  10.1.23.0 0.0.0.255
[AR3-ospf-1-area-0.0.0.0]quit
[AR3-ospf-1]

[AR4]ospf 1 router-id  4.4.4.4
[AR4-ospf-1]area  2
[AR4-ospf-1-area-0.0.0.2]network  4.4.4.4 0.0.0.0	
[AR4-ospf-1-area-0.0.0.2]network  10.1.34.0 0.0.0.255
[AR4-ospf-1-area-0.0.0.2]quit
[AR4-ospf-1]

实验结果验证

1.查询各设备IP地址配置情况。

[AR1]display  ip  interface  brief 
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 3
The number of interface that is DOWN in Physical is 2
The number of interface that is UP in Protocol is 3
The number of interface that is DOWN in Protocol is 2

Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              10.1.12.1/24         up         up        
GigabitEthernet0/0/1              unassigned           down       down      
GigabitEthernet0/0/2              unassigned           down       down      
LoopBack0                         1.1.1.1/32           up         up(s)     
NULL0                             unassigned           up         up(s)     
[AR1]

[AR2]display  ip interface  brief 
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 4
The number of interface that is DOWN in Physical is 1
The number of interface that is UP in Protocol is 4
The number of interface that is DOWN in Protocol is 1

Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              10.1.12.2/24         up         up        
GigabitEthernet0/0/1              10.1.23.2/24         up         up        
GigabitEthernet0/0/2              unassigned           down       down      
LoopBack0                         2.2.2.2/32           up         up(s)     
NULL0                             unassigned           up         up(s)     
[AR2]

[AR3]display ip interface  brief 
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 4
The number of interface that is DOWN in Physical is 1
The number of interface that is UP in Protocol is 4
The number of interface that is DOWN in Protocol is 1

Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              unassigned           down       down      
GigabitEthernet0/0/1              10.1.23.3/24         up         up        
GigabitEthernet0/0/2              10.1.34.3/24         up         up        
LoopBack0                         3.3.3.3/32           up         up(s)     
NULL0                             unassigned           up         up(s)     
[AR3]

[AR4]display ip interface  brief 
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 3
The number of interface that is DOWN in Physical is 2
The number of interface that is UP in Protocol is 3
The number of interface that is DOWN in Protocol is 2

Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              unassigned           down       down      
GigabitEthernet0/0/1              unassigned           down       down      
GigabitEthernet0/0/2              10.1.34.4/24         up         up        
LoopBack0                         4.4.4.4/32           up         up(s)     
NULL0                             unassigned           up         up(s)     
[AR4]

2.查看OSPF邻居关系列表。

[AR2]display  ospf peer  brief 

	 OSPF Process 1 with Router ID 2.2.2.2
		  Peer Statistic Information
 ----------------------------------------------------------------------------
 Area Id          Interface                        Neighbor id      State    
 0.0.0.0          GigabitEthernet0/0/1             3.3.3.3          Full        
 0.0.0.1          GigabitEthernet0/0/0             1.1.1.1          Full        
 ----------------------------------------------------------------------------
[AR2]

[AR3]display  ospf peer  brief 

	 OSPF Process 1 with Router ID 3.3.3.3
		  Peer Statistic Information
 ----------------------------------------------------------------------------
 Area Id          Interface                        Neighbor id      State    
 0.0.0.0          GigabitEthernet0/0/1             2.2.2.2          Full        
 0.0.0.2          GigabitEthernet0/0/2             4.4.4.4          Full        
 ----------------------------------------------------------------------------
[AR3]

3.在AR1和AR4设备看全局IP路由表情况。

[AR1]display ip routing-table 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 13       Routes : 13       

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

        1.1.1.1/32  Direct  0    0           D   127.0.0.1       LoopBack0
        2.2.2.2/32  OSPF    10   1           D   10.1.12.2       GigabitEthernet0/0/0
        3.3.3.3/32  OSPF    10   2           D   10.1.12.2       GigabitEthernet0/0/0
        4.4.4.4/32  OSPF    10   3           D   10.1.12.2       GigabitEthernet0/0/0
      10.1.12.0/24  Direct  0    0           D   10.1.12.1       GigabitEthernet0/0/0
      10.1.12.1/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/0
    10.1.12.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/0
      10.1.23.0/24  OSPF    10   2           D   10.1.12.2       GigabitEthernet0/0/0
      10.1.34.0/24  OSPF    10   3           D   10.1.12.2       GigabitEthernet0/0/0
      127.0.0.0/8   Direct  0    0           D   127.0.0.1       InLoopBack0
      127.0.0.1/32  Direct  0    0           D   127.0.0.1       InLoopBack0
127.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0
255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0
[AR1]

[AR4]display  ip routing-table  
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 12       Routes : 12       

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

        2.2.2.2/32  OSPF    10   2           D   10.1.34.3       GigabitEthernet0/0/2
        3.3.3.3/32  OSPF    10   1           D   10.1.34.3       GigabitEthernet0/0/2
        4.4.4.4/32  Direct  0    0           D   127.0.0.1       LoopBack0
      10.1.12.0/24  OSPF    10   3           D   10.1.34.3       GigabitEthernet0/0/2
      10.1.23.0/24  OSPF    10   2           D   10.1.34.3       GigabitEthernet0/0/2
      10.1.34.0/24  Direct  0    0           D   10.1.34.4       GigabitEthernet0/0/2
      10.1.34.4/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/2
    10.1.34.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/2
      127.0.0.0/8   Direct  0    0           D   127.0.0.1       InLoopBack0
      127.0.0.1/32  Direct  0    0           D   127.0.0.1       InLoopBack0
127.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0
255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0
[AR4]

4.测试各IP地址连通。

[AR1]ping  4.4.4.4
  PING 4.4.4.4: 56  data bytes, press CTRL_C to break
    Reply from 4.4.4.4: bytes=56 Sequence=1 ttl=253 time=80 ms
    Reply from 4.4.4.4: bytes=56 Sequence=2 ttl=253 time=30 ms
    Reply from 4.4.4.4: bytes=56 Sequence=3 ttl=253 time=20 ms
    Reply from 4.4.4.4: bytes=56 Sequence=4 ttl=253 time=30 ms
    Reply from 4.4.4.4: bytes=56 Sequence=5 ttl=253 time=30 ms

  --- 4.4.4.4 ping statistics ---
    5 packet(s) transmitted
    5 packet(s) received
    0.00% packet loss
    round-trip min/avg/max = 20/38/80 ms

[AR1]ping 3.3.3.3
  PING 3.3.3.3: 56  data bytes, press CTRL_C to break
    Reply from 3.3.3.3: bytes=56 Sequence=1 ttl=254 time=20 ms
    Reply from 3.3.3.3: bytes=56 Sequence=2 ttl=254 time=30 ms
    Reply from 3.3.3.3: bytes=56 Sequence=3 ttl=254 time=40 ms
    Reply from 3.3.3.3: bytes=56 Sequence=4 ttl=254 time=30 ms
    Reply from 3.3.3.3: bytes=56 Sequence=5 ttl=254 time=50 ms

  --- 3.3.3.3 ping statistics ---
    5 packet(s) transmitted
    5 packet(s) received
    0.00% packet loss
    round-trip min/avg/max = 20/34/50 ms

[AR1]ping 2.2.2.2
  PING 2.2.2.2: 56  data bytes, press CTRL_C to break
    Reply from 2.2.2.2: bytes=56 Sequence=1 ttl=255 time=30 ms
    Reply from 2.2.2.2: bytes=56 Sequence=2 ttl=255 time=30 ms
    Reply from 2.2.2.2: bytes=56 Sequence=3 ttl=255 time=20 ms
    Reply from 2.2.2.2: bytes=56 Sequence=4 ttl=255 time=10 ms
    Reply from 2.2.2.2: bytes=56 Sequence=5 ttl=255 time=20 ms

  --- 2.2.2.2 ping statistics ---
    5 packet(s) transmitted
    5 packet(s) received
    0.00% packet loss
    round-trip min/avg/max = 10/22/30 ms

[AR1]ping 10.1.34.4
  PING 10.1.34.4: 56  data bytes, press CTRL_C to break
    Reply from 10.1.34.4: bytes=56 Sequence=1 ttl=253 time=40 ms
    Reply from 10.1.34.4: bytes=56 Sequence=2 ttl=253 time=30 ms
    Reply from 10.1.34.4: bytes=56 Sequence=3 ttl=253 time=20 ms
    Reply from 10.1.34.4: bytes=56 Sequence=4 ttl=253 time=30 ms
    Reply from 10.1.34.4: bytes=56 Sequence=5 ttl=253 time=30 ms

  --- 10.1.34.4 ping statistics ---
    5 packet(s) transmitted
    5 packet(s) received
    0.00% packet loss
    round-trip min/avg/max = 20/30/40 ms

[AR1]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

A_Puter

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值