小知识:多区域OSPF中所涉及的路由器的类型有:内部路由器、主干/内部路由器
ABR和主干路由器、ASBR和主干路由器。
内部路由器:OSPF路由器上所有直连的链路都处于同一个区域
主干路由器:具有连接区域0接口的路由器
区域边界路由器(ABR):路由器与多个区域相连
自治系统边界路由器(ASBR):与AS外部的路由器相连并相互交换路由信息。

区域类型:
标准区域:可以接受链路更新信息和路由汇总。
主干区域:连接各区域的中心实体,所有其他的区域都要连接到这个区域上
                    交换路由信息
末节区域:不接受外部自治系统的路由信息
完全末节区域:即不接受外部自治系统的路由也不接受自治系统内部其他区域的
                            路由汇总。
次末节区域:允许接受以类型7的LSA发送的外部路由信息,并且ABR要负责把类型
                        7的LSA转换成类型5的LSA.
1》开启R1的OSPF进程
R1(config)#router ospf 1
R1(config-router)#router-id 1.1.1.1
R1(config-router)#network 1.1.1.0 0.0.0.255 area 1
R1(config-router)#network 192.168.12.0 0.0.0.255 area 1
2》用同样的方法开启R2、R3的OSPF进程
3》开启R4的OSPF进程
R4(config)#router ospf 1
R4(config-router)#router-id 4.4.4.4
R4(config-router)#network 192.168.34.0 0.0.0.255 area 2
4》R2#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

     1.0.0.0/32 is subnetted, 1 subnets
O       1.1.1.1 [110/782] via 192.168.12.1, 00:25:06, Serial0/3/0
     2.0.0.0/24 is subnetted, 1 subnets
C       2.2.2.0 is directly connected, Loopback0
     3.0.0.0/32 is subnetted, 1 subnets
O       3.3.3.3 [110/782] via 192.168.23.2, 00:23:35, Serial0/2/0
C    192.168.12.0/24 is directly connected, Serial0/3/0
C    192.168.23.0/24 is directly connected, Serial0/2/0
O IA 192.168.34.0/24 [110/1562] via 192.168.23.2, 00:23:10, Serial0/2/0
从以上结果可知,R2上通过OSPF获取了两条区域内路由和一条区域间路由。
5》在R4上将4.4.4.0/24网络重分布进OSPF网络,在这里4.4.4.0模拟了一个外部自治系统
命令是:
R4(config-router)#redistribute connected subnets
6》再在R2上查看路由显示的结果是
Gateway of last resort is not set

     1.0.0.0/32 is subnetted, 1 subnets
O       1.1.1.1 [110/782] via 192.168.12.1, 00:35:30, Serial0/3/0
     2.0.0.0/24 is subnetted, 1 subnets
C       2.2.2.0 is directly connected, Loopback0
     3.0.0.0/32 is subnetted, 1 subnets
O       3.3.3.3 [110/782] via 192.168.23.2, 00:33:59, Serial0/2/0
     4.0.0.0/24 is subnetted, 1 subnets
O E2    4.4.4.0 [110/20] via 192.168.23.2, 00:00:21, Serial0/2/0
C    192.168.12.0/24 is directly connected, Serial0/3/0
C    192.168.23.0/24 is directly connected, Serial0/2/0
O IA 192.168.34.0/24 [110/1562] via 192.168.23.2, 00:33:34, Serial0/2/0
从上面的结果可以看出多了一条路由。
注意:
OSPF的外部路由分为:类型1(E1)和类型2(E2)他们计算外部路由度量值的方式不同
类型1(E2):外部路径成本+数据包在OSPF网络所经过各链路成本;
类型2(E2):外部路径成本,即ASBR上的默认设置(默认值为20)
在重分布的时候,可以通过“metric-type”参数设置时类型1或2,也可以通过“metric”
参数设置外部路径成本,默认值为20.例如:
R4(config-router)#redistribute connected subnets metric 50 metric-type 1