router0:
Router>en
Router#conf t
Router(config)#int fastEthernet 0/0
Router(config-if)#ip add 192.168.1.1 255.255.255.0
Router(config-if)#no shutdown
Router(config-if)#int s2/0
Router(config-if)#ip add 10.0.0.1 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#clock rate 64000
router1:
Router>en
Router#conf t
Router(config)#int fastEthernet 0/0
Router(config-if)#ip add 192.168.2.1 255.255.255.0
Router(config-if)#no shutdown
Router(config-if)#int s2/0
Router(config-if)#ip add 10.0.0.2 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#int s3/0
Router(config-if)#ip add 20.0.0.1 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#clock rate 64000
router2:
Router>en
Router#conf t
Router(config)#int fastEthernet 0/0
Router(config-if)#ip add 192.168.3.1 255.255.255.0
Router(config-if)#no shutdown
Router(config-if)#int s2/0
Router(config-if)#ip add 20.0.0.2 255.0.0.0
Router(config-if)#no shutdown

接下来我们就去配置OSPF:
其实配置OSPF只是配置与当前路由器相连的接口或接口的IP就可以了。
router0:
Router(config)#router ospf 1
router(config-router)#network 192.168.1.0 0.0.0.255 area 0 //这里的0.0.0.255是192.168.1.0的通配掩码,也就是说当它全为0时,就要进行所有检查也就是匹配,而全为1时,就忽略,我们的子网掩码是由32位二进制数组成,全为0时为0,全为1时为255。这里的0.0.0.255表示检查192.168.1这个网段,若想只检查到192.168这里,通配掩码就为0.0.255.255,依次类推......
router(config-router)#network 10.0.0.0 0.255.255.255 area 0

router1:
Router(config)#router ospf 2
router(config-router)#network 192.168.2.0 0.0.0.255 area 0
router(config-router)#network 10.0.0.0 0.255.255.255 area 0
router(config-router)#network 20.0.0.0 0.255.255.255 area 0

router2:
Router(config)#router ospf 3
router(config-router)#network 192.168.3.0 0.0.0.255 area 0
router(config-router)#network 20.0.0.0 0.255.255.255 area 0

这样我们就可以用192.168.1.2 PC机去与所有网段进行通信,接下来我们分别去查看路由表中所用的协议、OSPF、接口、相邻路由ID、邻居和邻接状态。
router0:
Router#show ip protocols //所使用的协议

Routing Protocol is "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.1.1
Number of areas in this router is 1. 1 normal 0 stub 0 nssa
Maximum path: 4
Routing for Networks:
192.168.1.0 0.0.0.255 area 0
10.0.0.0 0.255.255.255 area 0
Routing Information Sources:
Gateway Distance Last Update
10.0.0.2 110 00:02:14
Distance: (default is 110)

Router#show ip route ospf //路由表中有关OSPF的表项
O 20.0.0.0/8 [110/1562] via 10.0.0.2, 00:02:43, Serial2/0
O 192.168.2.0/24 [110/782] via 10.0.0.2, 00:02:43, Serial2/0
O 192.168.3.0/24 [110/1563] via 10.0.0.2, 00:02:15, Serial2/0

Router#show ip ospf interface //查看接口是否已经被配置到目标区域
FastEthernet0/0 is up, line protocol is up
Internet address is 192.168.1.1/24, Area 0
Process ID 1, Router ID 192.168.1.1, Network Type BROADCAST, Cost: 1
Transmit Delay is 1 sec, State DR, Priority 1
Designated Router (ID) 192.168.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
Hello due in 00:00:01
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)
Serial2/0 is up, line protocol is up
Internet address is 10.0.0.1/8, Area 0
Process ID 1, Router ID 192.168.1.1, Network Type POINT-TO-POINT, Cost: 781
Transmit Delay is 1 sec, State POINT-TO-POINT,
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
Hello due in 00:00:08
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 10.0.0.2
Suppress hello for 0 neighbor(s)

Router#show ip ospf database //查看链锯号和相邻路由器ID
OSPF Router with ID (192.168.1.1) (Process ID 1)

Router Link States (Area 0)

Link ID ADV Router Age Seq# Checksum Link count
192.168.1.1 192.168.1.1 201 0x80000003 0x00e967 3
192.168.2.1 192.168.2.1 184 0x80000005 0x00d5a1 5
192.168.3.1 192.168.3.1 184 0x80000003 0x001026 3

Router#show ip ospf neighbor //查看关于邻居和邻接状态的信息
Neighbor ID Pri State Dead Time Address Interface
192.168.2.1 1 FULL/- 00:00:37 10.0.0.2 Serial2/0

router1:
Router#show ip protocols

Routing Protocol is "ospf 2"
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
Number of areas in this router is 1. 1 normal 0 stub 0 nssa
Maximum path: 4
Routing for Networks:
192.168.2.0 0.0.0.255 area 0
10.0.0.0 0.255.255.255 area 0
20.0.0.0 0.255.255.255 area 0
Routing Information Sources:
Gateway Distance Last Update
10.0.0.1 110 00:03:26
20.0.0.2 110 00:03:31
Distance: (default is 110)

Router#show ip route ospf
O 192.168.1.0/24 [110/782] via 10.0.0.1, 00:03:54, Serial2/0
O 192.168.3.0/24 [110/782] via 20.0.0.2, 00:03:37, Serial3/0

Router#show ip ospf interface
FastEthernet0/0 is up, line protocol is up
Internet address is 192.168.2.1/24, Area 0
Process ID 2, 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
No backup designated router on this network
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
Hello due in 00:00:07
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)
Serial2/0 is up, line protocol is up
Internet address is 10.0.0.2/8, Area 0
Process ID 2, Router ID 192.168.2.1, Network Type POINT-TO-POINT, Cost: 781
Transmit Delay is 1 sec, State POINT-TO-POINT,
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
Hello due in 00:00:04
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 10.0.0.1
Suppress hello for 0 neighbor(s)
Serial3/0 is up, line protocol is up
Internet address is 20.0.0.1/8, Area 0
Process ID 2, Router ID 192.168.2.1, Network Type POINT-TO-POINT, Cost: 781
Transmit Delay is 1 sec, State POINT-TO-POINT,
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
Hello due in 00:00:08
Index 3/3, 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 20.0.0.2
Suppress hello for 0 neighbor(s)

Router#show ip ospf database
OSPF Router with ID (192.168.2.1) (Process ID 2)

Router Link States (Area 0)

Link ID ADV Router Age Seq# Checksum Link count
192.168.1.1 192.168.1.1 260 0x80000003 0x00e967 3
192.168.2.1 192.168.2.1 243 0x80000005 0x00d5a1 5
192.168.3.1 192.168.3.1 243 0x80000003 0x001026 3

Router#show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
192.168.1.1 1 FULL/- 00:00:36 10.0.0.1 Serial2/0
192.168.3.1 1 FULL/- 00:00:32 20.0.0.2 Serial3/0

router2:
Router#show ip protocols

Routing Protocol is "ospf 3"
Outgoing update filter list for all interfaces is not set
Incoming update filter list for all interfaces is not set
Router ID 192.168.3.1
Number of areas in this router is 1. 1 normal 0 stub 0 nssa
Maximum path: 4
Routing for Networks:
192.168.3.0 0.0.0.255 area 0
20.0.0.0 0.255.255.255 area 0
Routing Information Sources:
Gateway Distance Last Update
20.0.0.1 110 00:04:24
Distance: (default is 110)

Router#show ip route ospf
O 10.0.0.0/8 [110/1562] via 20.0.0.1, 00:04:29, Serial2/0
O 192.168.1.0/24 [110/1563] via 20.0.0.1, 00:04:29, Serial2/0
O 192.168.2.0/24 [110/782] via 20.0.0.1, 00:04:29, Serial2/0


Router#show ip ospf interface
FastEthernet0/0 is up, line protocol is up
Internet address is 192.168.3.1/24, Area 0
Process ID 3, Router ID 192.168.3.1, Network Type BROADCAST, Cost: 1
Transmit Delay is 1 sec, State DR, Priority 1
Designated Router (ID) 192.168.3.1, Interface address 192.168.3.1
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)
Serial2/0 is up, line protocol is up
Internet address is 20.0.0.2/8, Area 0
Process ID 3, Router ID 192.168.3.1, Network Type POINT-TO-POINT, Cost: 781
Transmit Delay is 1 sec, State POINT-TO-POINT,
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 20.0.0.1
Suppress hello for 0 neighbor(s)

Router#show ip ospf database
OSPF Router with ID (192.168.3.1) (Process ID 3)

Router Link States (Area 0)

Link ID ADV Router Age Seq# Checksum Link count
192.168.1.1 192.168.1.1 306 0x80000003 0x00e967 3
192.168.3.1 192.168.3.1 289 0x80000003 0x001026 3
192.168.2.1 192.168.2.1 289 0x80000005 0x00d5a1 5

Router#show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
192.168.2.1 1 FULL/- 00:00:34 20.0.0.1 Serial2/0

到此,实验已经做完了