1.按照拓扑图配置好每台路由器的接口IP地址;
2.配置单区域OSPF:
R1(config)#router ospf 10 //启用OSPF路由协议,进程ID为10
R1(config-router)#network 10.1.1.0 0.0.0.255 area 0 //指明直连网段10.1.1.0,注意后面跟的是子网掩码的反码
R1(config-router)#network 10.2.2.0 0.0.0.31 area 0
R1(config-router)#network 10.3.3.0 0.0.0.255 area 0
R1(config-router)#exit
R2(config)#router ospf 20
R2(config-router)#network 10.3.3.0 0.0.0.255 area 0
R2(config-router)#network 172.16.3.0 0.0.0.255 area 0
R2(config-router)#exit
R3(config)#router ospf 30
R3(config-router)#network 172.16.3.0 0.0.0.255 area 0
R3(config-router)#network 172.16.1.0 0.0.0.255 area
R3(config-router)#network 172.16.1.0 0.0.0.255 area 0
R3(config-router)#network 172.16.2.0 0.0.0.31 area 0
R3(config-router)#exit
R1(config-router)#network 10.1.1.0 0.0.0.255 area 0 //指明直连网段10.1.1.0,注意后面跟的是子网掩码的反码
R1(config-router)#network 10.2.2.0 0.0.0.31 area 0
R1(config-router)#network 10.3.3.0 0.0.0.255 area 0
R1(config-router)#exit
R2(config)#router ospf 20
R2(config-router)#network 10.3.3.0 0.0.0.255 area 0
R2(config-router)#network 172.16.3.0 0.0.0.255 area 0
R2(config-router)#exit
R3(config)#router ospf 30
R3(config-router)#network 172.16.3.0 0.0.0.255 area 0
R3(config-router)#network 172.16.1.0 0.0.0.255 area
R3(config-router)#network 172.16.1.0 0.0.0.255 area 0
R3(config-router)#network 172.16.2.0 0.0.0.31 area 0
R3(config-router)#exit
注:子网掩码的反码:就是用255.255.255.255减去子网掩码所得到的数,例如:255.255.255.224的掩码反码为:255.255.255.255-255.255.255.224=0.0.0.31,就和上面的10.2.2.0/27和172.16.2.0/27网段计算出来的一样。
R1#show ip route
Codes: C - connected, S - static, 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
i - IS-IS, su - IS-IS summary, 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
172.16.0.0/16 is variably subnetted, 3 subnets, 2 masks
O 172.16.1.1/32 [110/129] via 10.3.3.2, 00:00:02, Serial1/1
O 172.16.3.0/24 [110/128] via 10.3.3.2, 00:00:02, Serial1/1
O 172.16.2.1/32 [110/129] via 10.3.3.2, 00:00:02, Serial1/1
10.0.0.0/8 is variably subnetted, 3 subnets, 2 masks
C 10.3.3.0/24 is directly connected, Serial1/1
C 10.2.2.0/27 is directly connected, Loopback1
C 10.1.1.0/24 is directly connected, Loopback0
R1#show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
172.16.3.2 0 FULL/ - 00:00:36 10.3.3.2 Serial1/1
R1#show ip ospf database
OSPF Router with ID (10.2.2.1) (Process ID 10)
Router Link States (Area 0)
Link ID ADV Router Age Seq# Checksum Link count
10.2.2.1 10.2.2.1 37 0x80000004 0x003032 4
172.16.2.1 172.16.2.1 27 0x80000002 0x00330E 4
172.16.3.2 172.16.3.2 28 0x80000003 0x001EEF 4
Codes: C - connected, S - static, 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
i - IS-IS, su - IS-IS summary, 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
172.16.0.0/16 is variably subnetted, 3 subnets, 2 masks
O 172.16.1.1/32 [110/129] via 10.3.3.2, 00:00:02, Serial1/1
O 172.16.3.0/24 [110/128] via 10.3.3.2, 00:00:02, Serial1/1
O 172.16.2.1/32 [110/129] via 10.3.3.2, 00:00:02, Serial1/1
10.0.0.0/8 is variably subnetted, 3 subnets, 2 masks
C 10.3.3.0/24 is directly connected, Serial1/1
C 10.2.2.0/27 is directly connected, Loopback1
C 10.1.1.0/24 is directly connected, Loopback0
R1#show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
172.16.3.2 0 FULL/ - 00:00:36 10.3.3.2 Serial1/1
R1#show ip ospf database
OSPF Router with ID (10.2.2.1) (Process ID 10)
Router Link States (Area 0)
Link ID ADV Router Age Seq# Checksum Link count
10.2.2.1 10.2.2.1 37 0x80000004 0x003032 4
172.16.2.1 172.16.2.1 27 0x80000002 0x00330E 4
172.16.3.2 172.16.3.2 28 0x80000003 0x001EEF 4
OK,实验完。
本文转自loveme2351CTO博客,原文链接:http://blog.51cto.com/loveme23/30302 ,如需转载请自行联系原作者