
(一):ospf单区域配置:
(二):ospf多区域配置:
(一):ospf单区域配置:
r2基本信息配置:
Router#conf t
Router(config)#enable secret abc
Router(config)#line console 0
Router(config-line)#password abc
Router(config-line)#login
Router(config-line)#logging synchronous
Router(config-line)#exec-timeout 0 0
Router(config-line)#exi
Router(config)#no ip domain lookup
Router(config)#no cdp run
Router(config)#hostname r2
r2(config-if)#ip add 219.146.2.1 255.255.255.0
r2(config-if)#no shut
r2(config-if)#in loo 0 //虚拟环回接口
r2(config-if)#ip add 172.16.0.1 255.255.255.0
r2(config-if)#in loo 1
r2(config-if)#ip add 172.16.1.1 255.255.255.0
r2(config-if)#in loo 2
r2(config-if)#ip add 172.16.2.1 255.255.255.0
r2(config-if)#in loo 3
r2(config-if)#ip add 172.16.3.1 255.255.255.0
r2(config-if)#exi
r2(config)#router ospf 10 //10代表进程id,没有全局属性
r2(config-router)#router-id 1.1.1.1 //手工指定RID
r2(config-router)#network 219.146.2.0 0.0.0.255 area 0 //添加直连网络,并加入区域0
r2(config-router)#network 172.16.0.0 0.0.0.255 a 0 //这里使用的是反掩码
r2(config-router)#network 172.16.1.0 0.0.0.255 a 0
r2(config-router)#network 172.16.2.0 0.0.0.255 a 0
r2(config-router)#network 172.16.3.0 0.0.0.255 a 0
r2(config-router)#exi
Router#conf t
Router(config)#enable secret abc
Router(config)#line console 0
Router(config-line)#password abc
Router(config-line)#login
Router(config-line)#logging synchronous
Router(config-line)#exec-timeout 0 0
Router(config-line)#exi
Router(config)#no ip domain lookup
Router(config)#no cdp run
Router(config)#hostname r3
r3(config-if)#ip add 219.146.2.2 255.255.255.0
r3(config-if)#no shut
r3(config-if)#in s1/2
r3(config-if)#ip add 219.146.3.1 255.255.255.0
r3(config-if)#no shut
r3(config-if)#exi
r3(config)#router ospf 11 //进程id因为没有全局属性,每个路由器可以不一样
r3(config-router)#network 219.146.2.0 0.0.0.255 a 0 //加入区域0
r3(config-router)#network 219.146.3.0 0.0.0.255 a 0
r3(config-router)#exi
r4基本信息配置:
Router#conf t
Router(config)#enable secret abc
Router(config)#line console 0
Router(config-line)#password abc
Router(config-line)#login
Router(config-line)#logging synchronous
Router(config-line)#exec-timeout 0 0
Router(config-line)#exi
Router(config)#no ip domain lookup
Router(config)#no cdp run
Router(config)#hostname r4
r4(config-if)#ip add 219.146.3.2 255.255.255.0
r4(config-if)#no shut
r4(config-if)#in loo 0
r4(config-if)#ip add 172.16.4.1 255.255.255.0
r4(config-if)#in loo 1
r4(config-if)#ip add 172.16.5.1 255.255.255.0
r4(config-if)#exi
r4(config)#router ospf 12 //进程id可以不一样
r4(config-router)#network 219.146.3.0 0.0.0.255 a 0 //加入区域0
r4(config-router)#network 172.16.4.0 0.0.0.255 a 0
r4(config-router)#network 172.16.5.0 0.0.0.255 a 0
r4(config-router)#exi
至此,ospf的配置就己完成。
Routing Protocol is "ospf 10"
Outgoing update filter list for all interfaces is not set
Incoming update filter list for all interfaces is not set
Router ID 1.1.1.1
Number of areas in this router is 1. 1 normal 0 stub 0 nssa
Maximum path: 4
Routing for Networks:
172.16.0.0 0.0.0.255 area 0
172.16.1.0 0.0.0.255 area 0
172.16.2.0 0.0.0.255 area 0
172.16.3.0 0.0.0.255 area 0
219.146.2.0 0.0.0.255 area 0
Reference bandwidth unit is 100 mbps
Routing Information Sources:
Gateway Distance Last Update
219.146.3.1 110 00:00:27
172.16.5.1 110 00:00:27
Distance: (default is 110)
查看r3的路由协议:
r3(config)#do show ip pro
Routing Protocol is "ospf 11"
Outgoing update filter list for all interfaces is not set
Incoming update filter list for all interfaces is not set
Router ID 219.146.3.1
Number of areas in this router is 1. 1 normal 0 stub 0 nssa
Maximum path: 4
Routing for Networks:
219.146.2.0 0.0.0.255 area 0
219.146.3.0 0.0.0.255 area 0
Reference bandwidth unit is 100 mbps
Routing Information Sources:
Gateway Distance Last Update
1.1.1.1 110 00:22:00
172.16.5.1 110 00:20:12
Distance: (default is 110)
Routing Protocol is "ospf 12"
Outgoing update filter list for all interfaces is not set
Incoming update filter list for all interfaces is not set
Router ID 172.16.5.1
Number of areas in this router is 1. 1 normal 0 stub 0 nssa
Maximum path: 4
Routing for Networks:
172.16.4.0 0.0.0.255 area 0
172.16.5.0 0.0.0.255 area 0
219.146.3.0 0.0.0.255 area 0
Reference bandwidth unit is 100 mbps
Routing Information Sources:
Gateway Distance Last Update
1.1.1.1 110 00:21:27
219.146.3.1 110 00:21:27
Distance: (default is 110)
RID的选举:
手工指定的RID最优先,其次是环回接口最大的地址,再次是物理接口最大的地址。
注意:RID一旦选举后,是不会改变的,手工指定了也不会改变,除非重启路由器,或者在手工指定RID后,可以重启ospf进程来得到指定的RID。
r3#clear ip ospf process
Reset ALL OSPF processes? [no]: y
r2(config)#do 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
O 219.146.3.0/24 [110/128] via 219.146.2.2, 00:02:52, Serial1/0
172.16.0.0/16 is variably subnetted, 6 subnets, 2 masks
O 172.16.5.1/32 [110/129] via 219.146.2.2, 00:01:14, Serial1/0
O 172.16.4.1/32 [110/129] via 219.146.2.2, 00:01:24, Serial1/0
C 172.16.0.0/24 is directly connected, Loopback0
C 172.16.1.0/24 is directly connected, Loopback1
C 172.16.2.0/24 is directly connected, Loopback2
C 172.16.3.0/24 is directly connected, Loopback3
度量值的算法是:10的8次方/入口带宽,这是一个路由器上的值,把所有经过的路由器的值加起来的和就是度量值,(小于1的数取1,大于1的数小数点后的省略,不四舍五入)
下面的实验就来做ospf在ABR上做汇总。
r2(config)#no router ospf 10 //去掉ospf10
r2(config)#router ospf 10 //重建一个ospf10
r2(config-router)#network 219.146.2.0 0.0.0.255 a 1 //加入区域1
r2(config-router)#network 172.16.0.0 0.0.0.255 a 1
r2(config-router)#network 172.16.1.0 0.0.0.255 a 1
r2(config-router)#network 172.16.2.0 0.0.0.255 a 1
r2(config-router)#network 172.16.3.0 0.0.0.255 a 1
r2(config-router)#exi
r3(config)#no router ospf 11 //去掉ospf11
r3(config)#router ospf 11
r3(config-router)#network 219.146.2.0 0.0.0.255 a 1 //加入区域1
r3(config-router)#network 219.146.3.0 0.0.0.255 a 0 //加入区域0
r3(config-router)#exi
r4(config)#do 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
C 219.146.3.0/24 is directly connected, Serial1/0
172.16.0.0/16 is variably subnetted, 6 subnets, 2 masks
C 172.16.4.0/24 is directly connected, Loopback0
C 172.16.5.0/24 is directly connected, Loopback1
O IA 172.16.1.1/32 [110/129] via 219.146.3.1, 00:01:09, Serial1/0
O IA 172.16.0.1/32 [110/129] via 219.146.3.1, 00:01:09, Serial1/0
O IA 172.16.3.1/32 [110/129] via 219.146.3.1, 00:01:09, Serial1/0
O IA 172.16.2.1/32 [110/129] via 219.146.3.1, 00:01:09, Serial1/0
r3(config-router)#area 0 range 172.16.4.0 255.255.254.0 //将区域0汇总
r3(config-router)#area 1 range 172.16.0.0 255.255.252.0 //将区域1汇总
r3(config-router)#exi
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
C 219.146.3.0/24 is directly connected, Serial1/0
172.16.0.0/16 is variably subnetted, 3 subnets, 2 masks
C 172.16.4.0/24 is directly connected, Loopback0
C 172.16.5.0/24 is directly connected, Loopback1
O IA 172.16.0.0/22 [110/129] via 219.146.3.1, 00:00:12, Serial1/0
已经是汇总后的路由表了。
ospf:如果网络中只有一个区域,区域号可以是任意一个有效范围内的数字。
如果网络中有两个以上的区域,必须有区域0.因为,系统认为区域0是骨干网络。
OSPF常用调试命令:
show running-config 查看当前运行的配置
show startup-config 查看已保存过的配置
show ip int brie 查看接口基本状态
show int s0 查看接口详细信息
show ip ospf neighbor 查看OSPF的邻居
show ip ospf interface +接口名 查看运行OSPF的接口信息
show ip route 查看路由表
show ip route ospf 查看OSPF的路由
show ip ospf database 查看OSPF的数据库
debug ip ospf adj 查看ADJ的DEBUG的信息
debug ip ospf events 查看OSPF的事件
















