实验拓扑

单区域OSPF协议的配置 单区域ospf配置命令_R3


实验需求

目前公司网络需要使用OSPF协议来进行路由信息的传递。规划网络中所有路由器属于OSPF的区域。通过这次部署需要了解DR/BDR选举机制以及Router-id机制。

实验配置

目前公司网络需要使用OSPF协议来进行路由信息的传递。规划网络中所有路由器属于OSPF的区域。通过这次部署需要了解DR/BDR选举机制以及Router-id机制。

三:实验配置:

1:按照实验拓扑配置IP地址。

2:配置OSPF进程并且设置router-id

[R1]ospf 1
[R1-ospf-1]area 0
 [R1-ospf-1-area-0.0.0.0]network 192.168.1.0 0.0.0.255
 [R1-ospf-1-area-0.0.0.0]network 1.1.1.1 0.0.0.0
手工设置router-id:
(1)设置全局router-id:
[R1]router id 100.1.1.1
(2)设置进程router-id:
[R1]ospf 1 router-id11.1.1.1
进程router-id优于全局router-id
手工设置router-id须在启用进程之前,否则需要重启路由器或者路由进程。
[R1]ospf 1 router-id 11.1.1.1
Info: The configuration succeeded. You needto restart the OSPF process to validate the new router ID.
3:全部配置完成后查看ospf之间邻居关系
[R1]display ospf peer brief
 OSPF Process 1 with Router ID 192.168.1.1
 Peer Statistic Information
 ---------------------------------------------------------------------
 AreaId Interface Neighbor id State 
 0.0.0.0 GigabitEthernet0/0/0 192.168.1.2 Full 
 0.0.0.0 GigabitEthernet0/0/0 192.168.1.3 Full 
 ---------------------------------------------------------------------
Full状态为完全邻接关系。看到此状态说明邻居正常建立。
通过display ospf peer可以看到192.168.1.1为网络中的DR,192.168.1.2为网络中的BDR
[R1]display ospf peer
 OSPF Process 1 with RouterID 192.168.1.1
 Neighbors
 Area 0.0.0.0 interface192.168.1.1(GigabitEthernet0/0/0)'s neighbors
 Router ID: 192.168.1.2 Address: 192.168.1.2 
 State: Full Mode:Nbr is Master Priority: 1
 DR: 192.168.1.1 BDR: 192.168.1.2 MTU: 0 
 Dead timer due in 40 sec
 Retrans timer interval: 5
 Neighbor is up for 00:04:46 
 Authentication Sequence: [ 0 ]
 Router ID: 192.168.1.3 Address: 192.168.1.3 
 State: Full Mode:Nbr is Master Priority: 1
 DR: 192.168.1.1 BDR: 192.168.1.2 MTU: 0 
 Dead timer due in 36 sec
 Retrans timer interval: 5
 Neighbor is up for 00:04:26 
 Authentication Sequence: [ 0 ]
4:设置ospf接口优先级,验证ospf非抢占原则
[R3]int g0/0/0
 [R3-GigabitEthernet0/0/0]ospf dr-priority 100
将R3优先级设置为100,查看DR身份是否发生变化。
[R1]display ospf peer
 OSPF Process 1 with RouterID 192.168.1.1
 Neighbors
 Area 0.0.0.0 interface192.168.1.1(GigabitEthernet0/0/0)'s neighbors
 Router ID: 192.168.1.2 Address: 192.168.1.2 
 State: Full Mode:Nbr is Master Priority: 1
 DR: 192.168.1.1 BDR: 192.168.1.2 MTU: 0 
 Dead timer due in 39 sec
 Retrans timer interval: 5
 Neighbor is up for 00:20:51 
 Authentication Sequence: [ 0 ]
可以看到DR和BDR身份并没有发生变化。
[R1]int g0/0/0
 [R1-GigabitEthernet0/0/0]shutdown
将R1接口关闭掉,看DR和BDR身份的切换。
[R3-ospf-1-area-0.0.0.0]displayospf peer
 OSPF Process 1 with RouterID 192.168.1.3
 Neighbors
 Area 0.0.0.0 interface192.168.1.3(GigabitEthernet0/0/0)'s neighbors
 Router ID: 192.168.1.2 Address: 192.168.1.2 
 State: Full Mode:Nbr is Slave Priority: 1
 DR: 192.168.1.2 BDR: 192.168.1.3 MTU: 0 
 Dead timer due in 34 sec
 Retrans timer interval: 5
 Neighbor is up for 00:00:11 
 Authentication Sequence: [ 0 ]

可以看到R2从BDR直接切换为DR,R3作为网络中的BDR


单区域OSPF协议的配置 单区域ospf配置命令_OSPF_02


5:设置OSPF开销

OSPF基于接口带宽计算开销,计算公式为:接口开销=带宽参考值÷带宽。带宽参考值可配置,缺省为100Mbit/s。因此,一个64kbit/s串口的开销为1562,一个E1接口(2.048 Mbit/s)的开销为48。

命令bandwidth-reference可以用来调整带宽参考值,从而可以改变接口开销,带宽参考值越大,开销越准确。在支持10Gbit/s速率的情况下,推荐将带宽参考值提高到10000Mbit/s来分别为10 Gbit/s、1Gbit/s和100Mbit/s的链路提供1、10和100的开销。注意,配置带宽参考值时,需要在整个OSPF网络中统一进行调整。

另外,还可以通过ospfcost命令来手动为一个接口调整开销,开销值范围是1~65535,缺省值为1。

[R1]interfaceGigabitEthernet 0/0/0
[R1- GigabitEthernet0/0/0]ospf cost 20
[R2]ospf
[R2-ospf-1]bandwidth-reference10000

6:ospf认证

OSPF支持简单认证及加密认证功能,加密认证对潜在的攻击行为有更强的防范性。OSPF认证可以配置在接口或区域上,配置接口认证方式的优先级高于区域认证方式。

接口或区域上都可以运行ospf authentication-mode { simple[ [plain ] <plain-text> | cipher <cipher-text>]| null } 命令来配置简单认证,参数plain表示使用显示密码,参数cipher表示使用密文密码,参数null表示不认证。

命令ospfauthentication-mode { md5| hmac-md5 } [ key-id {plain <plain-text >|[ cipher ] <cipher-text>} ] 用于配置加密认证,MD5是一种保证链路认证安全的加密算法(具体配置已在举例中给出),参数key-id表示接口加密认证中的认证密钥ID,它必须与对端上的key-id一致。

在接口上使用加密认证功能:

[R1]int g0/0/0
 [R1-GigabitEthernet0/0/0]ospfauthentication-mode md5 1 ciphershangwen

只在R1上配置认证,发现R1的邻居表清空,没有任何邻居关系。


单区域OSPF协议的配置 单区域ospf配置命令_ci_03


R2与R3配置认证后,邻居关系正常建立。


单区域OSPF协议的配置 单区域ospf配置命令_ospf配置命令_04


单区域OSPF协议的配置 单区域ospf配置命令_OSPF_05