上次的博文具体讨论了OSPF的理论,这次主要是OSPF的配置哈!OSPF理论篇的链接:http://sweetpotato.blog.51cto.com/533893/1401426 


OSPF的配置涉及到的命令归纳如下:

1、配置步骤

1、配置loopback接口地址:     //用于产生路由器的Router ID
Router(config)#interface loopback 0
Router(config-if)#ip address IP地址 掩码 

2、启动OSPF路由进程:    //本路由器的进程号,用于标识同一路由器上的多个OSPF进程
Router(config)#router ospf 进程号 

3、指定OSPF协议运行的接口和所在区域:
Router(config-router)#network 网络号 反向掩码 area 区域号
/*说明:
**网络号:可以是网络地址、子网地址、接口地址
**反向掩码:即子网掩码的反码(例如:192.168.2.0/28的反向掩码为:0.0.0.15<-->因为子网掩码为255.255.255.240,所以反向掩码为:0.0.0.<255-240=15>)
**区域号:指明网络所属区域,此处是0-->骨干区域(非0则为常规区域;单区域必须为骨干区域哈)
*/

2、修改接口的cost值:

//修改接口的cost值(OSPF路由器在接口上使用cost值来决定最佳路径,cost=10^8/BW)
Router(config-if)#ip ospf cost number
  
//举例:
Router(config)#inteface s0
Router(config-if)#ip ospf cost 1000 //取值范围1~65535

3、配置OSPF计时器:

//配置OSPF计时器(为了交换信息,相邻路由器必须有相同的hello和dead间隔,通常dead时间是hello时间的4倍)
Router(config-if)#ip ospf hello-interval 时间(s)
Router(config-if)#ip ospf dead-interval 时间(s)

4、Router ID的配置命令:

Router(config)#router ospf 进程号  //启用OSPF
Router(config-router)#router-id IP_Address   //指定Router-ID

5、OSPF汇总命令:

Router(config-router)#area 区域号 range 要汇总的IP 掩码

6、验证OSPF配置:

//验证OSPF配置:
//查看邻居表
Router#show ip ospf neighbor
//查看链路状态数据库
Router#show ip ospf database
//查看路由表
Router#show ip route
//查看OSPF的配置
Router#show ip ospf
//查看OSPF接口数据结构
Router#show ip ospf interface 接口
Router#show ip ospf interface 
 
   
Router#show running-config | s r o

一、配置单区域OSPF:

实验环境和配置过程:

1、实验拓扑:

image

2、实验要求:

(1)在每个路由器上启用OSPF,使得网络互联互通

(2)验证OSPF配置:理解OSPF邻接关系的建立、理解以太网广播型网络DR/BDR的选举

(3)理解广播多路访问链路上和点对点链路上的OSPF 特征

3、配置过程:

(1)每个路由器上按图配置好IP地址并启用回环口:

R1#show ip int bri   //R1的接口配置
Interface                  IP-Address      OK? Method Status                Protocol
Serial0/0                  13.1.1.1        YES manual up                    up      
Serial0/1                  unassigned      YES unset  administratively down down    
Serial0/2                  unassigned      YES unset  administratively down down    
Serial0/3                  unassigned      YES unset  administratively down down    
FastEthernet1/0            12.1.1.1        YES manual up                    up      
Loopback0                  1.1.1.1         YES manual up                    up   

R2#show ip int bri     //R2的接口配置
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            12.1.1.2        YES manual up                    up      
FastEthernet1/0            24.1.1.1        YES manual up                    up      
Loopback0                  2.2.2.2         YES manual up                    up      

R3#show ip int bri    //R3的接口配置
Interface                  IP-Address      OK? Method Status                Protocol
Serial0/0                  13.1.1.2        YES manual up                    up      
Serial0/1                  34.1.1.1        YES manual up                    up      
Serial0/2                  unassigned      YES unset  administratively down down    
Serial0/3                  unassigned      YES unset  administratively down down    
Loopback0                  3.3.3.3         YES manual up                    up  

R4#show ip int bri   //R4的接口配置
Interface                  IP-Address      OK? Method Status                Protocol
Serial0/0                  34.1.1.2        YES manual up                    up      
Serial0/1                  unassigned      YES unset  administratively down down    
Serial0/2                  unassigned      YES unset  administratively down down    
Serial0/3                  unassigned      YES unset  administratively down down    
FastEthernet1/0            24.1.1.2        YES manual up                    up      
Loopback0                  4.4.4.4         YES manual up                    up

(2)在每个路由器上启用OSPF并且手动指定Router ID:

//路由器R1上启用OSPF,进程号为10
R1(config)#router ospf 10 
R1(config-router)#router-id 1.1.1.1        
//通告网段
R1(config-router)#network 1.1.1.1 0.0.0.0 area 0   
R1(config-router)#network 12.1.1.0 0.0.0.255 area 0  
R1(config-router)#network 13.1.1.0 0.0.0.255 area 0
//邻居消息
R1(config-router)#
*Mar  1 00:55:06.991: %OSPF-5-ADJCHG: Process 10, Nbr 2.2.2.2 on FastEthernet1/0 from LOADING to FULL, Loading Done      
R1(config-router)#
*Mar  1 00:56:49.695: %OSPF-5-ADJCHG: Process 10, Nbr 3.3.3.3 on Serial0/0 from LOADING to FULL, Loading Done
//路由器R2上启用OSPF
R2(config)#router ospf 10
R2(config-router)#router-id 2.2.2.2
//通告网段
R2(config-router)#network 2.2.2.2 0.0.0.0 area 0
R2(config-router)#network 12.1.1.0 0.0.0.255 area 0
R2(config-router)#network 24.1.1.0 0.0.0.255 area 0
//邻居消息
R2(config-router)#
*Mar  1 00:55:04.883: %OSPF-5-ADJCHG: Process 10, Nbr 1.1.1.1 on FastEthernet0/0 from LOADING to FULL, Loading Done
R2(config-router)#
*Mar  1 00:58:18.399: %OSPF-5-ADJCHG: Process 10, Nbr 4.4.4.4 on FastEthernet1/0 from LOADING to FULL, Loading Done
//路由器R3上启用OSPF
R3(config)#router ospf 10
R3(config-router)#router-id 3.3.3.3
//通告网段
R3(config-router)#network 3.3.3.3 0.0.0.0 area 0
R3(config-router)#network 13.1.1.0 0.0.0.255 area 0
R3(config-router)#network 34.1.1.0 0.0.0.255 area 0
//邻居消息
R3(config-router)#network 
*Mar  1 00:57:45.751: %OSPF-5-ADJCHG: Process 10, Nbr 1.1.1.1 on Serial0/0 from LOADING to FULL, Loading Done
R3(config-router)#
*Mar  1 00:59:33.715: %OSPF-5-ADJCHG: Process 10, Nbr 4.4.4.4 on Serial0/1 from LOADING to FULL, Loading Done
//在路由器R4上启用OSPF
R4(config)#router ospf 10
R4(config-router)#router-id 4.4.4.4
//通告网段
R4(config-router)#network 4.4.4.4 0.0.0.0 area 0
R4(config-router)#network 24.1.1.0 0.0.0.255 area 0
R4(config-router)#network 34.1.1.0 0.0.0.255 area 0
//邻居消息
R4(config-router)#
*Mar  1 00:59:14.371: %OSPF-5-ADJCHG: Process 10, Nbr 2.2.2.2 on FastEthernet1/0 from LOADING to FULL, Loading Done
R4(config-router)#
*Mar  1 00:59:31.671: %OSPF-5-ADJCHG: Process 10, Nbr 3.3.3.3 on Serial0/0 from LOADING to FULL, Loading Done

【技术要点】
① OSPF 路由进程ID 的范围必须是在1~65535 之间,而且只有本地含义,不同路由器的路由进程ID 可以不同,如果
要想启动OFPS 路由进程,至少确保有一个接口是up 的;
② 区域ID 是在0~4 294 967 295 内的十进制数,也可以是IP 地址格式A.B.C.D,当网络区域ID 为0 或0.0.0.0 时称为
主干区域;
③ 在高版本的IOS 中通告OSPF 网络的时候,网络号的后面可以跟网络掩码,也可以跟反掩码;
④ 确定Router ID 遵循如下顺序:
? 最优先的是在OSPF 进程中用命令”router-id”指定了路由器ID;
? 如果没有在OSPF 进程中指定路由器ID,那么把选择IP 地址最大的环回接口的IP 地址为Router ID;
? 如果没有环回接口,就选择最大活动的物理接口的IP 地址为Router ID,建议用命令”router-id”来指定路由器ID,这样可控性比较好。

(3)实验调试:

  • 查看路由表(show ip route):
R1#show ip route        //查看R1的路由表
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

     34.0.0.0/24 is subnetted, 1 subnets
O       34.1.1.0 [110/66] via 12.1.1.2, 00:47:24, FastEthernet1/0    //输出结果表明同一个区域内通过OSPF 路由协议学习的路由条目用代码”O”表示。
     1.0.0.0/24 is subnetted, 1 subnets
C       1.1.1.0 is directly connected, Loopback0
     2.0.0.0/32 is subnetted, 1 subnets
O       2.2.2.2 [110/2] via 12.1.1.2, 00:47:24, FastEthernet1/0
     3.0.0.0/32 is subnetted, 1 subnets
O       3.3.3.3 [110/65] via 13.1.1.2, 00:47:24, Serial0/0
     4.0.0.0/32 is subnetted, 1 subnets
O       4.4.4.4 [110/3] via 12.1.1.2, 00:47:24, FastEthernet1/0
     24.0.0.0/24 is subnetted, 1 subnets
O       24.1.1.0 [110/2] via 12.1.1.2, 00:47:26, FastEthernet1/0
     12.0.0.0/24 is subnetted, 1 subnets
C       12.1.1.0 is directly connected, FastEthernet1/0
     13.0.0.0/24 is subnetted, 1 subnets
C       13.1.1.0 is directly connected, Serial0/0

【说明】
① 环回接口OSPF 路由条目的掩码长度都是32 位,这是环回接口的特性,尽管通告了24 位。解决的办法是在环回接口下修改网络类型为”Point-to-Point”,操作如下:
R2(config)#interface loopback 0
R2(config-if)#ip ospf network point-to-point
这样收到的路由条目的掩码长度和通告的就一致了。
② 路由条目”4.4.4.4”的度量值为3,计算过程如下:
cost 的计算公式为10^8/带宽(bps),然后取整,而且是所有链路入口的cost 之和。

可以用"show interfaces 接口"命令来查看带宽:

R4#show interfaces lo0 | in BW
  MTU 1514 bytes, BW 8000000 Kbit, DLY 5000 usec,    

R2#show interfaces f1/0 | in BW
  MTU 1500 bytes, BW 100000 Kbit, DLY 100 usec,

R1#show interfaces f1/0 | in BW
  MTU 1500 bytes, BW 100000 Kbit, DLY 100 usec,

路由条目"4.4.4.4”到路由器R2 经过的入接口包括路由器R4 的loopback 0,路由器R2的f1/0,路由器R1 的f1/0,所以计算如下:10^8/(8*10^9)+10^8/(10^8)+10^8/(10^8)≈1+1+1=3,也可以直接通过命令”ip ospf cost”设置接口的cost 值,并且它是优先计算的cost 值

  • 查看路由协议(show ip protocols):
R1#show ip protocols   
Routing Protocol is "ospf 10"     //当前路由器运行的OSPF 进程ID
  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      //本路由器ID
  Number of areas in this router is 1. 1 normal 0 stub 0 nssa     //本路由器参与的区域数量和类型
  Maximum path: 4      //支持等价路径最大数目
  Routing for Networks:       //表明OSPF 通告的网络以及这些网络所在的区域
    1.1.1.1 0.0.0.0 area 0
    12.1.1.0 0.0.0.255 area 0
    13.1.1.0 0.0.0.255 area 0
 Reference bandwidth unit is 100 mbps     //参考带宽为10^8
  Routing Information Sources:    //表明路由信息源
    Gateway         Distance      Last Update
    2.2.2.2              110      00:52:29
    4.4.4.4              110      00:52:29
    3.3.3.3              110      00:52:29
  Distance: (default is 110)      //OSPF 路由协议默认的管理距离
  • show ip ospf:
R1#show ip ospf
 Routing Process "ospf 10" with ID 1.1.1.1
 Start time: 00:00:14.580, Time elapsed: 00:58:51.508
 Supports only single TOS(TOS0) routes
 Supports opaque LSA
 Supports Link-local Signaling (LLS)
 Supports area transit capability
 Router is not originating router-LSAs with maximum metric
 Initial SPF schedule delay 5000 msecs
 Minimum hold time between two consecutive SPFs 10000 msecs
 Maximum wait time between two consecutive SPFs 10000 msecs
 Incremental-SPF disabled
 Minimum LSA interval 5 secs
 Minimum LSA arrival 1000 msecs
 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 1. 1 normal 0 stub 0 nssa
 Number of areas transit capable is 0
 External flood list length 0
    Area BACKBONE(0)
        Number of interfaces in this area is 3 (1 loopback)
        Area has no authentication
        SPF algorithm last executed 00:57:56.652 ago
        SPF algorithm executed 4 times
        Area ranges are
        Number of LSA 6. Checksum Sum 0x026085
        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
  • show ip ospf interface:
R1#show ip ospf interface 
Serial0/0 is up, line protocol is up     
  Internet Address 13.1.1.1/24, Area 0     //该接口的地址和运行的OSPF 区域
  Process ID 10, Router ID 1.1.1.1, Network Type POINT_TO_POINT, Cost: 64    //进程ID,路由器ID,网络类型,接口Cost值
  Transmit Delay is 1 sec, State POINT_TO_POINT,    //接口的延迟和状态
  Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5    //显示几个计时器的值(Hello时间、死亡时间、等待时长)
    oob-resync timeout 40     
    Hello due in 00:00:03      //距离下次发送Hello 包的时间
  Supports Link-local Signaling (LLS)    //支持LLS
  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 4 msec
  Neighbor Count is 1, Adjacent neighbor count is 1    //邻居的个数以及已建立邻接关系的邻居的个数
    Adjacent with neighbor 3.3.3.3     //已经建立邻接关系的邻居路由器ID
  Suppress hello for 0 neighbor(s)   //没有进行Hello 抑制

FastEthernet1/0 is up, line protocol is up 
  Internet Address 12.1.1.1/24, Area 0 
  Process ID 10, Router ID 1.1.1.1, Network Type BROADCAST, Cost: 1
  Transmit Delay is 1 sec, State BDR, Priority 1     
  Designated Router (ID) 2.2.2.2, Interface address 12.1.1.2     
  Backup Designated router (ID) 1.1.1.1, Interface address 12.1.1.1   
  Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
    oob-resync timeout 40
    Hello due in 00:00:01
  Supports Link-local Signaling (LLS)
  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 4 msec, maximum is 4 msec
  Neighbor Count is 1, Adjacent neighbor count is 1   
    Adjacent with neighbor 2.2.2.2  (Designated Router)   
  Suppress hello for 0 neighbor(s)
Loopback0 is up, line protocol is up 
  Internet Address 1.1.1.1/24, Area 0 
  Process ID 10, Router ID 1.1.1.1, Network Type LOOPBACK, Cost: 1
  Loopback interface is treated as a stub Host   
  • 查看邻居表(show ip ospf neighbor):
R1#show ip ospf neighbor 

Neighbor ID     Pri   State           Dead Time   Address         Interface
3.3.3.3           0   FULL/ -         00:00:32    13.1.1.2        Serial0/0    
2.2.2.2           1   FULL/DR         00:00:39    12.1.1.2        FastEthernet1/0   

/**以上输出表明路由器R1 有两个邻居,它们的路由器ID 分别为3.3.3.3和2.2.2.2,其他参数解释如下所述:
**① Pri;邻居路由器接口的优先级;
**② State;当前邻居路由器接口的状态(full表示邻接状态);
**③ Deard Time;清除邻居关系前等待的最长时间;
**④ Address;邻居接口的地址;
**⑤ Interface;自己和邻居路由器相连的接口;
**⑥ “-":表示点到点的链路上OSPF 不进行DR 选举
**/
R2#show ip ospf neighbor       

Neighbor ID     Pri   State           Dead Time   Address         Interface
4.4.4.4           1   FULL/DR         00:00:30    24.1.1.2        FastEthernet1/0    //R4的Router ID大,所以R4为DR
1.1.1.1           1   FULL/BDR        00:00:38    12.1.1.1        FastEthernet0/0

R3#show ip ospf  neighbor   //R3的接口全是点到点网络,所以不参与DR/BDR选举

Neighbor ID     Pri   State           Dead Time   Address         Interface
4.4.4.4           0   FULL/  -        00:00:39    34.1.1.2        Serial0/1
1.1.1.1           0   FULL/  -        00:00:37    13.1.1.1        Serial0/0

R4#show ip ospf neighbor 

Neighbor ID     Pri   State           Dead Time   Address         Interface
3.3.3.3           0   FULL/  -        00:00:38    34.1.1.1        Serial0/0    //点到点网络不参与DR/BDR选举
2.2.2.2           1   FULL/BDR        00:00:35    24.1.1.1        FastEthernet1/0   //R2的Router ID小于自己,所以R4是DR,R2是BDR

【技术要点】
① 为了避免路由器之间建立完全邻接关系而引起的大量开销,OSPF 要求在多路访问的网络中选举一个DR(一个广播域对应地需要一个DR/BDR),每个路由器都与之建立邻接关系。选举DR 的同时也选举出一个BDR,在DR 失效的时候,BDR 担负起DR 的职责,所有其他路由器只与DR 和BDR 建立邻接关系。
② DR 和BDR 有它们自己的组播地址224.0.0.6
③ DR和BDR 的选举是以各个网络为基础的,也就是说,DR 和BDR 选举是一个路由器的接口特性,而不是整个路由器的特性。
④ DR 选举的原则:
首要因素是时间,最先启动的路由器被选举成DR;

如果同时启动,或者重新选举,则看接口优先级(范围为0~255),优先级最高的被选举成DR,在默认情况下,多路访问网络的接口优先级为1,点到点网络接口优先级为0,修改接口优先级的命令是"ip ospf priority”,如果接口的优先级被设置为0,那么该接口将不参与DR 选举;

如果前两者相同,最后看路由器ID,路由器ID 最高的被选举成DR。

【DR/BDR的选举】在R1上将其接口f1/0的优先级调高

R1(config)#int f1/0
R1(config-if)#ip ospf priority 10    //将R1的f1/0接口优先级调高
//在R2上查看邻居信息
R2#show ip ospf neighbor 

Neighbor ID     Pri   State           Dead Time   Address         Interface
4.4.4.4           1   FULL/DR         00:00:38    24.1.1.2        FastEthernet1/0
1.1.1.1          10   FULL/BDR        00:00:36    12.1.1.1        FastEthernet0/0   //优先级调高后没有重新选举DR/BDR

/**
**【结论】
**(1)DR/BDR选举完成后,为了保证网络的稳定性,即使人为将路由器某接口的优先级调高,****路由器也不会重新选举DR/BDR
**(2)若要重新让路由器选举DR/BDR,可以用“clear ip ospf process”清除OSPF的进程信息让路由**器重新建立邻接关系
**注意:由于邻接关系是双向的,所以清除OSPF进程时要在两个路由器上进行
**/

R1#clear ip ospf process 
Reset ALL OSPF processes? [no]: y
R1#
*Mar  1 03:16:33.003: %OSPF-5-ADJCHG: Process 10, Nbr 3.3.3.3 on Serial0/0 from FULL to DOWN, Neighbor Down: Interface down or detached
*Mar  1 03:16:33.011: %OSPF-5-ADJCHG: Process 10, Nbr 2.2.2.2 on FastEthernet1/0 from FULL to DOWN, Neighbor Down: Interface down or detached
*Mar  1 03:16:33.619: %OSPF-5-ADJCHG: Process 10, Nbr 3.3.3.3 on Serial0/0 from LOADING to FULL, Loading Done
*Mar  1 03:16:33.623: %OSPF-5-ADJCHG: Process 10, Nbr 2.2.2.2 on FastEthernet1/0 from LOADING to FULL, Loading Done

R2#clear ip ospf process 
Reset ALL OSPF processes? [no]: y
R2#
*Mar  1 03:16:18.143: %OSPF-5-ADJCHG: Process 10, Nbr 4.4.4.4 on FastEthernet1/0 from FULL to DOWN, Neighbor Down: Interface down or detached
*Mar  1 03:16:18.151: %OSPF-5-ADJCHG: Process 10, Nbr 1.1.1.1 on FastEthernet0/0 from FULL to DOWN, Neighbor Down: Interface down or detached
*Mar  1 03:16:18.639: %OSPF-5-ADJCHG: Process 10, Nbr 1.1.1.1 on FastEthernet0/0 from LOADING to FULL, Loading Done
*Mar  1 03:16:18.655: %OSPF-5-ADJCHG: Process 10, Nbr 4.4.4.4 on FastEthernet1/0 from LOADING to FULL, Loading Done
R2#
*Mar  1 03:16:30.159: %OSPF-5-ADJCHG: Process 10, Nbr 1.1.1.1 on FastEthernet0/0 from LOADING to FULL, Loading Done

//再在路由器R2上查看邻居信息
R2#show ip ospf neighbor 

Neighbor ID     Pri   State           Dead Time   Address         Interface
4.4.4.4           1   FULL/DR         00:00:37    24.1.1.2        FastEthernet1/0
1.1.1.1          10   FULL/DR         00:00:36    12.1.1.1        FastEthernet0/0   //R1为DR了哈
  • 查看链路状态数据库(show ip ospf database):
R1#show ip ospf database   

            OSPF Router with ID (1.1.1.1) (Process ID 10)

                Router Link States (Area 0)

Link ID         ADV Router      Age         Seq#       Checksum Link count
1.1.1.1         1.1.1.1         1846        0x80000005 0x0077B1 4
2.2.2.2         2.2.2.2         1849        0x80000005 0x00336B 3
3.3.3.3         3.3.3.3         1845        0x80000003 0x007DD3 5
4.4.4.4         4.4.4.4         1913        0x80000005 0x00724E 4

                Net Link States (Area 0)

Link ID         ADV Router      Age         Seq#       Checksum
12.1.1.2        2.2.2.2         1849        0x80000003 0x000E06
24.1.1.2        4.4.4.4         1913        0x80000003 0x00AB48

/*
**以上输出是R1的区域0 的拓扑结构数据库的信息,标题行的解释如下所述。
**① Link ID;是指Link State ID,代表整个路由器,而不是某个链路;
**② ADV Router;是指链路状态信息的路由器ID;
**③ Age;老化时间;
**④ Seq#;序列号;
**⑤ Checksum;校验和;
**⑥ Link count;通告路由器在本区域内的链路数目
*/

在R2的f1/0口到R4的f1/0口进行抓包:

image

image

image 

在路由器R2的f1/0接口上,我们来改变其hello时间间隔,看看在hello时间间隔不一致的情况下,OSPF是否还可以建立邻居关系

从上面的验证信息可以看到:f1/0上,Hello时间为10S,死亡时间为40S(Hello时间的4倍);将Hello时间手工改为15S:

R2(config)#int f1/0       
R2(config-if)#ip ospf he
R2(config-if)#ip ospf hello-interval 15         //将Hello时间改为15秒
R2(config-if)#end
R2#show ip ospf int f1/0       //验证接口f1/0的OSPF信息
FastEthernet1/0 is up, line protocol is up 
  Internet Address 24.1.1.1/24, Area 0 
  Process ID 10, Router ID 2.2.2.2, Network Type BROADCAST, Cost: 1
  Transmit Delay is 1 sec, State BDR, Priority 1 
  Designated Router (ID) 4.4.4.4, Interface address 24.1.1.2
  Backup Designated router (ID) 2.2.2.2, Interface address 24.1.1.1
  Timer intervals configured,  Wait 60, Retransmit 5  
    oob-resync timeout 60
    Hello due in 00:00:12
  Supports Link-local Signaling (LLS)
  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 4 msec, maximum is 4 msec
  Neighbor Count is 1, Adjacent neighbor count is 1 
    Adjacent with neighbor 4.4.4.4  (Designated Router)
  Suppress hello for 0 neighbor(s)
R2#          //可以看到,OSPF的邻居状态变成了down
*Mar  1 12:49:44.860: %OSPF-5-ADJCHG: Process 10, Nbr 4.4.4.4 on FastEthernet1/0 from FULL to DOWN, Neighbor Down: Dead timer expired

R2#show ip ospf neighbor       //查看OSPF邻居表发现没有R4的邻居信息了哈

Neighbor ID     Pri   State           Dead Time   Address         Interface
1.1.1.1           1   FULL/DR         00:00:36    12.1.1.1        FastEthernet0/0

这次不改变Hello时间而改变死亡时间:

R2(config-if)#ip ospf dead-interval 50      //不改变Hello时间而将死亡时间改为50S
R2(config-if)#      //邻居状态变成Down了哈
*Mar  1 13:11:54.908: %OSPF-5-ADJCHG: Process 10, Nbr 4.4.4.4 on FastEthernet1/0 from FULL to DOWN, Neighbor Down: Dead timer expired
R2(config-if)#do show ip ospf int f1/0       //查看f1/0的OSPF信息
FastEthernet1/0 is up, line protocol is up 
  Internet Address 24.1.1.1/24, Area 0 
  Process ID 10, Router ID 2.2.2.2, Network Type BROADCAST, Cost: 1
  Transmit Delay is 1 sec, State DR, Priority 1 
  Designated Router (ID) 2.2.2.2, Interface address 24.1.1.1
  No backup designated router on this network
  Timer intervals configured, Hello 10, Dead 50, Wait 50, Retransmit 5     //死亡时间变成了50S而Hello时间没变哈
    oob-resync timeout 50
    Hello due in 00:00:00
  Supports Link-local Signaling (LLS)
  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 4 msec
  Neighbor Count is 0, Adjacent neighbor count is 0 
  Suppress hello for 0 neighbor(s)
R2(config-if)#do show ip ospf neighbor      //没有了路由器R4的OSPF邻居信息哈

Neighbor ID     Pri   State           Dead Time   Address         Interface
1.1.1.1           1   FULL/DR         00:00:33    12.1.1.1        FastEthernet0/0

【结论】

OSPF 邻居关系不能建立的常见原因:
① Hello 间隔和Dead 间隔不同:
同一链路上的Hello 包间隔和Dead 间隔必须相同才能建立邻接关系。默认时,Dead 间隔是Hello 间隔的4 倍,可以在接口下通过"ip ospf hello-interval”和"ip ospf Dead-interval”命令调整。
② 区域号码不一致。
③ 特殊区域(如stub和nssa 等)区域类型不匹配。
④ 认证类型或密码不一致。
⑤ 路由器ID 相同。
⑥ Hello 包被ACL deny。

⑦ 链路上的MTU 不匹配。
⑧ 接口下OSPF 网络类型不匹配。

 


三、配置多区域OSPF

1、实验拓扑:

image

2、实验目的:

(1)理解OSPF的多区域配置

(2)理解OSPF的区域汇总

3、配置过程:

(1)按照拓扑图把所有路由器的接口配置好IP地址:

R1#show ip interface brief 
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            40.0.1.1        YES manual up                    up      
FastEthernet1/0            40.0.2.1        YES manual up                    up      
Serial2/0                  40.0.0.2        YES manual up                    up      
Serial2/1                  unassigned      YES unset  administratively down down    
Serial2/2                  unassigned      YES unset  administratively down down    
Serial2/3                  unassigned      YES unset  administratively down down    

R2#show ip interface brief 
Interface                  IP-Address      OK? Method Status                Protocol
Serial0/0                  40.0.0.1        YES manual up                    up      
Serial0/1                  192.168.9.2     YES manual up                    up      
Serial0/2                  unassigned      YES unset  administratively down down    
Serial0/3                  unassigned      YES unset  administratively down down    

R3#show ip interface brief 
Interface                  IP-Address      OK? Method Status                Protocol
Serial0/0                  192.168.9.1     YES manual up                    up      
Serial0/1                  unassigned      YES unset  administratively down down    
Serial0/2                  unassigned      YES unset  administratively down down    
Serial0/3                  unassigned      YES unset  administratively down down    
FastEthernet1/0            192.168.8.1     YES manual up                    up

(2)在所有的路由器上启用OSPF:

//R1上启用OSPF
R1(config)#router ospf
R1(config)#router ospf 10
R1(config-router)#network 40.0.0.0 0.0.255.255 area 1
//R2上启用OSPF
R2(config)#router ospf 10
R2(config-router)#network 40.0.0.0 0.0.0.255 area 1   
R2(config-router)#network 192.168.9.0 0.0.0.255 area 0
//R3上启用OSPF
R3(config)#router ospf 10
R3(config-router)#network 192.168.9.0 0.0.0.255 area 0
R3(config-router)#network 192.168.8.0 0.0.0.255 area 0

(3)在R3上查看路由表:

R3#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

C    192.168.8.0/24 is directly connected, FastEthernet1/0
C    192.168.9.0/24 is directly connected, Serial0/0
     40.0.0.0/24 is subnetted, 3 subnets         //子网掩码是24,一共3个子网
O IA    40.0.0.0 [110/128] via 192.168.9.2, 00:04:23, Serial0/0
O IA    40.0.1.0 [110/129] via 192.168.9.2, 00:04:23, Serial0/0
O IA    40.0.2.0 [110/129] via 192.168.9.2, 00:04:23, Serial0/0

(4)在R2上进行汇总,汇总为:40.0.0.0/16

R2(config)#router ospf 10
R2(config-router)#area 1 range 40.0.0.0 255.255.0.0  //路由汇总

(5)在R3上查看area1汇总过来的路由表:

R3#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

C    192.168.8.0/24 is directly connected, FastEthernet1/0
C    192.168.9.0/24 is directly connected, Serial0/0
     40.0.0.0/16 is subnetted, 1 subnets       //可以看到:子网掩码为16,1个子网
O IA    40.0.0.0 [110/128] via 192.168.9.2, 00:03:00, Serial0/0

【结论】

(1)OSPF汇总的命令:

Router(config-router)#area 区域号 range 要汇总的IP 掩码

(2)OSPF默认在边界不会自动汇总,这点不同于RIPv1/RIPv2/EIGRP


关于CCNA部分的OSPF知识就总结这么多哈,欢迎大家拍砖~~