一、 拓扑。
实验要求:
1. OSPF的基本配置。
2. OSPF的优先级“DR选举”。
3. OSPF的虚链路。
4. OSPF的邻居认证。
5. OSPF的hello、dead time时间修改。
二、 实验。
1. OSPF的基本配置。
R3做ABR,R3到R1为area 0,R3到R4为area 1.
R1配置:
interface FastEthernet0/0
ip address 192.168.1.1 255.255.255.0
duplex half
!
router ospf 1
router-id 1.1.1 .1
log-adjacency-changes
network 192.168.1.1 0.0.0 .0 area 0
!
R1#show ip route
C 192.168.1.0/24 is directly connected, FastEthernet0/0
O 192.168.2.0/24 [110/2] via 192.168.1.2, 00:06:38, FastEthernet0/0
O IA 192.168.3.0/24 [110/3] via 192.168.1.2, 00:05:23, FastEthernet0/0
R1#
R2配置:
interface FastEthernet0/0
ip address 192.168.1.2 255.255.255.0
duplex half
!
interface FastEthernet1/0
ip address 192.168.2.1 255.255.255.0
duplex auto
speed auto
!
R2#show ip route
C 192.168.1.0/24 is directly connected, FastEthernet0/0
C 192.168.2.0/24 is directly connected, FastEthernet1/0
O IA 192.168.3.0/24 [110/2] via 192.168.2.2, 00:07:24, FastEthernet1/0
R2#R2#show ip route
C 192.168.1.0/24 is directly connected, Serial1/0
C 192.168.2.0/24 is directly connected, Serial1/1
O IA 192.168.3.0/24 [110/128] via 192.168.2.2, 00:11:21, Serial1/1
R2#
R3配置:
interface FastEthernet0/0
ip address 192.168.3.1 255.255.255.0
duplex half
!
interface FastEthernet1/0
ip address 192.168.2.2 255.255.255.0
duplex auto
speed auto
!
router ospf 1
router-id 3.3.3 .3
log-adjacency-changes
network 192.168.2.2 0.0.0 .0 area 0
network 192.168.3.1 0.0.0 .0 area 1
!
R3#show ip route
O 192.168.1.0/24 [110/2] via 192.168.2.1, 00:10:07, FastEthernet1/0
C 192.168.2.0/24 is directly connected, FastEthernet1/0
C 192.168.3.0/24 is directly connected, FastEthernet0/0
R3#
R4配置:
interface FastEthernet0/0
ip address 192.168.3.2 255.255.255.0
duplex half
!
router ospf 1
router-id 4.4.4 .4
log-adjacency-changes
network 192.168.3.2 0.0.0 .0 area 1
!
R4#show ip route
O IA 192.168.1.0/24 [110/3] via 192.168.3.1, 00:11:12, FastEthernet0/0
O IA 192.168.2.0/24 [110/2] via 192.168.3.1, 00:11:12, FastEthernet0/0
C 192.168.3.0/24 is directly connected, FastEthernet0/0
R4#
从上面各个路由器的路由表可以看出,area1和area2可以相互学习的到,下面用ping命令从R1到R4测试。
R1#ping 192.168.3.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.3.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 76/117/176 ms
OK!!测试成功,OSPF基本配置完成。
2. OSPF的优先级,DR选举。
先说明下DR的选举过程:
路由器接口和邻居建立关系的时候,都认为自己是DR,如果无人反对,大概过40s此接口就成为DR。如果有对方接口和它竞争,则比接口优先级,优先级大的为DR。如果优先级相同,则比路由ID,路由ID大的就为DR。如果无路由ID,则比loop口的IP,IP大的就为DR。如果连loop口也没有,则比物理口IP,大的为DR。
下面在R1上看邻居关系:
可以看到邻居的路由ID为 2.2.2 .2,优先级为1,并且对方为DR。如果想把R1做为DR,那么第一个想到的就是改端口优先级。
先看下R1的F0/0端口情况:
R1#show ip ospf int f0/0
FastEthernet0/0 is up, line protocol is up
Internet Address 192.168.1.1/24, Area 0
Process ID 1, Router ID 1.1.1 .1, Network Type BROADCAST, Cost: 1
Transmit Delay is 1 sec, State BDR, Priority 1
Designated Router (ID) 2.2.2 .2, Interface address 192.168.1.2
Backup Designated router (ID) 1.1.1 .1, Interface address 192.168.1.1
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
oob-resync timeout 40
Hello due in 00:00:06
Index 1/1, flood queue length 0
Next 0x0(0)/0x0(0)
Last flood scan length is 1, maximum is 1
Last flood scan time is 0 msec, maximum is 4 msec
Neighbor Count is 1, Adjacent neighbor count is 1
Adjacent with neighbor 2.2.2 .2 (Designated Router)
Suppress hello for 0 neighbor(s)
R1#
上面可以看出,优先级和R2的F0/0一样大,但route id没人家的大,所以人家理所当然就是DR,下面通过改R1的F0/0端口优先级来手工指定R1为DR。
R1(config)#int f0/0
R1(config-if)#ip ospf priority 255
然后在特权模式下用命令:clear ip ospf process,清除他们的进程,使它们从新建立邻居关系,并从新选举DR。
然后在R1上再看他们的邻居关系:
在R2上看它和R1的邻居关系:
上面可以看出R1为变成了DR,并且优先级为最大255。
3. OSPF虚链路。
现在把上面的拓扑稍改一下,R1和R2为area 0,R2和R3为area 1,R3和R4为area 2。
我们知道OSPF所有的非骨干区都必须和骨干区连接。修改后area 2没有和area 0直接连接,那么它也不会学到area 0的路由信息,这种情况可以在R2和R3上面建立一条虚链路,是area 2和area 0能够互相通信。
R2配置:
R2(config)#router ospf 1
R2(config-router)#area 1 virtual-link 3.3.3 .3
R3配置:
R3(config)#router ospf 1
R3(config-router)#area 1 virtual-link 2.2.2 .2
虚链路配好后看R4的路由表信息:
R4#show ip route
O IA 192.168.1.0/24 [110/3] via 192.168.3.1, 00:00:42, FastEthernet0/0
O IA 192.168.2.0/24 [110/2] via 192.168.3.1, 00:00:51, FastEthernet0/0
C 192.168.3.0/24 is directly connected, FastEthernet0/0
可以看到R4已经学到area 0区域的信息。
4. OSPF的邻居认证。
OSPF支持明文和密文两种认证,明文就别说了,太不安全,下面在R1和R2上作MD5的密文认证。
R1配置:
R1(config)#router ospf 1
R1(config-router)#area 0 authentication message-digest
先在area 0上启用MD5的认证。
然后在F0/0的端口上配置密码和密钥:
R1(config)#int f0/0
R1(config-if)#ip ospf authentication-key 5 md5 369
对端R2的F0/0上也做相同配置,如果一端配置,一端不配置,双方是学不到路由信息的。
5. OSPF的hello/dead time修改。
在广播型多路访问网络中,OSPF路由默认hello时间是10s,dead时间是hello的4倍,40s。
首先看R1的F0/0端口hello时间和dead时间:
R1#show ip ospf int f0/0
FastEthernet0/0 is up, line protocol is up
Internet Address 192.168.1.1/24, Area 0
Process ID 1, Router ID 1.1.1 .1, Network Type BROADCAST, Cost: 1
Transmit Delay is 1 sec, State DR , Priority 255
Designated Router (ID) 1.1.1 .1, Interface address 192.168.1.1
No backup designated router on this network
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
oob-resync timeout 40
Hello due in 00:00:03
Index 1/1, flood queue length 0
Next 0x0(0)/0x0(0)
Last flood scan length is 0, maximum is 5
Last flood scan time is 0 msec, maximum is 4 msec
Neighbor Count is 0, Adjacent neighbor count is 0
Suppress hello for 0 neighbor(s)
Message digest authentication enabled
No key configured, using default key id 0
下面修改R2的hello时间,然后看R1和R2能否建立邻居关系:
R2(config)#int f0/0
R2(config-if)#ip ospf hello-interval 15
R2#show ip ospf int f0/0
FastEthernet0/0 is up, line protocol is up
Internet Address 192.168.1.2/24, Area 0
Process ID 1, Router ID 2.2.2 .2, Network Type BROADCAST, Cost: 1
Transmit Delay is 1 sec, State DR , Priority 1
Designated Router (ID) 2.2.2 .2, Interface address 192.168.1.2
No backup designated router on this network
Timer intervals configured, Hello 15, Dead 60, Wait 60, Retransmit 5
oob-resync timeout 60
Hello due in 00:00:11
Index 1/1, flood queue length 0
Next 0x0(0)/0x0(0)
Last flood scan length is 0, maximum is 2
Last flood scan time is 0 msec, maximum is 4 msec
Neighbor Count is 0, Adjacent neighbor count is 0
Suppress hello for 0 neighbor(s)
Message digest authentication enabled
No key configured, using default key id 0
Dead时间是随hello时间改变的,然后在R2上看R1和R2的邻居关系:
可以看出hello时间不一样,是建立不起来邻居关系滴!!
然后把R1的hello时间改的和R2一样,再看他们的邻居关系:
R1(config)#int f0/0
R1(config-if)#ip ospf hello-interval 15
把R1的hello时间改过后,它们又恢复了邻居关系,看来OSPF的路由器要建立邻居关系,hello时间是必须要相同的。
Hello时间如果不匹配不能建立邻居关系,那么dead时间不匹配能否建立邻居关系哪?做个试验就知道了!
首先把R1 的dead时间改为hello时间的5倍,75s,R2的不变,看他们能否建立邻居:
R1(config)#int f0/0
R1(config-if)#ip ospf dead-interval 75
在R2上看能否建立邻居关系:
可以看出是不能建立邻居关系的,既然改大不能建立,那么把dead时间改小看能否建立邻居关系:
R1(config)#int f0/0
R1(config-if)#ip ospf dead-interval 45
再在R2上看邻居关系:
可以看到还是不能建立,那么把两端的dead时间改的相等看能否建立邻居关系:
R2(config)#int f0/0
R2(config-if)#ip ospf dead-interval 45
然后看邻居关系:
已经建立,得出结论:
OSPF路由器建立邻居关系条件:1.hello是时间必须相同
2.dead是时间必须相同
3.dead是时间不一定是hello时间的4倍。