1.OSPF支持两种类型的认证

-明文认证

-MD5认证

2.OSPF的认证分为 

-链路认证  -区域认证  -虚链路认证

3.认证分为两个部分

-开启认证   -出示密钥

 

我们通过实验来解析OSPF的各种认证问题,首先搭建如下拓扑:

 

OSPF的认证问题_OSPF认证问题

配置步骤如下

 

R1>en

R1#config

R1(config)#int lo 0

R1(config-if)#ip add 1.1.1.1 255.255.255.0

R1(config-if)#no shut

R1(config-if)#exit

R1(config)#int s1/0

R1(config-if)#ip add 12.1.1.1 255.255.255.0

R1(config-if)#no shut

R1(config-if)#int s1/1

R1(config-if)#ip add 13.1.1.1 255.255.255.0

R1(config-if)#no shut

R1(config-if)#exit

R1(config)#router ospf 100

R1(config-router)#net 1.1.1.0 0.0.0.255 area 0

R1(config-router)#net 12.1.1.10 0.0.0.255 area 0

R1(config-router)#net 13.1.1.0 0.0.0.255 area 2

R1(config-router)#exit

R1(config)#

 
R2>en
R2#config
R2(config)#int lo 0
R2(config-if)#ip add 2.2.2.2 255.255.255.0
R2(config-if)#no shut
R2(config-if)#exit
R2(config)#int s1/1
R2(config-if)#ip add 12.1.1.2 255.255.255.0
R2(config-if)#no shut
R2(config-if)#exit
R2(config)#int s1/0
R2(config-if)#ip add 24.1.1.1 255.255.255.0
R2(config-if)#no shut
R2(config-if)#exit
R2(config)#router ospf 100
R2(config-router)#net 24.1.1.0 0.0.0.255 area 1
R2(config-router)#net 12.1.1.0 0.0.0.255 area 0
R2(config-router)#net 2.2.2.0 0.0.0.255 area 0
R2(config-router)#exit
R2(config)#
 
 
R3>en
R3#config
R3(config)#int lo 0
R3(config-if)#ip add 3.3.3.3 255.255.255.0
R3(config-if)#no shut
R3(config-if)#exit
R3(config)#int s1/0
R3(config-if)#ip add 13.1.1.2 255.255.255.0
R3(config-if)#no shut
R3(config-if)#exit
R3(config)#int s1/1
R3(config-if)#ip add 35.1.1.1 255.255.255.0
R3(config-if)#no shut
R3(config-if)#exit
R3(config)#router ospf 100
R3(config-router)#net 3.3.3.0 0.0.0.255 area 2
R3(config-router)#net 13.1.1.0 0.0.0.255 area 2
R3(config-router)#net 35.1.1.0 0.0.0.255 area 3
R3(config-router)#exit
 
 
R4>en
R4#config
R4(config)#int lo 0
R4(config-if)#ip add 4.4.4.4 255.255.255.0
R4(config-if)#no shut
R4(config-if)#exit
R4(config)#int s1/0
R4(config-if)#ip add 24.1.1.2 255.255.255.0
R4(config-if)#no shut
R4(config-if)#exit
R4(config)#router ospf 100
R4(config-router)#net 4.4.4.0 0.0.0.255 area 1
R4(config-router)#net 24.1.1.0 0.0.0.255 area 1
R4(config-router)#exit
R4(config)#
 
R5>en
R5#config
R5(config)#int lo 0
R5(config-if)#ip add 5.5.5.5 255.255.255.0
R5(config-if)#no shut
R5(config-if)#exit
R5(config)#int s1/0
R5(config-if)#ip add 35.1.1.2 255.255.255.0
R5(config-if)#no shut
R5(config-if)#exit
R5(config)#router ospf 100
R5(config-router)#net 5.5.5.0 0.0.0.255 area 3
R5(config-router)#net 35.1.1.0 0.0.0.255 area 3
R5(config-router)#exit
R5(config)#
 
 
首先我们在 Area1上配置链路认证
 
R2(config)#int s1/0                                进入接口下
R2(config-if)#ip ospf authentication               开启OSPF明文认证
R2(config-if)#ip ospf authentication-key cisco     出示OSPF明文密钥
R2(config-if)#end
R2#clear ip  ospf process
Reset ALL OSPF processes? [no]: y                  清空OSPF进程让其重新建立邻居关系
R2#
*Jan  2 15:07:32.379: %OSPF-5-ADJCHG: Process 100, Nbr 1.1.1.1 on Serial1/1 from FULL to DOWN, Neighbor Down: Interface down or detached
*Jan  2 15:07:32.427: %OSPF-5-ADJCHG: Process 100, Nbr 4.4.4.4 on Serial1/0 from FULL to DOWN, Neighbor Down: Interface down or detached
*Jan  2 15:07:32.991: %OSPF-5-ADJCHG: Process 100, Nbr 1.1.1.1 on Serial1/1 from LOADING to FULL, Loading Done
 
                                                   OSPF邻居关系重新建立
 
R2#
*Jan  2 15:08:09.087: OSPF: Rcv pkt from 24.1.1.2, Serial1/0 : Mismatch Authentication Key - Clear Text
R2#no debug all
                                                     
                                                    提示R2和R4之间的认证密钥不匹配
 
此时我们继续在R4上进行相同配置
 
R4(config)#int s1/0
R4(config-if)#ip ospf authentication                开启认证
R4(config-if)#ip ospf authentication-key cisco      出示密钥
R4(config-if)#
*Jan  2 15:11:49.815: %OSPF-5-ADJCHG: Process 100, Nbr 2.2.2.2 on Serial1/0 from LOADING to FULL, Loading Done
R4(config-if)#exit                                  邻居关系建立成功
 
 
那么OSPF的链路明文认证就配置成功了,我们继续在 Area0 配置链路的MD5认证
 
 
R1(config)#int s1/0
R1(config-if)#ip  ospf  authentication message-digest    开启链路的MD5认证
 
R1(config-if)#ip ospf message-digest-key 
  <1-255>  Key ID
 
R1(config-if)#ip ospf message-digest-key 1               配置密钥序号(建议两端配置相同)
  md5  Use MD5 algorithm
 
R1(config-if)#ip ospf message-digest-key 1 md5 ?         密钥类型为MD5
  <0-7>  Encryption type (0 for not yet encrypted, 7 for proprietary)
  LINE   The OSPF password (key) (maximum 16 characters)
 
R1(config-if)#ip ospf message-digest-key 1 md5 cisco     密钥为cisco
 
R1#clear ip ospf process
Reset ALL OSPF processes? [no]: y                        清空OSPF进程,让邻居关系重新建                                                          立
R1#
*Jan  2 15:17:17.903: %OSPF-5-ADJCHG: Process 100, Nbr 3.3.3.3 on Serial1/1 from FULL to DOWN, Neighbor Down: Interface down or detached
*Jan  2 15:17:18.387: %OSPF-5-ADJCHG: Process 100, Nbr 3.3.3.3 on Serial1/1 from LOADING to FULL, Loading Done
 
R1#debug ip ospf adj                                     跟踪查看OSPF邻居建立过程
OSPF adjacency events debugging is on
R1#debug ip ospf
*Jan  2 15:17:36.951: OSPF: Send with youngest Key 1
 
*Jan  2 15:17:44.007: OSPF: Rcv pkt from 12.1.1.2, Serial1/0 : Mismatch Authentication type. Input packet specified type 0, we use type 2
 
                                                         提示认证不匹配
 
那么此时我们在R2上进行相同的配置
 
 
R2(config)#int s1/1
R2(config-if)#ip ospf authen
R2(config-if)#ip ospf authentication mess
R2(config-if)#ip ospf authentication message-digest
R2(config-if)#ip ospf mess
R2(config-if)#ip ospf message-digest-key 1 md5 cisco
*Jan  2 15:21:02.667: %OSPF-5-ADJCHG: Process 100, Nbr 1.1.1.1 on Serial1/1 from     LOADING to FULL, Loading Done
                                                         此时我们发现邻居关系已经成功的                                                          建立
 
到此OSPF的链路明文和MD5认证就介绍到这里.
 
 
我们继续介绍OSPF的虚链路认证
 
虚链路的明文认证
 
R1(config)#router ospf 100
R1(config-router)#area 2 virtual-link 3.3.3.3  authentication    开启虚链路认证
R1(config-router)#area 2 virtual-link 3.3.3.3 authentication-key cisco  出示虚链路认证                                                                         密钥
R1(config)#exit
 
 
在R3上进行同样的配置
 
R3(config)#router ospf 100
R3(config-router)#area 2 vir
R3(config-router)#area 2 virtual-link 1.1.1.1 authentication
R3(config-router)#area 2 virtual-link 1.1.1.1 authentication-key cisco
 
*Jan  2 15:41:08.423: %OSPF-5-ADJCHG: Process 100, Nbr 1.1.1.1 on OSPF_VL0 fro                                            m LOADING to FULL, Loading Done
 
此时虚链路明文认证建立成功,邻居关系建立成功
 
 
虚链路MD5认证配置也很简单

 

R3(config-router)#area 2 virtual-link 1.1.1.1 message-digest-key 1 md5 cisco

R3(config-router)#area 2 virtual-link 1.1.1.1 authentication message-digest

R1(config-router)#area 2 virtual-link 3.3.3.3 message-digest-key 1 md5 cisco

R1(config-router)#area 2 virtual-link 3.3.3.3 authentication message-digest

 

OSPF的区域认证配置

 

R3(config)#router ospf 100

R3(config-router)#area 3 authentication              开启区域认证

R3(config-router)#exit

R3(config)#int s1/1

R3(config-if)#ip ospf authentication-key cisco       出示区域认证密钥

在路由器R3和R5之间配置区域认证,在OSPF进程下开启认证,在属于相应区域的接口上配置密钥

 

继续在R5上进行相同的操作

R5(config)#router ospf 100

R5(config-router)#area 3 authentication

R5(config-router)#exit

R5(config)#int s1/0

R5(config-if)#ip ospf au

R5(config-if)#ip ospf authentication-key cisco

*Jan  2 16:09:06.455: %OSPF-5-ADJCHG: Process 100, Nbr 3.3.3.3 on Serial1/0 from LOADING to FULL, Loading Done

R5(config-if)#                          邻居关系建立成功

 

 

OSPF区域的MD5认证配置方法

1.在OSPF进程下开启区域认证

 area 0 authentication message-digest

2.在属于欲配置认证的区域的接口上配置密文密码

  ip ospf message-digest-key 1 md5  cisco

 

OSPF的区域认证配置成功