配置过程如下:
一.先配置好pc0和pc1的IP地址,网关地址。
二.配置三个路由器各个接口的IP地址,并启用:
Router0:
Router#conf t
Router(config)#hostname r0
r0(config)#interface fa0/0
r0(config-if)#ip address 192.168.1.2 255.255.255.0
r0(config-if)#no shut
r0(config-if)#int fa0/1
r0(config-if)#ip add 192.168.2.1 255.255.255.0
r0(config-if)#no shut
Router1:
Router>en
Router#conf t
Router(config)#hostname r1
r1(config)#int fa0/0
r1(config-if)#ip address 192.168.2.2 255.255.255.0
r1(config-if)#no shut
r1(config-if)#int fa 0/1
r1(config-if)#ip add 192.168.3.1 255.255.255.0
r1(config-if)#no shut
Router2:
Router>en
Router#conf t
Router(config)#hostname r2
r2(config)#int fa0/0
r2(config-if)#ip add 192.168.3.2 255.255.255.0
r2(config-if)#no shut
r2(config-if)#int fa0/1
r2(config-if)#ip add 192.168.4.1 255.255.255.0
r2(config-if)#no shut
三.在三个路由器上分别启用OSPF协议:
Router0:
r0(config-if)#router OSPF 1
//1表示的是路由器上运行的不同的OSPF进程号,不需要和其他路由器上的进程号相同。
r0(config-router)#network 192.168.1.0 0.0.0.255 area 0
//指示路由器的哪些接口运行在哪个区域内,目前还是单域实验,所以所有的接口都运行在同一个area里面,此处都运行在area 0中。
r0(config-router)#network 192.168.2.0 0.0.0.255 area 0
Router1:
r1(config)#router OSPF 2
r1(config-router)#network 192.168.3.0 0.0.0.255 area 0
r1(config-router)#network 192.168.2.0 0.0.0.255 area 0
Router2:
r2(config)#router OSPF 3
r2(config-router)#network 192.168.3.0 0.0.0.255 area 0
r2(config-router)#network 192.168.4.0 0.0.0.255 area 0
四.检查OSPF的运行:
1.pc0 ping pc4:
2.pc4 ping pc0:
3.
r0#show ip protocols
Routing Protocol is "OSPF 1" //路由器上运行OSPF协议,进程号1
Outgoing update filter list for all interfaces is not set
Incoming update filter list for all interfaces is not set
Router ID 192.168.2.1 //本路由器ID
Number of areas in this router is 1. 1 normal 0 stub 0 nssa
Maximum path: 4 //最多支持4条等值路由
Routing for Networks:
192.168.1.0 0.0.0.255 area 0
192.168.2.0 0.0.0.255 area 0
Routing Information Sources:
Gateway Distance Last Update
192.168.2.2 110 00:01:52
Distance: (default is 110) //OSPF默认管理距离为110
4.
r0#show ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route
Gateway of last resort is not set
C 192.168.1.0/24 is directly connected, FastEthernet0/0
C 192.168.2.0/24 is directly connected, FastEthernet0/1
O 192.168.3.0/24 [110/2] via 192.168.2.2, 00:02:54, FastEthernet0/1
O 192.168.4.0/24 [110/3] via 192.168.2.2, 00:02:54, FastEthernet0/1
5.
r0#show ip OSPF neighbor
Neighbor ID Pri State Dead Time Address Interface
192.168.3.1 1 FULL/BDR 00:00:36 192.168.2.2 FastEthernet0/1 //显示出r2被选举成为了BDR
6.
r0#show ip OSPF interface
FastEthernet0/0 is up, line protocol is up
Internet address is 192.168.1.2/24, Area 0
Process ID 1, Router ID 192.168.2.1, Network Type BROADCAST, Cost: 1
Transmit Delay is 1 sec, State DR, Priority 1
Designated Router (ID) 192.168.2.1, Interface address 192.168.1.2
No backup designated router on this network
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
Hello due in 00:00:09
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 0 msec
Neighbor Count is 0, Adjacent neighbor count is 0
Suppress hello for 0 neighbor(s)
FastEthernet0/1 is up, line protocol is up
Internet address is 192.168.2.1/24, Area 0
Process ID 1, Router ID 192.168.2.1, Network Type BROADCAST, Cost: 1
Transmit Delay is 1 sec, State DR, Priority 1
Designated Router (ID) 192.168.2.1, Interface address 192.168.2.1
Backup Designated Router (ID) 192.168.3.1, Interface address 192.168.2.2
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
Hello due in 00:00:06
Index 2/2, 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 0 msec
Neighbor Count is 1, Adjacent neighbor count is 1
Adjacent with neighbor 192.168.2.2 (Backup Designated Router)
Suppress hello for 0 neighbor(s)
7.使用show ip OSPF database命令查看路由器的OSPF链路状态数据库
r0#show ip OSPF database
OSPF Router with ID (192.168.2.1) (Process ID 1)
Router Link States (Area 0)
Link ID ADV Router Age Seq# Checksum Link count
192.168.4.1 192.168.4.1 623 0x80000003 0x005cbe 2
192.168.2.1 192.168.2.1 612 0x80000003 0x0034f1 2
192.168.3.1 192.168.3.1 612 0x80000004 0x00b6fa 2
Net Link States (Area 0)
Link ID ADV Router Age Seq# Checksum
192.168.3.2 192.168.4.1 623 0x80000001 0x001c4a
192.168.2.1 192.168.2.1 612 0x80000001 0x004e5b
实验总结:OSPF能够解决许多距离矢量型路由协议所不能解决的问题,适用于大型网络,但它的这些特点也为OSPF协议的网络带来了复杂性,现在只是OSPF协议在单域环境下的运行,多域环境下会更复杂的。