动态路由-OSPF
作者:行癫
OSPF 开放式路由优先
链路状态路由协议,是一种基于链路状态的内部网关路由协议。
OSPF 特点
域内天然无环
收敛速度快
扩展性好:无限制支持网络规模,适用于中型和大型企业网络
支持认证,支持VLSM,CIDR和路由聚合
OSPF 原理
每台运行OSPF的设备互相交互LSA(链路状态通告)形成统一LSDB(链路状态数据库:存放LSA),基于LSDB执行SPF(最短路径优先算法)算法得出达到每个网络的最短路径树,通过最短路径树,得出最优路由,加入路由表。
OSPF 报文
直接封装在IP头部,协议号为89 ,传递过程不可靠
Hello报文:用于建立和维护邻居,在BMA(广播)和NBMA(非广播)网络中选举DR和BDR
DD(Database Description)报文:数据库描述报文:用于描述LSDB,选举主从关系
LSR(LSA Request)报文:链路状态通告请求报文: 用于请求
LSU(LSA Update)报文:链路状态通告更新报文:用于更新LSA
LSACK报文:链路状态确认报文:用于确认LSU
邻居状态机
作用:用于描述OSPF的工作流程
Down:表示没有从邻居收到任何的HELLO报文
Init:从邻居收到Hello报文,但并没有从Hello的邻居列表中看到自己的Router-ID(路由器标识)
2-Way:从邻居收到Hello报文,并且从Hello报文中看到自己的Router-ID,标志着邻居关系建立完成,并在该状态下为BMA和NBMA网络选举DR和BDR
ExStart:该状态下交互空的DD报文,选举主从关系
Exchange:在改状态下,交互带有真事内容的DD报文
Loading:在改状态下交互LSA,LSU,LSACK
Full:LSDB同步完成邻接关系建立完毕
注意:
邻居:两台互连的路由器称为邻居。
邻接:在邻居关系之上发展出来的关系。
Router-ID路由器标识:结构IP地址一样,但是IP地址和Router-ID没有任何关系,必须唯一,作用:用于在网络中唯一的标识一台设备。
OSPF邻居发现 :
Hello报文格式:保障属于同一网络,要求双方的Hello间隔和Dead间隔保持一直
Network Mask :网络掩码
Hello Interval :Hello间隔 Hello 默认10s每次
Options:选项
Router Priority:路由器优先级(0-255),默认值为1:用于在BMA和NBMA中选举DR和BDR
Router Dead Interval :路由器死亡间隔,取值默认40,为Hello间隔的4倍。4次没有收到Hello则邻居死亡。
DR:指定路由器:用于减少邻接关系数量,避免重复的LSA,减少了LAS的数量,在2way状态下选举,根据路由器的优先级越大越优先,优先级一样比较RouterID比较越大越优先。优先级为0不参与DR的竞选。DR有不可抢占性。
BDR:备份指定路由器:作为DR设备的备份。
LSA链路状态通告:既能传递路由信息还能传递拓扑信息 30分钟更新一次 1800s
DD报文:数据库描述报文(相当于目录)减少LAS 交互的数量,模拟TCP传递方式
OSPF区域:OSPF 支持区域化设计 区域0为骨干区域
注意:DR的选举原则
1.优先级为0的不参与选举;
2.优先级高的路由器为DR;
3.优先级相同时,以router ID 大为DR;
OSPF企业级单区域部署
要求:
1.全程使用OSPF单区域部署
2.Client处使用DHCP自动获取IP地址
一:基础部署
分别给路由器设置IP地址
R1(Client):
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]int g0/0/0
[Huawei-GigabitEthernet0/0/0]ip address 192.168.1.1 24
[Huawei-GigabitEthernet0/0/0]int g0/0/1
[Huawei-GigabitEthernet0/0/1]ip address 192.168.100.1 24
R2:
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]int g0/0/1
[Huawei-GigabitEthernet0/0/1]ip address 192.168.100.2 24
[Huawei-GigabitEthernet0/0/1]int g0/0/0
[Huawei-GigabitEthernet0/0/0]ip address 192.168.111.1 24
R3:
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]int g0/0/0
[Huawei-GigabitEthernet0/0/0]ip address 192.168.111.2 24
[Huawei-GigabitEthernet0/0/0]int g0/0/1
[Huawei-GigabitEthernet0/0/1]ip address 192.168.222.1 24
R4:
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]int g0/0/0
[Huawei-GigabitEthernet0/0/0]ip address 192.168.222.2 24
[Huawei-GigabitEthernet0/0/0]int g0/0/1
[Huawei-GigabitEthernet0/0/1]ip address 192.168.233.1 24
R5:
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]int g0/0/0
[Huawei-GigabitEthernet0/0/0]ip address 192.168.233.2 24
[Huawei-GigabitEthernet0/0/0]int g0/0/1
[Huawei-GigabitEthernet0/0/1]ip address 192.168.200.1 24
R6(Server):
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]int g0/0/1
[Huawei-GigabitEthernet0/0/1]ip address 192.168.200.2 24
[Huawei-GigabitEthernet0/0/1]int g0/0/0
[Huawei-GigabitEthernet0/0/0]ip address 192.168.2.1 24
二:OSPF部署
所有路由器部署OSPF
R1:
[Huawei]ospf 1 router-id 1.1.1.1 //开启OSPF进程并且指定RID
[Huawei-ospf-1]area 0 //进入区域0
[Huawei-ospf-1-area-0.0.0.0]network 192.168.1.0 0.0.0.255 //宣告直连网段,反掩码
[Huawei-ospf-1-area-0.0.0.0]network 192.168.100.0 0.0.0.255
[Huawei]dhcp enable
Info: The operation may take a few seconds. Please wait for a moment.done.
[Huawei]ip pool xingdian
Info: It's successful to create an IP address pool.
[Huawei-ip-pool-xingdian]network 192.168.1.0 mask 24
[Huawei-ip-pool-xingdian]gateway-list 192.168.1.1
[Huawei-ip-pool-xingdian]dns-list 8.8.8.8
[Huawei-ip-pool-xingdian]int g0/0/0
[Huawei-GigabitEthernet0/0/0]dhcp select global
R2:
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]ospf 1 router-id 2.2.2.2
[Huawei-ospf-1]area 0
[Huawei-ospf-1-area-0.0.0.0]network 192.168.100.0 0.0.0.255
[Huawei-ospf-1-area-0.0.0.0]network 192.168.111.0 0.0.0.255
R3:
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]ospf 1 router-id 3.3.3.3
[Huawei-ospf-1]area 0
[Huawei-ospf-1-area-0.0.0.0]network 192.168.111.0 0.0.0.255
[Huawei-ospf-1-area-0.0.0.0]network 192.168.222.0 0.0.0.255
R4:
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]ospf 1 router-id 4.4.4.4
[Huawei-ospf-1]area 0
[Huawei-ospf-1-area-0.0.0.0]net
[Huawei-ospf-1-area-0.0.0.0]network 192.168.222.0 0.0.0.255
[Huawei-ospf-1-area-0.0.0.0]network 192.168.233.0 0.0.0.255
R5:
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]ospf 1 router-id 5.5.5.5
[Huawei-ospf-1]area 0
[Huawei-ospf-1-area-0.0.0.0]network 192.168.233.0 0.0.0.255
[Huawei-ospf-1-area-0.0.0.0]network 192.168.200.0 0.0.0.255
R6:
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]ospf 1 router-id 6.6.6.6
[Huawei-ospf-1]area 0
[Huawei-ospf-1-area-0.0.0.0]network 192.168.2.0 0.0.0.255
[Huawei-ospf-1-area-0.0.0.0]network 192.168.200.0 0.0.0.255
三:验证
注意:
1.OSPF状态
Sep 21 2019 01:06:33-08:00 Huawei %%01OSPF/4/NBR_CHANGE_E(l)[0]:Neighbor changes
event: neighbor status changed. (ProcessId=256, NeighborAddress=1.100.168.192,
NeighborEvent=HelloReceived, NeighborPreviousState=Down, NeighborCurrentState=In
it)
Sep 21 2019 01:06:33-08:00 Huawei %%01OSPF/4/NBR_CHANGE_E(l)[1]:Neighbor changes
event: neighbor status changed. (ProcessId=256, NeighborAddress=1.100.168.192,
NeighborEvent=2WayReceived, NeighborPreviousState=Init, NeighborCurrentState=2Wa
y)
Sep 21 2019 01:06:33-08:00 Huawei %%01OSPF/4/NBR_CHANGE_E(l)[2]:Neighbor changes
event: neighbor status changed. (ProcessId=256, NeighborAddress=1.100.168.192,
NeighborEvent=AdjOk?, NeighborPreviousState=2Way, NeighborCurrentState=ExStart)
Sep 21 2019 01:06:33-08:00 Huawei %%01OSPF/4/NBR_CHANGE_E(l)[3]:Neighbor changes
event: neighbor status changed. (ProcessId=256, NeighborAddress=1.100.168.192,
NeighborEvent=NegotiationDone, NeighborPreviousState=ExStart, NeighborCurrentSta
te=Exchange)
Sep 21 2019 01:06:33-08:00 Huawei %%01OSPF/4/NBR_CHANGE_E(l)[4]:Neighbor changes
event: neighbor status changed. (ProcessId=256, NeighborAddress=1.100.168.192,
NeighborEvent=ExchangeDone, NeighborPreviousState=Exchange, NeighborCurrentState
=Loading)
Sep 21 2019 01:06:33-08:00 Huawei %%01OSPF/4/NBR_CHANGE_E(l)[5]:Neighbor changes
event: neighbor status changed. (ProcessId=256, NeighborAddress=1.100.168.192,
NeighborEvent=LoadingDone, NeighborPreviousState=Loading, NeighborCurrentState=F
ull)
2.查看路由表
[Huawei]display 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
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
192.168.1.0/24 Direct 0 0 D 192.168.1.1 GigabitEthernet0/0/0
192.168.1.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0
192.168.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0
192.168.2.0/24 OSPF 10 6 D 192.168.100.2 GigabitEthernet0/0/1
192.168.100.0/24 Direct 0 0 D 192.168.100.1 GigabitEthernet0/0/1
192.168.100.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1
192.168.100.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1
192.168.111.0/24 OSPF 10 2 D 192.168.100.2 GigabitEthernet0/0/1
192.168.200.0/24 OSPF 10 5 D 192.168.100.2 GigabitEthernet0/0/1
192.168.222.0/24 OSPF 10 3 D 192.168.100.2 GigabitEthernet0/0/1
192.168.233.0/24 OSPF 10 4 D 192.168.100.2 GigabitEthernet0/0/1
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
3.查看OSPF邻居表的简要信息
R1:
[Huawei]display ospf 1 peer brief
OSPF Process 1 with Router ID 1.1.1.1
Peer Statistic Information
----------------------------------------------------------------------------
Area Id Interface Neighbor id State
0.0.0.0 GigabitEthernet0/0/1 2.2.2.2 Full
----------------------------------------------------------------------------
R2:
[Huawei]display ospf 1 peer brief
OSPF Process 1 with Router ID 2.2.2.2
Peer Statistic Information
----------------------------------------------------------------------------
Area Id Interface Neighbor id State
0.0.0.0 GigabitEthernet0/0/1 1.1.1.1 Full
0.0.0.0 GigabitEthernet0/0/0 3.3.3.3 Full
----------------------------------------------------------------------------
4.查看OSPF邻居表的详细信息
[Huawei]display ospf 1 peer
OSPF Process 1 with Router ID 1.1.1.1
Neighbors
Area 0.0.0.0 interface 192.168.100.1(GigabitEthernet0/0/1)'s neighbors
Router ID: 2.2.2.2 Address: 192.168.100.2
State: Full Mode:Nbr is Master Priority: 1
DR: 192.168.100.1 BDR: 192.168.100.2 MTU: 0
Dead timer due in 29 sec
Retrans timer interval: 5
Neighbor is up for 00:15:10
Authentication Sequence: [ 0 ]
5.查看所有配置
[Huawei]display current-configuration
[V200R003C00]
#
snmp-agent local-engineid 800007DB03000000000000
snmp-agent
#
clock timezone China-Standard-Time minus 08:00:00
#
portal local-server load portalpage.zip
#
drop illegal-mac alarm
#
set cpu-usage threshold 80 restore 75
#
aaa
authentication-scheme default
authorization-scheme default
accounting-scheme default
domain default
domain default_admin
local-user admin password cipher %$%$K8m.Nt84DZ}e#<0`8bmE3Uw}%$%$
local-user admin service-type http
#
firewall zone Local
priority 15
#
interface GigabitEthernet0/0/0
ip address 192.168.1.1 255.255.255.0
#
interface GigabitEthernet0/0/1
ip address 192.168.100.1 255.255.255.0
#
interface GigabitEthernet0/0/2
#
interface NULL0
#
ospf 1 router-id 1.1.1.1
area 0.0.0.0
network 192.168.1.0 0.0.0.255
network 192.168.100.0 0.0.0.255
#
user-interface con 0
authentication-mode password
user-interface vty 0 4
user-interface vty 16 20
#
wlan ac
#
return
interface GigabitEthernet0/0/1
ip address 192.168.100.1 255.255.255.0
interface GigabitEthernet0/0/2
interface NULL0
ospf 1 router-id 1.1.1.1
area 0.0.0.0
network 192.168.1.0 0.0.0.255
network 192.168.100.0 0.0.0.255
user-interface con 0
authentication-mode password
user-interface vty 0 4
user-interface vty 16 20
wlan ac
return