路由交换练习——配置OSPF协议

OSPF协议

路由表的建立

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

在这里插入图片描述

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

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

度量值(路径开销)

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

适用环境

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

实验要求

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

搭建网络

在这里插入图片描述

为各路由端口配置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

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

在这里插入图片描述

可以看到,从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
( OSPF练习.rar ) 练习题一: 问题描述:R1-R4所有的路由器运行OSPF 10,全网全通,并且R1,R2的loopback 口防单点故障; 看看配置几条虚链路才是最合理? 解答:如果此图只要求全网全通的话只要在R2-R3或R1-R4之间只做一条virtual-link就行了; 为了冗余还因此需要做三条virtual-link ① R2-R3 area 14 virtual-link x.x.x.x (x代表对方router-id); ② R1-R4 area 13 virtual-link x.x.x.x ③ R1-R2 area 12 virtual-link x.x.x.x 注意: 本来只需在R1-R4或R2-R3之间只做一跳virtual-link就可以了,为了防止loopbabck单点故障, 因此在R1-R4和R2-R3之间都要做virtual-link;此时就可以防止loopback单点故障; R1-R2之间仍然需要一条virtual-link 这样就可以防止area 0 这条链路故障了; 练习题二: 问题描述: 1、按照上面的图上部分,把r1上的lo重分布到R1上,area 2是stub区域,看看area1 area 0 area2里分别有几类lsa 2、按照上面的图下部分,在R4上将eigrap重分布到R4上,area 2 是nssa区域,看看area1 area0 area2里分别有几类lsa 解答: 上面的下面实验,area0里没有4类LSA,因为虽然真正的ASBR是R4,但是因为AREA2是NSSA,R3要进行7转5的过程,LSA5是由R3产生的,所以R3被认为是ASBR,所以应该是由ABR也就是R2产生4类LSA,所以AREA0里没有4类LSA。 谁产生5类LSA谁就被认为是ASBR,4类LSA是由ABR产生描述ASBR在那里,只有ASBR产生的5类LSA的通告者不变,其他的都会变化。 练习题三: 问题描述:上面是一个hub-spoke模型,其中R1是hub,分别在R1 R4 R5上配置ospf,让他们能够全网可达。上面运行的是ospf的nbma模型。 解决方案:需要确定以下几点 1、要单播指邻居,在R1上指就可以了 2、要确保R1是DR 3、R4 R5要相互添加对方的map表
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值