一、实验目的

1、掌握OSPF协议的多区域配置

2、掌握OSPF协议的LSA类型

3、配置OSPF路由协议的汇总

二、实验拓扑

 

三、实验步骤

1、按照拓扑图配置好接口的IP地址和loopback网络,配置如下:

R1(config)#int s1/1 

R1(config-if)#ip add 172.16.1.1 255.255.255.0

R1(config-if)#no shut

R1(config-if)#exit

R1(config)#int loop 0

R1(config-if)#ip add 172.16.64.1 255.255.255.0

R1(config-if)#exi

R1(config)#int loop 1

R1(config-if)#ip add 172.16.80.1 255.255.255.0

R1(config-if)#int loop 2  

R1(config-if)#ip add 172.16.96.1 255.255.255.0

R1(config-if)#int loop 3                     

R1(config-if)#ip add 172.16.112.1 255.255.255.0

R1(config-if)#int loop 5                      

R1(config-if)#ip add 10.0.0.1 255.255.255.0

R1(config-if)#exit

其它R2R3类似地配置好,并接口互相间直连要ping通。

2、同样地按照拓扑图配置多区域OSPF协议,配置如下

R1

R1(config)#router ospf 1

R1(config-router)#network 172.16.1.0 0.0.0.255 area 0

R1(config-router)#network 172.16.64.0 0.0.0.255 area 1

R1(config-router)#network 172.16.80.0 0.0.0.255 area 1

R1(config-router)#network 172.16.96.0 0.0.0.255 area 1

R1(config-router)#network 172.16.112.0 0.0.0.255 area 1    

R2、R3同样地配置好OSPF协议。 

R3配置如下网络到NULL0接口的静态路由,以便后面做OSPF外部路由实验时用到。

R3(config)#ip route 172.16.240.0 255.255.255.0 null 0

R3(config)#ip route 172.16.244.0 255.255.255.0 null 0

R3(config)#ip route 172.16.248.0 255.255.255.0 null 0

R3(config)#ip route 172.16.252.0 255.255.255.0 null 0

R3(config)#exit

3、配置好OSPF协议后,可以通过命令show ip ospf查看哪个路由器是ABR、哪个是ASBR

R1#sh ip ospf

 Routing Process "ospf 1" with ID 172.16.112.1

 Supports only single TOS(TOS0) routes

 Supports opaque LSA

 Supports Link-local Signaling (LLS)

 It is an area border router

 Initial SPF schedule delay 5000 msecs

 Minimum hold time between two consecutive SPFs 10000 msecs

 Maximum wait time between two consecutive SPFs 10000 msecs

 Minimum LSA interval 5 secs. Minimum LSA arrival 1 secs

 LSA group pacing timer 240 secs

 Interface flood pacing timer 33 msecs

 Retransmission pacing timer 66 msecs

 Number of external LSA 0. Checksum Sum 0x000000

 Number of opaque AS LSA 0. Checksum Sum 0x000000

 Number of DCbitless external and opaque AS LSA 0

 Number of DoNotAge external and opaque AS LSA 0

 Number of areas in this router is 2. 2 normal 0 stub 0 nssa

 External flood list length 0

    Area BACKBONE(0)

        Number of interfaces in this area is 1

        Area has no authentication

        SPF algorithm last executed 00:05:10.176 ago

        SPF algorithm executed 9 times

        Area ranges are

        Number of LSA 7. Checksum Sum 0x02FB2B

        Number of opaque link LSA 0. Checksum Sum 0x000000

        Number of DCbitless LSA 0

        Number of indication LSA 0

        Number of DoNotAge LSA 0

        Flood list length 0

    Area 1

        Number of interfaces in this area is 4 (4 loopback)

        Area has no authentication

        SPF algorithm last executed 00:06:46.200 ago

        SPF algorithm executed 5 times

        Area ranges are

        Number of LSA 4. Checksum Sum 0x02490A

        Number of opaque link LSA 0. Checksum Sum 0x000000

        Number of DCbitless LSA 0

        Number of indication LSA 0

        Number of DoNotAge LSA 0

        Flood list length 0

 

4、使用命令show ip ospf neighbor查看邻居信息。

R1#sh ip ospf nei

 

Neighbor ID     Pri   State           Dead Time   Address         Interface

172.16.3.1        0   FULL/  -        00:00:35    172.16.1.2      Serial1/1

 

R2#sh ip ospf nei

 

Neighbor ID     Pri   State           Dead Time   Address         Interface

172.16.112.1      0   FULL/  -        00:00:30    172.16.1.1      Serial1/0

172.16.224.2      0   FULL/  -        00:00:32    172.16.224.2    Serial1/2

 

R3#sh ip ospf nei

 

Neighbor ID     Pri   State           Dead Time   Address         Interface

172.16.3.1        0   FULL/  -        00:00:32    172.16.224.1    Serial1/1

5、使用命令show ip route查看路由表。

R1#sh ip route

 

 

 

Gateway of last resort is not set

172.16.0.0/16 is variably subnetted, 7 subnets, 2 masks

O IA    172.16.224.0/24 [110/128] via 172.16.1.2, 00:10:12, Serial1/1

C       172.16.1.0/24 is directly connected, Serial1/1

O       172.16.3.1/32 [110/65] via 172.16.1.2, 00:10:12, Serial1/1

C       172.16.112.0/24 is directly connected, Loopback3

C       172.16.96.0/24 is directly connected, Loopback2

C       172.16.80.0/24 is directly connected, Loopback1

C       172.16.64.0/24 is directly connected, Loopback0

     10.0.0.0/24 is subnetted, 1 subnets

C       10.0.0.0 is directly connected, Loopback5

 

R2#sh ip route

 

 

 

Gateway of last resort is not set

     172.16.0.0/16 is variably subnetted, 7 subnets, 2 masks

C       172.16.224.0/24 is directly connected, Serial1/2

C       172.16.1.0/24 is directly connected, Serial1/0

C       172.16.3.0/24 is directly connected, Loopback0

O IA    172.16.112.1/32 [110/65] via 172.16.1.1, 00:09:50, Serial1/0

O IA    172.16.96.1/32 [110/65] via 172.16.1.1, 00:09:50, Serial1/0

O IA    172.16.80.1/32 [110/65] via 172.16.1.1, 00:09:50, Serial1/0

O IA    172.16.64.1/32 [110/65] via 172.16.1.1, 00:09:50, Serial1/0

 

R3#sh ip route

Gateway of last resort is not set

 

     172.16.0.0/16 is variably subnetted, 11 subnets, 2 masks

S       172.16.252.0/24 is directly connected, Null0

S       172.16.248.0/24 is directly connected, Null0

S       172.16.244.0/24 is directly connected, Null0

S       172.16.240.0/24 is directly connected, Null0

C       172.16.224.0/24 is directly connected, Serial1/1

O IA    172.16.1.0/24 [110/128] via 172.16.224.1, 00:06:19, Serial1/1

O IA    172.16.3.1/32 [110/65] via 172.16.224.1, 00:06:19, Serial1/1

O IA    172.16.112.1/32 [110/129] via 172.16.224.1, 00:06:19, Serial1/1

O IA    172.16.96.1/32 [110/129] via 172.16.224.1, 00:06:19, Serial1/1

O IA    172.16.80.1/32 [110/129] via 172.16.224.1, 00:06:19, Serial1/1

O IA    172.16.64.1/32 [110/129] via 172.16.224.1, 00:06:19, Serial1/1

加粗的都是区域间的路由。

6、为了减小路由表的条目,可以在R1上执行路由器汇总,配置如下:

R1(config)#router ospf 1

R1(config-router)#area 1 range 172.16.64.0 255.255.192.0

R1(config-router)#exit

配置好可以在R2R3上查看路由表信息

R2#sh 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, 4 subnets, 2 masks

C       172.16.224.0/24 is directly connected, Serial1/2

C       172.16.1.0/24 is directly connected, Serial1/0

C       172.16.3.0/24 is directly connected, Loopback0

O IA    172.16.64.0/18 [110/65] via 172.16.1.1, 00:00:47, Serial1/0

对比前面的R2的路由表可以发现少了好多路由条目。

R3#sh ip route

 

Gateway of last resort is not set

 

 

     172.16.0.0/16 is variably subnetted, 8 subnets, 3 masks

S       172.16.252.0/24 is directly connected, Null0

S       172.16.248.0/24 is directly connected, Null0

S       172.16.244.0/24 is directly connected, Null0

S       172.16.240.0/24 is directly connected, Null0

C       172.16.224.0/24 is directly connected, Serial1/1

O IA    172.16.1.0/24 [110/128] via 172.16.224.1, 00:14:16, Serial1/1

O IA    172.16.3.1/32 [110/65] via 172.16.224.1, 00:14:16, Serial1/1

O IA    172.16.64.0/18 [110/129] via 172.16.224.1, 00:00:10, Serial1/1

已经将R1通告过来的172.16.64.0~172.16.112.0网段都汇总成一条172.16.64.0/18的路由项了,大大地减少了路由条目。

7R3必须重分布外部路由从外部网络172.16.240.0~172.16.252.0OSPFAS内部配置如下

R3(config)#router ospf 1

R3(config-router)#redistribute static

% Only classful networks will be redistributed  // 不加上subnets只重发布classful路由

R3(config-router)#exit      

R3(config)#router ospf 1

R3(config-router)#redistribute static subnets   

R3(config-router)#exit                   

再分别在R1R2上查看路由表

R1#sh ip route

 

 

Gateway of last resort is not set

 

 

     172.16.0.0/16 is variably subnetted, 12 subnets, 3 masks

O E2    172.16.252.0/24 [110/20] via 172.16.1.2, 00:00:13, Serial1/1

O E2    172.16.248.0/24 [110/20] via 172.16.1.2, 00:00:13, Serial1/1

O E2    172.16.244.0/24 [110/20] via 172.16.1.2, 00:00:13, Serial1/1

O E2    172.16.240.0/24 [110/20] via 172.16.1.2, 00:00:13, Serial1/1

O IA    172.16.224.0/24 [110/128] via 172.16.1.2, 00:14:48, Serial1/1

C       172.16.1.0/24 is directly connected, Serial1/1

O       172.16.3.1/32 [110/65] via 172.16.1.2, 00:14:48, Serial1/1

C       172.16.112.0/24 is directly connected, Loopback3

C       172.16.96.0/24 is directly connected, Loopback2

C       172.16.80.0/24 is directly connected, Loopback1

C       172.16.64.0/24 is directly connected, Loopback0

O       172.16.64.0/18 is a summary, 00:14:48, Null0

     10.0.0.0/24 is subnetted, 1 subnets

C       10.0.0.0 is directly connected, Loopback5

 

R2#sh ip route

 

 

Gateway of last resort is not set

 

 

     172.16.0.0/16 is variably subnetted, 8 subnets, 2 masks

O E2    172.16.252.0/24 [110/20] via 172.16.224.2, 00:00:03, Serial1/2

O E2    172.16.248.0/24 [110/20] via 172.16.224.2, 00:00:02, Serial1/2

O E2    172.16.244.0/24 [110/20] via 172.16.224.2, 00:00:02, Serial1/2

O E2    172.16.240.0/24 [110/20] via 172.16.224.2, 00:00:02, Serial1/2

C       172.16.224.0/24 is directly connected, Serial1/2

C       172.16.1.0/24 is directly connected, Serial1/0

C       172.16.3.0/24 is directly connected, Loopback0

O IA    172.16.64.0/18 [110/65] via 172.16.1.1, 00:12:40, Serial1/0

这是因为对于外部路由OSPF默认使用E2类型的LSA,不计算AS内部路径所带来的cost值。

现在重新在R3上配置重分布,使用E1类型的LSA来计算看看。

R3(config)#router ospf 1

R3(config-router)#redistribute static metric-type 1 subnets

R3(config-router)#exit

配置完成后,分别使用show ip route查看R1R2上的路由表。

R1#sh ip route

 

 

Gateway of last resort is not set

 

 

     172.16.0.0/16 is variably subnetted, 12 subnets, 3 masks

O E1    172.16.252.0/24 [110/148] via 172.16.1.2, 00:00:23, Serial1/1

O E1    172.16.248.0/24 [110/148] via 172.16.1.2, 00:00:23, Serial1/1

O E1    172.16.244.0/24 [110/148] via 172.16.1.2, 00:00:23, Serial1/1

O E1    172.16.240.0/24 [110/148] via 172.16.1.2, 00:00:23, Serial1/1

O IA    172.16.224.0/24 [110/128] via 172.16.1.2, 00:12:23, Serial1/1

C       172.16.1.0/24 is directly connected, Serial1/1

O       172.16.3.1/32 [110/65] via 172.16.1.2, 00:12:23, Serial1/1

C       172.16.112.0/24 is directly connected, Loopback3

C       172.16.96.0/24 is directly connected, Loopback2

C       172.16.80.0/24 is directly connected, Loopback1

C       172.16.64.0/24 is directly connected, Loopback0

O       172.16.64.0/18 is a summary, 00:12:23, Null0

     10.0.0.0/24 is subnetted, 1 subnets

C       10.0.0.0 is directly connected, Loopback5

 

R2#sh ip route

 

 

Gateway of last resort is not set

 

 

     172.16.0.0/16 is variably subnetted, 8 subnets, 2 masks

O E1    172.16.252.0/24 [110/84] via 172.16.224.2, 00:02:05, Serial1/2

O E1    172.16.248.0/24 [110/84] via 172.16.224.2, 00:02:05, Serial1/2

O E1    172.16.244.0/24 [110/84] via 172.16.224.2, 00:02:05, Serial1/2

O E1    172.16.240.0/24 [110/84] via 172.16.224.2, 00:02:05, Serial1/2

C       172.16.224.0/24 is directly connected, Serial1/2

C       172.16.1.0/24 is directly connected, Serial1/0

C       172.16.3.0/24 is directly connected, Loopback0

O IA    172.16.64.0/18 [110/65] via 172.16.1.1, 00:12:08, Serial1/0

分别出现了4E1类型的OSPF路由,R1R2上相同目的网络的metric值不同,原因是把AS内部路径的cost值加进来了。如果在OSPF区域内只有一个出口,可以使用E2类型,如果区域有2个出口,我们可以用E1类型,以避免次优路径用来转发数据。