配置OSPF协议

  • OSPF协议
  • 路由表的建立
  • 度量值(路径开销)
  • 适用环境
  • 实验要求
  • 搭建网络
  • OSPF协议基本配置
  • OSPF的邻居表、DR选举
  • 查看OSPF的LSDB表和路由表
  • 修改接口开销,实现等值路径负载均衡
  • 调试OSPF协议


OSPF协议

路由表的建立

  1. 先建立邻居关系
  2. 构建关于整个网络链路状态的数据库
  3. 用SPF算法自己计算路由表(链路状态型路由协议)

交换机修改ospf 开销 ospf怎么交换路由信息_R3

HELLO:建立邻居关系通告目的IP为224.0.0.5( 所有OSPF路由器 可识别)

描述包DBD:向邻居通告自已当前数据库的简略信息(序列号)
请求包LSR:序列号新,请求对方发送
更新包LSU:通告关于某条链路的详细信息 (LSA 拓扑 + 路由)
确认包ACK:对更新包回复消息以示确认

度量值(路径开销)

COST=100M/带宽,依据带宽来选择最佳路径

适用环境

没有环路、跳数限制,适于大型、复杂的网络环境

实验要求

配置OSPF协议,实现全网互通,并在合适的路由器上修改OSPF开销,实现等值路径负载均衡。

搭建网络

交换机修改ospf 开销 ospf怎么交换路由信息_R3_02

为各路由端口配置IP:

R1(config)#int f0/1
R1(config-if)#ip address 172.16.1.1 255.255.255.0
R1(config-if)#no shutdown 
R1(config-if)#
R1(config-if)#int s1/0
R1(config-if)#ip address 12.0.0.1 255.0.0.0
R1(config-if)#clock rate 64000
R1(config-if)#no shutdown
R1(config)#
R1(config-if)#int f0/0 
R1(config-if)#ip address 14.0.0.1 255.0.0.0
R1(config-if)#no shutdown 


R0(config)#int s1/0
R0(config-if)#ip address 12.0.0.2 255.0.0.0
R0(config-if)#no shutdown 
R0(config-if)#
R0(config-if)#int s1/1
R0(config-if)#ip address 23.0.0.2 255.0.0.0
R0(config-if)#clock rate 64000
R0(config-if)#no shutdown 


R2(config)#int f0/0
R2(config-if)#ip address 14.0.0.4 255.0.0.0
R2(config-if)#no shutdown 
R2(config-if)#
R2(config-if)#int s1/0
R2(config-if)#ip address 34.0.0.4 255.0.0.0
R2(config-if)#clock rate 64000
R2(config-if)#no shutdown 


R3(config)#int s1/0
R3(config-if)#ip address 34.0.0.3 255.0.0.0
R3(config-if)#no shutdown 
R3(config-if)#
R3(config-if)#int s1/1
R3(config-if)#ip address 23.0.0.3 255.0.0.0
R3(config-if)#no shutdown 
R3(config-if)#
R3(config-if)#int f0/1
R3(config-if)#ip address 172.16.8.1 255.255.255.0
R3(config-if)#no shutdown

OSPF协议基本配置

router ospf 1中的1为本地进程号
router-id 1.1.1.1中的1.1.1.1为ID号,格式与IP格式相同,不能重复

network 172.16.1.0 0.0.0.255 area 1各项的值依次为网络号、通配符掩码、区域号

例如:

net 172.16.1.0 0.0.0.255 area 1 为匹配对应子网号

net 172.16.1.1 0.0.0.0 area 1 为匹配接口IP

R1(config)#router ospf 1
R1(config-router)#router-id 1.1.1.1
R1(config-router)#network 172.16.1.0 0.0.0.255 area 1
R1(config-router)#network 12.0.0.0 0.255.255.255 area 1
R1(config-router)#network 14.0.0.1 0.0.0.0 area 1


R0(config)#router ospf 1
R0(config-router)#router-id 2.2.2.2
R0(config-router)#network 12.0.0.2 0.0.0.0 area 1
R0(config-router)#network 23.0.0.2 0.0.0.0 area 1


R3(config)#router ospf 1
R3(config-router)#router-id 3.3.3.3
R3(config-router)#network 172.16.8.0 0.0.0.255 area 1
R3(config-router)#network 23.0.0.3 0.0.0.0 area 1
R3(config-router)#network 34.0.0.3 0.0.0.0 area 1


R2(config)#router ospf 1
R2(config-router)#router-id 4.4.4.4
R2(config-router)#network 14.0.0.4 0.0.0.0 area 1
R2(config-router)#network 34.0.0.4 0.0.0.0 area 1

OSPF的邻居表、DR选举

在同一网段中可能有多个路由器存在,即会选举DR,其作用是:减少邻居关系,减小网络中的更新流量。在DR选举时先比较优先级,优先级大的为DR,默认为1,设置为0时不能成为DR。当优先级相同时,比较ID号 ID号大的为DR。

R1#show ip ospf neighbor 

Neighbor ID     Pri   State           Dead Time   Address         Interface
4.4.4.4           1   FULL/BDR        00:00:31    14.0.0.4        FastEthernet0/0
2.2.2.2           0   FULL/  -        00:00:30    12.0.0.2        Serial1/0
R1#show ip ospf interface f0/0

FastEthernet0/0 is up, line protocol is up
  Internet address is 14.0.0.1/8, Area 1
  Process ID 1, Router ID 1.1.1.1, Network Type BROADCAST, Cost: 65
  Transmit Delay is 1 sec, State DR, Priority 2
  Designated Router (ID) 1.1.1.1, Interface address 14.0.0.1
  Backup Designated Router (ID) 4.4.4.4, Interface address 14.0.0.4
  Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
    Hello due in 00:00:07
  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 0 msec, maximum is 0 msec
  Neighbor Count is 1, Adjacent neighbor count is 1
    Adjacent with neighbor 4.4.4.4  (Backup Designated Router)
  Suppress hello for 0 neighbor(s)

R1和R2的优先级相同,但R2的ID大于R1,但DR为R1。是因为,R1首先启动,40秒后成为了DR。虽然R2的ID号更大,但不能抢占DR。如果R2想成为DR,需要将两个路由器的接口shut, 然后no shut,重新选举。

若R1在新的选举中还想成为DR,则需要修改f0/0的接口优先级:

R1(config)#int f0/0
R1(config-if)#ip ospf priority 2

另外,DR选举,发生广播型多路访问网络(以太网)中,点到点链路上(广域网)不需要选举DR。

查看OSPF的LSDB表和路由表

R1#show ip ospf database 
            OSPF Router with ID (1.1.1.1) (Process ID 1)

                Router Link States (Area 1)

Link ID         ADV Router      Age         Seq#       Checksum Link count
1.1.1.1         1.1.1.1         1408        0x80000007 0x004911 4
2.2.2.2         2.2.2.2         1443        0x80000006 0x006a4e 4
3.3.3.3         3.3.3.3         1442        0x80000007 0x00aff3 5
4.4.4.4         4.4.4.4         1407        0x80000006 0x0061ba 3

                Net Link States (Area 1)
Link ID         ADV Router      Age         Seq#       Checksum
14.0.0.1        1.1.1.1         1408        0x80000002 0x00865f
R1#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

C    12.0.0.0/8 is directly connected, Serial1/0
C    14.0.0.0/8 is directly connected, FastEthernet0/0
O    23.0.0.0/8 [110/128] via 12.0.0.2, 00:55:11, Serial1/0
O    34.0.0.0/8 [110/129] via 14.0.0.4, 00:54:36, FastEthernet0/0
     172.16.0.0/24 is subnetted, 2 subnets
C       172.16.1.0 is directly connected, FastEthernet0/1
O       172.16.8.0 [110/129] via 12.0.0.2, 00:55:11, Serial1/0

修改接口开销,实现等值路径负载均衡

交换机修改ospf 开销 ospf怎么交换路由信息_网络_03

可以看到,从R1到172.16.8.0有两条路可走:
R1—R0—R3 64+64+1=129
R1—R2—R3 1+64+1=66
OSPF选择了路径最短的: R1—R2—R3

如果R1到R2之间的链路出现故障断开,OSPF会自动更新LSDB表,然后R1会自动重新计算前往172.16.8.0的路径:
R1—R0—R3 64+64+1=129

若想减小R1与R2之间的压力,让数据流量经过R1—R0—R3前往172.16.8.0则需要修改对应接口的开销:

R1(config)#int f0/0
R1(config-if)#ip ospf cost 65


R1#show ip ospf interface f0/0

FastEthernet0/0 is up, line protocol is up
  Internet address is 14.0.0.1/8, Area 1
  Process ID 1, Router ID 1.1.1.1, Network Type BROADCAST, Cost: 65
  Transmit Delay is 1 sec, State DR, Priority 2
  Designated Router (ID) 1.1.1.1, Interface address 14.0.0.1
  Backup Designated Router (ID) 4.4.4.4, Interface address 14.0.0.4
  Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
    Hello due in 00:00:00
  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 0 msec, maximum is 0 msec
  Neighbor Count is 1, Adjacent neighbor count is 1
    Adjacent with neighbor 4.4.4.4  (Backup Designated Router)
  Suppress hello for 0 neighbor(s)
R1#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

C    12.0.0.0/8 is directly connected, Serial1/0
C    14.0.0.0/8 is directly connected, FastEthernet0/0
O    23.0.0.0/8 [110/128] via 12.0.0.2, 01:08:28, Serial1/0
O    34.0.0.0/8 [110/129] via 14.0.0.4, 01:07:53, FastEthernet0/0
     172.16.0.0/24 is subnetted, 2 subnets
C       172.16.1.0 is directly connected, FastEthernet0/1
O       172.16.8.0 [110/129] via 12.0.0.2, 01:08:28, Serial1/0

说明:
OSPF的开销计算是按前往目标出方向的累加开销。由于数据通信是双向的,要实现返回数据的负载均衡,则还需要修改R2的f0/0的开销为65。

调试OSPF协议

开启调试:

R1#debug ip ospf events 

OSPF events debugging is on

01:26:31: OSPF: Rcv hello from 2.2.2.2 area 1 from Serial1/0 12.0.0.2
01:26:31: OSPF: End of hello processing
01:26:31: OSPF: Rcv hello from 4.4.4.4 area 1 from FastEthernet0/0 14.0.0.4
01:26:31: OSPF: End of hello processing
01:26:41: OSPF: Rcv hello from 2.2.2.2 area 1 from Serial1/0 12.0.0.2
01:26:41: OSPF: End of hello processing
01:26:41: OSPF: Rcv hello from 4.4.4.4 area 1 from FastEthernet0/0 14.0.0.4
01:26:41: OSPF: End of hello processing

关闭调试:

R1#undebug ip ospf events 

OSPF events debugging is off