OSPF ---ip阶段
RIP的特点:
- 基于UDP协议,端口号为520
- 优先级为100,数值越小越好(cisco AD=120 管理距离)
- 使用跳数作为度量值,取值0-15,跳数值为15最大,调数值16跳不可达,最大跳数16跳
- RIP信息交互使用两种报文:Request和Responsee
- 30s定期更新,更新整张路由表,导致收敛时间很慢
RIP是距离矢量路由协议,矢量就是跳数,每经过一跳跳数加一,听信邻居,ospf完全不一样
RIP的缺陷
- 路由表周期更新,30s更新太慢了
- 次优路径,就是按照cost开销值计算的
- 跳数限制,16跳
RIP缺陷问题优化方法
- 路由表周期更新,修改为触发更新
- 次优路径,以带宽为参考值选取最佳路径
- 跳数限制,取消跳数限制,基于拓扑计算路由
什么是ospf
ospf,开放最短路径优先,是一种链路状态路由协议
链路状态
- 路径信息
- 描述链路类型
- 描述邻居设备
- 路由信息
- 描述接口IP和掩码(路由)
- 描述链路开销(带宽)
OSPF版本及特性
- OSPF有V2,V3,OSPF V2支持IPV4,OSPF V3支持IPV6
- OSPF的协议优先级为10(OSPF外部路由为150,RIP优先级为100)
- OSPF基于IP协议,协议号为89(RIP基于UDP,协议号520)
- 天然无环,基于SPF算法生成最优路径
- 使用链路状态数据库保存全网链路状态信息(路径信息,路由信息)
- OSPF使用接口cost值作为链路开销的度量方式。cos值=参考带宽/实际带宽。默认参考带宽为100M
OSPF Roter Id的选举规则
- 手动指定ip
- 默认换回接口地址
- 存活接口ip
OSPF工作过程
- 建立邻居关系
- 发送hello报文,与邻居建立双向通讯
- 建立邻接关系
- 同步链路状态数据库
- 计算最优路径
- 基于SPF算法计算最优路径,生成路由表
OSPF协议的五种报文
OSPF –链路状态路由协议(初级)【华为】(可以看这个)
Hello报文
- 发现建立维持邻居关系
通过OSPF Header头部影响邻居关系建立的因素:
- Version:版本要一致
- Source OSPF Router:RID不冲突
- Area ID:区域ID要一致
- Auth Type:认证;类型要一致
- Auth Data:认证秘钥要一致
通过OSPF Hell Packet包影响邻居关系建立的因素:
- Network Mask:广播型网络掩码要一致(选drbdr的时候需要在相同的网络)
- Hello Interval:时间要一致
- Router Dead Interval:死亡时间要一致
- Options:特殊区域标签要一致【主要看N是否携带7类,E是否携带5类】
- Router Priority:广播型网络DR优先级不全为0
DBD报文
- 链路信息摘要内容,同步信息,相当与目录
LSR报文
- 链路状态请求,只携带LSA的三要素,只有LSR不携带Options字段
LSU报文
- 链路状态更新,携带完整lsa头部信息,一个LSU中可以携带多个LSA头部
- LSA更新时间1800s
- LSA老化时间3600s
- LSU产生方式
- 回复LSR
- 周期更新
LS Age:表示LSA已经生存时间,单位s
Options:每一个bit都对应了OSPF所支持的某种特性
LS Type:标识LSA的类型
Link State ID(链路状态ID):不同的LSA,对该字段的定义不同
Advertising Router(通告路由器):产生该LSA的路由器的Router ID
Sequence Number(链路状态序列号):当LSA每次有新的实例产生时,序列号就会增加,用来确认LSA新旧的,比如说两条新的lSa来了以后,使用序列号来确认放入最新的
Checksum(校验和):用于保证数据的完整性和准确性
Length:是一个包含LSA头部在内的总长度
OSPF网络类型
接口类型 | 默认OSPF网络类型 | 默认Hello间隔 |
广域网类型接口 | P-2-P | 10秒 |
以太网类型接口 | broadcast | 10秒 |
帧中继接口 | NBMA | 30秒 |
—— | P2MP | 30秒 |
OSPF查看接口类型的命令
[R1]dis ospf int
OSPF Process 1 with Router ID 12.1.1.1
Interfaces
Area: 0.0.0.0 (MPLS TE not enabled)
IP Address Type State Cost Pri DR BDR
12.1.1.1 Broadcast DR 1 1 12.1.1.1 12.1.1.2
OSPF时间的详细内容
//hello 10代表发送hello包的时间间隔
//dead 40代码邻居之间40s内收不到报文,默认邻居down
[R1]dis ospf int verbose
OSPF Process 1 with Router ID 12.1.1.1
Interfaces
Area: 0.0.0.0 (MPLS TE not enabled)
Interface: 12.1.1.1 (GigabitEthernet0/0/0)
Cost: 1 State: DR Type: Broadcast MTU: 1500
Priority: 1
Designated Router: 12.1.1.1
Backup Designated Router: 12.1.1.2
Timers: Hello 10 , Dead 40 , Poll 120 , Retransmit 5 , Transmit Delay 1
IO Statistics
Type Input Output
Hello 146 153
DB Description 2 3
Link-State Req 1 1
Link-State Update 2 4
Link-State Ack 3 1
ALLSPF GROUP
ALLDR GROUP
OpaqueId: 0 PrevState: Waiting
Effective cost: 1, enabled by OSPF Protocol
OSPF邻居状态
OSPF查看数据库LSA信息
IP报文是尽力而为,尽力发过去,对方有没有收到不负责
查看全局OSPF路由表
[R3]dis ip routing-table protocol ospf
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 1 Routes : 1
OSPF routing table status : <Active>
Destinations : 1 Routes : 1
Destination/Mask Proto Pre Cost Flags NextHop Interface
24.1.1.0/24 OSPF 10 2 D 34.1.1.2 GigabitEthernet0/0/0
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0
故障一:接口类型不一置导致OSPF路由表为空
//一端修改接口类型为P2P
[R4]dis ip routing-table protocol ospf
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 1 Routes : 1
OSPF routing table status : <Active>
Destinations : 1 Routes : 1
Destination/Mask Proto Pre Cost Flags NextHop Interface
13.1.1.0/24 OSPF 10 2 D 34.1.1.1 GigabitEthernet0/0/1
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0
//两端都修改为P2P
[R4]dis ip routing-table protocol ospf
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 2 Routes : 2
OSPF routing table status : <Active>
Destinations : 2 Routes : 2
Destination/Mask Proto Pre Cost Flags NextHop Interface
12.1.1.0/24 OSPF 10 2 D 24.1.1.1 GigabitEthernet0/0/0
13.1.1.0/24 OSPF 10 2 D 34.1.1.1 GigabitEthernet0/0/1
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0
练习一:
交换机没有地址,我忘记改为123.1.1.0了
实验要求:
1.通过OSPF实现全网通,其中OSPF进程号为1,Area为0,手工指定RID为对应设备的loopback0口
R1
[R1]ospf router-id 1.1.1.1
[R1-ospf-1]area 0
[R1-ospf-1-area-0.0.0.0]network 1.1.1.1 0.0.0.0
[R1-ospf-1-area-0.0.0.0]network 12.1.1.0 0.0.0.255
[R1-ospf-1-area-0.0.0.0]network 123.1.1.0 0.0.0.255
R2
[R2]ospf router-id 2.2.2.2 [R2-ospf-1]area 0 [R2-ospf-1-area-0.0.0.0]network 2.2.2.2 0.0.0.0 [R2-ospf-1-area-0.0.0.0]network 24.1.1.0 0.0.0.255 [R2-ospf-1-area-0.0.0.0]network 12.1.1.0 0.0.0.255 [R2-ospf-1-area-0.0.0.0]network 123.1.1.0 0.0.0.255
R3
[R3]ospf router-id 3.3.3.3
[R3-ospf-1]area 0
[R3-ospf-1-area-0.0.0.0]network 3.3.3.3 0.0.0.0
[R3-ospf-1-area-0.0.0.0]network 123.1.1.0 0.0.0.255
R4
[R4]ospf 1 router-id 4.4.4.4
[R4-ospf-1]area 0
[R4-ospf-1-area-0.0.0.0]network 4.4.4.4 0.0.0.0
[R4-ospf-1-area-0.0.0.0]network 24.1.1.0 0.0.0.255
2.将R1的RID修改为11.11.11.11
[R1]dis ospf int
OSPF Process 1 with Router ID 1.1.1.1
Interfaces
Area: 0.0.0.0 (MPLS TE not enabled)
IP Address Type State Cost Pri DR BDR
1.1.1.1 P2P P-2-P 0 1 0.0.0.0 0.0.0.0
12.1.1.1 Broadcast DR 1 1 12.1.1.1 12.1.1.2
123.1.1.2 Broadcast DR 1 1 123.1.1.2 123.1.1.3
[R1]ospf 1 router-id 11.11.11.11
Info: The configuration succeeded. You need to restart the OSPF process to validate the new router ID.
<R1>reset ospf process
Warning: The OSPF process will be reset. Continue? [Y/N]:y
[R1]dis ospf int
OSPF Process 1 with Router ID 11.11.11.11
Interfaces
Area: 0.0.0.0 (MPLS TE not enabled)
IP Address Type State Cost Pri DR BDR
1.1.1.1 P2P P-2-P 0 1 0.0.0.0 0.0.0.0
12.1.1.1 Broadcast BDR 1 1 12.1.1.2 12.1.1.1
123.1.1.2 Broadcast DROther 1 1 123.1.1.3 123.1.1.4
3.通过修改cost值,实现R1去往4.4.4.4的主线路为R1-R2(12.1.1.2)-R4,辅线路为R1-R2(123.1.1.2)-R4
注意事项
- broadcast 默认的cost值为 1
- loopback口默认的cost值为0
- 串口默认的cost值为48
[R1]int g0/0/1
[R1-GigabitEthernet0/0/1]ospf cost 60
[R2]int g0/0/2
[R2-GigabitEthernet0/0/2]ospf cost 65
[R1]dis ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 15 Routes : 15
Destination/Mask Proto Pre Cost Flags NextHop Interface
1.1.1.1/32 Direct 0 0 D 127.0.0.1 LoopBack0
2.2.2.2/32 OSPF 10 1 D 12.1.1.2 GigabitEthernet0/0/0
3.3.3.3/32 OSPF 10 60 D 123.1.1.4 GigabitEthernet0/0/1
4.4.4.4/32 OSPF 10 2 D 12.1.1.2 GigabitEthernet0/0/0
12.1.1.0/24 Direct 0 0 D 12.1.1.1 GigabitEthernet0/0/0
12.1.1.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0
12.1.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0
24.1.1.0/24 OSPF 10 2 D 12.1.1.2 GigabitEthernet0/0/0
123.1.1.0/24 Direct 0 0 D 123.1.1.2 GigabitEthernet0/0/1
123.1.1.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1
123.1.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
[R1]int g0/0/0
[R1-GigabitEthernet0/0/0]shutdown
[R1]dis ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 12 Routes : 12
Destination/Mask Proto Pre Cost Flags NextHop Interface
1.1.1.1/32 Direct 0 0 D 127.0.0.1 LoopBack0
2.2.2.2/32 OSPF 10 60 D 123.1.1.3 GigabitEthernet0/0/1
3.3.3.3/32 OSPF 10 60 D 123.1.1.4 GigabitEthernet0/0/1
4.4.4.4/32 OSPF 10 61 D 123.1.1.3 GigabitEthernet0/0/1
24.1.1.0/24 OSPF 10 61 D 123.1.1.3 GigabitEthernet0/0/1
123.1.1.0/24 Direct 0 0 D 123.1.1.2 GigabitEthernet0/0/1
123.1.1.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1
123.1.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
4.修改R2 G0/0/01和R4 G0/0/0的网络接口类型为点对点
[R2]int g0/0/1
[R2-GigabitEthernet0/0/1]ospf network-type p2p
[R4]int g0/0/0
[R4-GigabitEthernet0/0/0]ospf network-type p2p
5.R1-R2-R3之间多路访问环境,选举R2为DR,R3为BDR
//到对应接口下,进行修改优先级
[R2]int g0/0/2
[R2-GigabitEthernet0/0/2]ospf dr-priority 255
<R2>reset ospf 1 pro
Y
[R3]int g0/0/0
[R3-GigabitEthernet0/0/2]ospf dr-priority 250
<R3>reset ospf 1 pro
6.用抓包软件抓取OSPF的5种报文并描述报文作用
OSPF的路由表什么时候为空?
两边接口类型不一致的时候(一边为P2P,一边为brother),虽然可以看到状态都是full,但是没有路由信息
重启OSPF,重启会重新选择DR,BDR
//HUAWEI
<R>reset ospf process
Warning:The OSPF process will be reset. Continue? [Y/N]:y
//cisco
clear ip ospf process

评论