ccnp.ospf认证_休闲
实验目的:
  1、了解ospf的认证方式
  2、掌握ospf的认证方法
 
 
一,路由器基本配置,接口地址配置,OSPF配置
Router>en
Router#conf t
Router(config)#no ip do lo
Router(config)#lin con 0
Router(config-line)#exec-ti 0 0
Router(config-line)#logg sy
Router(config-line)#exit
Router(config)#hos R1
R1(config)#int lo 0
R1(config-if)#ip add 10.1.1.1 255.255.255.0
R1(config-if)#ip ospf net point-to-p
R1(config-if)#int lo 1
R1(config-if)#ip add 10.1.2.1 255.255.255.0
R1(config-if)#ip ospf net point-to-p
R1(config-if)#int s1/1
R1(config-if)#ip add 192.168.1.1 255.255.255.252
R1(config-if)#no sh
R1(config-if)#router ospf 100
R1(config-router)#router-id 1.1.1.1
R1(config-router)#net 192.168.1.1 0.0.0.0 a 1
R1(config-router)#net 10.1.1.1 0.0.0.0 a 1  
R1(config-router)#net 10.1.2.1 0.0.0.0 a 1
R1(config-router)#exit
R1(config)#end
R1#
 
Router>en
Router#conf t
Router(config)#no ip do lo
Router(config)#lin con 0
Router(config-line)#exec-ti 0 0
Router(config-line)#logg sy
Router(config-line)#exit
Router(config)#hos R2
R2(config)#int s1/0
R2(config-if)#ip add 192.168.1.2 255.255.255.252
R2(config-if)#no sh
R2(config-if)#cl ra 64000
R2(config-if)#int s1/1
R2(config-if)#ip add 192.168.1.5 255.255.255.252
R2(config-if)#no sh
R2(config-if)#router ospf 100
R2(config-router)#router-id 2.2.2.2
R2(config-router)#net 192.168.1.2 0.0.0.0 a 1
R2(config-router)#net 192.168.1.5 0.0.0.0 a 0
R2(config-router)#exit
R2(config)#end
R2#
 
Router>en
Router#conf t
Router(config)#no ip do lo
Router(config)#lin con 0
Router(config-line)#exec-ti 0 0
Router(config-line)#logg sy
Router(config-line)#exit
Router(config)#hos R3
R3(config)#int s1/0
R3(config-if)#ip add 192.168.1.6 255.255.255.252
R3(config-if)#no sh
R3(config-if)#cl ra 64000
R3(config-if)#int s1/1
R3(config-if)#ip add 192.168.1.9 255.255.255.252
R3(config-if)#no sh
R3(config-if)#router ospf 100
R3(config-router)#router-id 3.3.3.3
R3(config-router)#net 192.168.1.6 0.0.0.0 a 0
R3(config-router)#net 192.168.1.9 0.0.0.0 a 2
R3(config-router)#exit
R3(config)#^Z
R3#
 

Router>en
Router#conf t
Router(config)#lin con 0
Router(config-line)#exec-ti 0 0
Router(config-line)#logg sy
Router(config-line)#exit
Router(config)#no ip do lo
Router(config)#hos R4
R4(config)#int lo 0
R4(config-if)#ip add 172.16.1.1 255.255.255.0
R4(config-if)#ip ospf net point-to-p
R4(config-if)#int lo 1
R4(config-if)#ip add 172.16.2.1 255.255.255.0
R4(config-if)#ip ospf net point-to-p
R4(config-if)#int s1/0
R4(config-if)#ip add 192.168.1.10 255.255.255.252
R4(config-if)#cl ra 64000
R4(config-if)#no sh
R4(config-if)#router ospf 100
R4(config-router)#router-id 4.4.4.4
R4(config-router)#net 192.168.1.10 0.0.0.0 a 2
R4(config-router)#net 172.16.1.1 0.0.0.0 a 2
R4(config-router)#net 172.16.2.1 0.0.0.0 a 2
R4(config-router)#exit
R4(config)#
 
二、测试连通性
R1#p 172.16.1.1 so lo 0
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.1.1, timeout is 2 seconds:
Packet sent with a source address of 10.1.1.1
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 24/37/56 ms
R1#p 172.16.2.1 so lo 1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.2.1, timeout is 2 seconds:
Packet sent with a source address of 10.1.2.1
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 24/38/60 ms
R1#
 
三、配置ospf的认证
  OSPF的认证有两种方式:接口认证和区域认证。每种认证方式又分为明文认证和MD5密文认证,首先使用接口认证方式下的明文认证
  1、接口认证--明文(R1R2之间)
首先在R2上开启debug信息
R2#debug ip ospf adj
 
R1(config)#int s1/1
R1(config-if)#ip ospf authentication
 
这里只是在s1/1口上启用认证,并没有配置认证密钥,所以R2上的debug信息返回,邻居关系down,原因是认证类型不匹配
R2#
00:36:06: OSPF: Rcv pkt from 192.168.1.1, Serial1/0 : Mismatch Authentication type. Input packet specified type 1, we use type 0
type 2=MD5认证方式  type 1=明文认证 type 0=null 不认证
如果只配置了认证密钥,而不调用认证的话,则邻居关系不会down
首先我们取消明文认证,然后在R1s1/1口只配置认证密钥而不调用认证
R1(config-if)#no ip ospf authentication--调用认证(明文)
R1(config-if)#ip ospf authentication-key cisco---设置认证密钥(明文)
可以发现R2没有任何debug信息输出,如果此时在R1的接口上调用密钥的话,则邻居关系会down,但是仍然提示认证方式不匹配
R1(config-if)#ip ospf authentication
 
R2#
01:37:46: OSPF: Rcv pkt from 192.168.1.1, Serial1/0 : Mismatch Authentication type. Input packet specified type 1, we use type 0---
认证类型不匹配
01:37:46: %OSPF-5-ADJCHG: Process 100, Nbr 1.1.1.1 on Serial1/0 from FULL to DOWN, Neighbor Down: Dead timer expired--
死亡时间超时后,邻居关系down
 
这是如果在R2上配置认证类型为明文而不设置密钥的话,则认证类型匹配,但是提示密钥不匹配
R2(config)#int s1/0
01:41:26: OSPF: Rcv pkt from 192.168.1.1, Serial1/0 : Mismatch Authentication type. Input packet specified type 1, we use type 0----
没调用认证之前提示认证类型不匹配
R2(config-if)#ip ospf authentication---
调用认证
01:41:36: OSPF: Rcv pkt from 192.168.1.1, Serial1/0 : Mismatch Authentication Key - Clear Text---
调用认证后,提示认证密钥不匹配
 
配置认证密钥后邻居关系成功建立
R2(config)#int s1/0
R2(config-if)#ip ospf au
R2(config-if)#ip ospf authentication-
R2(config-if)#ip ospf authentication-key cisco
R2(config-if)#
01:49:06: %OSPF-5-ADJCHG: Process 100, Nbr 1.1.1.1 on Serial1/0 from LOADING to FULL, Loading Done
 
  2、接口的MD5认证(R2R3之间)
R2s1/1口启用MD5认证,但不配置认证密钥
R2(config-if)#ip ospf authentication message-digest
R3开启debug后输出为认证类型不匹配,R2使用type 2 R3type 0
R3#debug ip ospf adj
01:50:43: OSPF: Rcv pkt from 192.168.1.5, Serial1/0 : Mismatch Authentication type. Input packet specified type 2, we use type 0
 
R2配置一个MD5认证密钥,R3启用MD5认证
R2(config-if)#no  ip ospf authentication message-digest ---关闭ospf的接口认证
R2(config-if)#
01:54:03: %OSPF-5-ADJCHG: Process 100, Nbr 3.3.3.3 on Serial1/1 from LOADING to FULL, Loading Done---
邻居关系重新建立
 
R2(config-if)#ip ospf message-digest-key 1 md5 cisco
R2(config-if)#ip ospf message-digest-key 2 md5 hahaha ---R2上创建2MD5认证密钥
 
R2# sh ip ospf neighbor -----邻居关系正常
Neighbor ID     Pri   State           Dead Time   Address         Interface
3.3.3.3           1   FULL/  -        00:00:39    192.168.1.6     Serial1/1
 
R2(config-if)#ip ospf authentication message-digest---接口调用md5认证
R3#
02:00:23: OSPF: Rcv pkt from 192.168.1.5, Serial1/0 : Mismatch Authentication type. Input packet specified type 2, we use type 0
02:00:23: %OSPF-5-ADJCHG: Process 100, Nbr 2.2.2.2 on Serial1/0 from FULL to DOWN, Neighbor Down: Dead timer expired--R3
报告认证类型不匹配,死亡时间超时后,邻居关系down
 
R3(config-if)#ip ospf authentication message-digest
02:06:40: OSPF: Send with youngest Key 0
02:06:43: OSPF: Rcv pkt from 192.168.1.5, Serial1/0 : Mismatch Authentication Key - No message digest key 2 on interface---R3
只调用不设密钥,提示认证密钥不匹配,并且,R3R2只验证key 2的成功与否,因为key 2是密钥中youngest(最新的)
 
R3(config-if)#ip ospf message-digest-key 1 md5 cisco--R3上只启用key 1
 
R3#sh ip ospf neighbor
Neighbor ID     Pri   State           Dead Time   Address         Interface
2.2.2.2           1   FULL/  -        00:00:30    192.168.1.5     Serial1/0
R3(config-if)#
02:28:13: OSPF: Rcv pkt from 192.168.1.5, Serial1/0 : Mismatch Authentication Key - No message digest key 2 on interface---
邻居可以建立因为有key相匹配,但是R2R3之间仍然提示,key2不匹配,表明R2R3之间只要有key匹配就可以建立邻居关系,但是他们会尽量使用最新的key建立邻居
 
R3(config-if)#ip ospf message-digest-key 2 md5 hahaha--R3上启用key 2

02:29:20: OSPF: Send with youngest Key 2---
之后R3只会发送最新的key,这样可以保证邻居关系在不down的情况下更新密钥
 
  3、区域明文认证(area 2
区域认证的基本方式是,在ospf进程中对区域调用认证,然后在路由器属于这个认证区域的所有需要发送hello的接口上设置认证密钥,一些不希望发送hello的接口没有必要配置,如环回口,末节路由器的下游接口,passive-interface接口
R3(config)#router ospf 100
R3(config-router)#area 2 authentication ---ospf
进程下调用区域认证
R3(config-router)#int s1/1
R3(config-if)#ip ospf authentication-key cisco--
属于这个认证区域接口上设置认证密钥
  
同接口认证一样,R4先是报告认证类型不匹配,在配置了区域明文认证后,报告认证密钥不匹配,配置认证密钥后,邻居关系建立
R4#
02:47:08: OSPF: Rcv pkt from 192.168.1.9, Serial1/0 : Mismatch Authentication type. Input packet specified type 1, we use type 0--调用认证前提示认证类型不匹配
R4#conf t
R4(config)#router ospf 100
R4(config-router)#area 2 authentication
02:47:28: OSPF: Rcv pkt from 192.168.1.9, Serial1/0 : Mismatch Authentication Key - Clear Text--
调用认证后,提示认证密钥不匹配
R4(config-router)#int s1/0
R4(config-if)#ip ospf authentication-key cisco
R4(config-if)#
02:47:53: %OSPF-5-ADJCHG: Process 100, Nbr 3.3.3.3 on Serial1/0 from LOADING to FULL, Loading Done --设置认证密钥后,邻居关系正常建立
 
  4、区域MD5认证(area 2
首先删除area 2的明文认证
R3(config-router)#no area 2 authentication
R3(config-if)#no ip ospf authentication-key cisco
 
R4(config-router)#no area 2 authentication
R4(config-if)#no ip ospf authentication-key cisco
 
区域的md5认证原理同接口,这里只介绍配置过程
R3(config-router)#area 2 authentication message-digest
R3(config-router)#int s1/1
R3(config-if)#ip ospf message-digest-key 1 md5 cisco
R3(config-if)#ip ospf message-digest-key 2 md5 hahaha--R4
提示认证类型不匹配
 
R4(config-router)#area 2 authentication message-digest --R4提示认证密钥不匹配
 
R4(config-if)#int s1/0
R4(config-if)#ip ospf message-digest-key 1 md5 cisco--
只设置key 1 ,邻居关系可以建立,仍然企望key2匹配
R4(config-if)#ip ospf message-digest-key 2 md5 hahaha--设置R2后,邻居关系建立在最新的密钥上