目录
实验原理
案例
路由器配置单区域OSPF基本功能
单区域总结
路由器配置多区域OSPF基本功能
多区域特点
OSPF(Open Shortest Path First,开放最短路径优先)是互联网的标准协议,是为克服RIP的缺点而开发的。目前针对IPv4协议使用的 是OSPFv2。OSPF最主要的特征就是使用分布式的链路状态协议(Link State Protocol)。当链路状态发生变化时,OSPF路由器使用可靠的洪泛法 (Flooding)向本自治系统中所有路由器发送信息,发送的信息是与本 路由器相邻的所有路由器的链路状态,包括:本路由器与哪些路由器相邻,以及该链路的“度量”(Metric)等。
由于一个路由器的链路状态只涉及到与相邻路由器的连通状态,而 与整个互联网的规模并无直接关系,因此当互联网规模很大时,OSPF 协议要比距离向量协议RIP好得多。
所 有 的 路 由 器 都 维 护 一 个 链 路 状 态 数 据 库 ( Link State DataBase,LSDB),这个数据库实际上就是全网的拓扑结构图。这个拓扑结构图在全网范围内是一致的(这称为链路状态数据库的同步)。每一个路由器使用链路状态数据库中的数据,构造出自己的路由表(例如,使用Dijkstra的最短路径路由算法)。OSPF的链路状态数据库能较快地进行更新,使各个路由器能及时更新其路由表。OSPF 的更新过程 收敛得快,没有“坏消息传播得慢”的问题,不会产生路由环路。
为了使 OSPF 能够用于规模很大的网络,OSPF 将一个自治系统再划分为若干个更小的范围,叫作区域(Area)。区域内的详细拓扑信息不向其他区域发送,区域间传递的是聚合的路由信息,而不是详细的描 述拓扑结构的链路状态信息,减少了整个网络上的通信量。每个区域都 有自己的LSDB,不同区域的LSDB是不同的。
为了使每一个区域能够和本区域以外的区域进行通信,OSPF使用层次结构的区域划分,将区域分为两层,在上层的区域叫作主干区域 (Backbone Area),用于连通其他在下层的区域。主干区域的标识符规定为0.0.0.0。下层区域都通过主干区域实现区域之间的通信。在一 个采用OSPF的自治系统中,只能有一个主干区域。
OSPF直接使用 IP 数据报传送 OSPF分组,协议号为 89。OSPF 有 五种类型的分组:Hello(问候)分组、DD(Database Description, 数据库描述)分组、LSR(Link State Request,链路状态请求)分 组、LSU(Link State Update,链路状态更新)分组和 LSA(Link State Acknowledgment,链路状态确认)分组。每个OSPF分组构成的数据报很短,不需要分片。
此外,OSPF对不同的链路可根据IP分组的不同服务类型TOS而设置 成不同的代价。因此,OSPF 对于不同类型的业务可计算出不同的路 由。如果到同一个目的网络有多条相同代价的路径,那么可以将通信量 分配给这几条路径,实现多路径间的负载平衡。
所有在 OSPF 路由器之间交换的分组都具有鉴别的功能。OSPF支持可变长度的子网划分和无分类编址CIDR。
由于网络中的链路状态可能经常发生变化,因此OSPF让每一个链路状态都带上一个32位的序号,序号越大,状态就越新。
对 于 多 点 接 入 的 局 域 网 , OSPF协议采用了指定路由器(Designated Router)的方法,使广播的信息量大大减少。指定的路由器代表该局域网上所有的链路向连接到该网络上的各OSPF路由器发送状态信息。
具体配置如下
配置路由器RTA
sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname RTSA
[RTSA]sysname RTA
#配置连接计算机端口的ip地址
[RTA]interface g0/0/2
[RTA-GigabitEthernet0/0/2]ip address 10.1.10.1 24
Sep 23 2023 10:35:40-08:00 RTA %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP
on the interface GigabitEthernet0/0/2 has entered the UP state.
[RTA-GigabitEthernet0/0/2]qu
[RTA]undo info-center enable
Info: Information center is disabled.
[RTA]qu
#配置连接路由器的端口的IP地址
[RTA]int g0/0/0
[RTA-GigabitEthernet0/0/0]ip address 172.16.101.1 24
[RTA-GigabitEthernet0/0/0]qu
配置路由器RTB
sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname RTB
[RTB]int g0/0/0
[RTB-GigabitEthernet0/0/0]ip address 172.16.101.2 24
Sep 23 2023 10:37:20-08:00 RTB %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP
on the interface GigabitEthernet0/0/0 has entered the UP state.
[RTB-GigabitEthernet0/0/0]qu
[RTB]int g0/0/1
[RTB-GigabitEthernet0/0/1]ip address 172.16.102.1 24
Sep 23 2023 10:37:34-08:00 RTB %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP
on the interface GigabitEthernet0/0/1 has entered the UP state.
[RTB-GigabitEthernet0/0/1]qu
配置路由器RTC
sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname RTC
[RTC]int g0/0/0
[RTC-GigabitEthernet0/0/0]ip address 172.16.103.2 24
Sep 23 2023 10:38:03-08:00 RTC %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP
on the interface GigabitEthernet0/0/0 has entered the UP state.
[RTC-GigabitEthernet0/0/0]
[RTC-GigabitEthernet0/0/0]qu
[RTC]undo info-center enable
Info: Information center is disabled.
[RTC]int g0/0/1
[RTC-GigabitEthernet0/0/1]ip address 172.16.102.2 24
[RTC-GigabitEthernet0/0/1]qu
配置路由器RTD
sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname RTD
[RTD]int g0/0/2
[RTD-GigabitEthernet0/0/2]ip address 11.1.50.1 24
Sep 23 2023 10:40:24-08:00 RTD %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP
on the interface GigabitEthernet0/0/2 has entered the UP state.
[RTD-GigabitEthernet0/0/2]qu
[RTD]int g0/0/0
[RTD-GigabitEthernet0/0/0]ip address 172.16.103.1 24
[RTD-GigabitEthernet0/0/0]
Sep 23 2023 10:40:38-08:00 RTD %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP
on the interface GigabitEthernet0/0/0 has entered the UP state.
[RTD-GigabitEthernet0/0/0]qu
[RTD]
配置各路由器的单区域OSPF基本功能
sys
Enter system view, return user view with Ctrl+Z.
# 路由器的 Router ID是一台路由器在自治系统中的唯一标识,是一个 32 比特无符号整数,用点分十进制数表示。默认情况下,路由器系统会从当前接口的 IP 地址中自动选取一个最大值作为 Router ID。手动配置 Router ID时,必须保证自治系统中任意两台 Router ID都不相同。通常的做法是将RouterID配置为与该设备某个端口的 IP地址一致
[RTA]router id 10.1.10.1
Info: Router ID has been modified, please reset the relative protocols manually
to update the Router ID.
#使能OSPF进程,指定OSPF进程为1,进程号取值范围是1~65535。默认值是1
[RTA]ospf 1
#创建区域,单区域只有一个主干区域。主干区域编号为0
[RTA-ospf-1]area 0
# 指定运行OSPE接口和接口所属区域
# OSPF使用反掩码,例如0.0.0.255表示掩码长度为24位
# 接口的 IP 地址掩码长度必须大于等于 network 命令中的掩码长度,且接口不带子网的 IP 地址必须在network命令指定的网段范围之内。
# undo network命令用来删除运行OSPE协议的接口
# 默认情况下,接口不属于任何区域。
[RTA-ospf-1-area-0.0.0.0]network 10.1.10.0 0.0.0.255
[RTA-ospf-1-area-0.0.0.0]network 172.16.101.0 0.0.0.255
[RTA-ospf-1-area-0.0.0.0]qu
[RTA-ospf-1]qu
[RTA]display IP routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 10 Routes : 10
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.1.10.0/24 Direct 0 0 D 10.1.10.1 GigabitEthernet
0/0/2
10.1.10.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/2
10.1.10.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/2
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
172.16.101.0/24 Direct 0 0 D 172.16.101.1 GigabitEthernet
0/0/0
172.16.101.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
172.16.101.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
[RTA]display IP routing-table protocol ospf
sys
Enter system view, return user view with Ctrl+Z.
[RTB]router id 172.16.101.2
[RTB]ospf 1
[RTB-ospf-1]area 0
[RTB-ospf-1-area-0.0.0.0]network 172.16.101.0 0.0.0.255
[RTB-ospf-1-area-0.0.0.0]network 172.16.102.0 0.0.0.255
[RTB-ospf-1-area-0.0.0.0]qu
[RTB-ospf-1]qu
[RTB]display IP routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 11 Routes : 11
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.1.10.0/24 OSPF 10 2 D 172.16.101.1 GigabitEthernet
0/0/0
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
172.16.101.0/24 Direct 0 0 D 172.16.101.2 GigabitEthernet
0/0/0
172.16.101.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
172.16.101.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
172.16.102.0/24 Direct 0 0 D 172.16.102.1 GigabitEthernet
0/0/1
172.16.102.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/1
172.16.102.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/1
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
[RTB]display 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 :
Destinations : 1 Routes : 1
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.1.10.0/24 OSPF 10 2 D 172.16.101.1 GigabitEthernet
0/0/0
OSPF routing table status :
Destinations : 0 Routes : 0
可以通过以下命令查看配置结果
# 查看OSPE 的概要信息
display ospf brief
display ospf 1 brief # 查看OSPE的接口信息
display ospf interface all
display ospf l interface gigabitethernet 0/0/0 # 查看OSPE的链路状态数据库(LSDB)详细信息
display ospf lsdb
display ospf 1 lsdb
# 查看OSPE的链路状态数据库(LSDB)概要信息
display ospf lsdb brief
display ospf 1 lsdb brief
# 查看OSPE链路状态数据库中 Router LSA的相关信息
display ospf lsdb router
display ospf 1 lsdb router
# 查看OSPE链路状态数据库中 Network LSA的相关信息
display ospf lsdb network 10.1.10.1
display ospf 1 lsdb network 172.16.101.0
# 查看 OSPE 中各区域邻居的详细信息
display ospf peer
# 查看 OSPE 中各区域邻居的概要信息
display ospf l peer brief
# 查看OSPE路由表的信息。
display ospf routing
display ospf 1 routing router-id 172.16.103.2 # 查看路由器 IP路由表。
display IP routing-table #查看路由器IP路由表中的OSPE路由
displayIP routing-table protocol ospf
PC端互ping结果如下
PC>ping 11.1.50.11
Ping 11.1.50.11: 32 data bytes, Press Ctrl_C to break
Request timeout!
From 11.1.50.11: bytes=32 seq=2 ttl=124 time=31 ms
From 11.1.50.11: bytes=32 seq=3 ttl=124 time=16 ms
From 11.1.50.11: bytes=32 seq=4 ttl=124 time=31 ms
From 11.1.50.11: bytes=32 seq=5 ttl=124 time=32 ms
--- 11.1.50.11 ping statistics ---
5 packet(s) transmitted
4 packet(s) received
20.00% packet loss
round-trip min/avg/max = 0/27/32 ms
PC>tracert 11.1.50.11
traceroute to 11.1.50.11, 8 hops max
(ICMP), press Ctrl+C to stop
1 10.1.10.1 16 ms 15 ms 16 ms
2 172.16.101.2 16 ms 15 ms 16 ms
3 172.16.102.2 31 ms 16 ms 31 ms
4 172.16.103.1 16 ms 31 ms 31 ms
5 11.1.50.11 31 ms 16 ms 31 ms
PC>ping 10.1.10.11
Ping 10.1.10.11: 32 data bytes, Press Ctrl_C to break
From 10.1.10.11: bytes=32 seq=1 ttl=124 time=31 ms
From 10.1.10.11: bytes=32 seq=2 ttl=124 time=31 ms
From 10.1.10.11: bytes=32 seq=3 ttl=124 time=31 ms
From 10.1.10.11: bytes=32 seq=4 ttl=124 time=16 ms
From 10.1.10.11: bytes=32 seq=5 ttl=124 time=31 ms
--- 10.1.10.11 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 16/28/31 ms
PC>tracert 10.1.10.11
traceroute to 10.1.10.11, 8 hops max
(ICMP), press Ctrl+C to stop
1 11.1.50.1 <1 ms 16 ms 15 ms
2 172.16.103.2 16 ms 16 ms <1 ms
3 172.16.102.1 31 ms 15 ms 16 ms
4 172.16.101.1 16 ms 31 ms 31 ms
5 10.1.10.11 31 ms 16 ms 31 ms
对RTB的g0/0/0端口抓包,可以看出
1.ospf是通过IPv4协议进行分组的,使用的端口为89号端口
2.使用组播地址作为目的地址(224.0.0.5)
这里可以看他属于什么包,以及版本(version)
这里可以看到包的信息
关闭RTD的g0/0/0端口
sys
Enter system view, return user view with Ctrl+Z.
[RTD]int g0/0/0
[RTD-GigabitEthernet0/0/0]shutdown
Sep 23 2023 13:32:31-08:00 RTD %%01IFPDT/4/IF_STATE(l)[0]:Interface GigabitEther
net0/0/0 has turned into DOWN state.
[RTD-GigabitEthernet0/0/0]
[RTD-GigabitEthernet0/0/0]
Sep 23 2023 13:32:31-08:00 RTD %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP
on the interface GigabitEthernet0/0/0 has entered the DOWN state.
[RTD-GigabitEthernet0/0/0]
Sep 23 2023 13:32:31-08:00 RTD %%01OSPF/3/NBR_CHG_DOWN(l)[2]:Neighbor event:neig
hbor state changed to Down. (ProcessId=256, NeighborAddress=2.103.16.172, Neighb
orEvent=KillNbr, NeighborPreviousState=Full, NeighborCurrentState=Down)
[RTD-GigabitEthernet0/0/0]
Sep 23 2023 13:32:31-08:00 RTD %%01OSPF/3/NBR_DOWN_REASON(l)[3]:Neighbor state l
eaves full or changed to Down. (ProcessId=256, NeighborRouterId=2.103.16.172, Ne
ighborAreaId=0, NeighborInterface=GigabitEthernet0/0/0,NeighborDownImmediate rea
son=Neighbor Down Due to Kill Neighbor, NeighborDownPrimeReason=Physical Interfa
ce State Change, NeighborChangeTime=2023-09-23 13:32:31-08:00)
[RTD-GigabitEthernet0/0/0]
在RTB的g0/0/0端口抓包,抓到了LSU,LSA
LSU信息如下
LSA信息如下
再次开启RTD的g0/0/0端口
sys
Enter system view, return user view with Ctrl+Z.
[RTD]int g0/0/0
[RTD-GigabitEthernet0/0/0]undo shutdown
[RTD-GigabitEthernet0/0/0]
Sep 23 2023 13:38:44-08:00 RTD %%01IFPDT/4/IF_STATE(l)[0]:Interface GigabitEther
net0/0/0 has turned into UP state.
[RTD-GigabitEthernet0/0/0]
Sep 23 2023 13:38:44-08:00 RTD %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP
on the interface GigabitEthernet0/0/0 has entered the UP state.
RTC的g0/0/0端口抓包信息如下
DD信息如下
LSR信息如下
LSU信息如下
LSA信息如下
•企业内网,如果仅仅配置一个区域,那必须是OSPF区域0,主干区域
•OSPF进程号的作用是:在同一个额路由器上区分不同的OSPF协议,不同路由器上的进程号可以相同也可以不相同。
•OSPF的Router-ID用于标识不同的路由器们必须确保全网唯一
•OSPF Ruter-id最大特点:稳定。一旦确定,就无法修改,除非重启OSPF协议或者重启路由器
OSPF区域的类型:
所有的非骨干区域,必须与骨干区域直接相连,否则区域之间无法互通
来看下面的案例:
在第一次配置的路由的基础上,配置多区域OSPF, 配置RTA
sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname RTA
[RTA]router id 10.1.10.1
Info: Router ID has been modified, please reset the relative protocols manually
to update the Router ID.
[RTA]ospf 1
[RTA-ospf-1]area 1
[RTA-ospf-1-area-0.0.0.1]network 10.1.10.0 0.0.0.255
[RTA-ospf-1-area-0.0.0.1]network 172.16.101.0 0.0.0.255
[RTA-ospf-1-area-0.0.0.1]qu
[RTA-ospf-1]qu
#路由器都配置ospf后
[RTA]display IP routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 13 Routes : 13
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.1.10.0/24 Direct 0 0 D 10.1.10.1 GigabitEthernet
0/0/2
10.1.10.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/2
10.1.10.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/2
11.1.50.0/24 OSPF 10 4 D 172.16.101.2 GigabitEthernet
0/0/0
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
172.16.101.0/24 Direct 0 0 D 172.16.101.1 GigabitEthernet
0/0/0
172.16.101.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
172.16.101.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
172.16.102.0/24 OSPF 10 2 D 172.16.101.2 GigabitEthernet
0/0/0
172.16.103.0/24 OSPF 10 3 D 172.16.101.2 GigabitEthernet
0/0/0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
[RTA]display IP routing-table protocol ospf
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 3 Routes : 3
OSPF routing table status :
Destinations : 3 Routes : 3
Destination/Mask Proto Pre Cost Flags NextHop Interface
11.1.50.0/24 OSPF 10 4 D 172.16.101.2 GigabitEthernet
0/0/0
172.16.102.0/24 OSPF 10 2 D 172.16.101.2 GigabitEthernet
0/0/0
172.16.103.0/24 OSPF 10 3 D 172.16.101.2 GigabitEthernet
0/0/0
OSPF routing table status :
Destinations : 0 Routes : 0
配置RTB
sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname RTB
[RTB]router id 172.16.101.2
Info: Router ID has been modified, please reset the relative protocols manually
to update the Router ID.
[RTB]ospf 1
[RTB-ospf-1]area 0
[RTB-ospf-1-area-0.0.0.0]network 172.16.102.0 0.0.0.255
[RTB-ospf-1-area-0.0.0.0]qu
[RTB-ospf-1]area 1
[RTB-ospf-1-area-0.0.0.1]network 172.16.101.0 0.0.0.255
[RTB-ospf-1-area-0.0.0.1]qu
[RTB-ospf-1]qu
#路由器都配置ospf后
[RTB]display IP routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 13 Routes : 13
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.1.10.0/24 OSPF 10 2 D 172.16.101.1 GigabitEthernet
0/0/0
11.1.50.0/24 OSPF 10 3 D 172.16.102.2 GigabitEthernet
0/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
172.16.101.0/24 Direct 0 0 D 172.16.101.2 GigabitEthernet
0/0/0
172.16.101.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
172.16.101.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
172.16.102.0/24 Direct 0 0 D 172.16.102.1 GigabitEthernet
0/0/1
172.16.102.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/1
172.16.102.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/1
172.16.103.0/24 OSPF 10 2 D 172.16.102.2 GigabitEthernet
0/0/1
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
[RTB]display IP routing-table protocol ospf
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 3 Routes : 3
OSPF routing table status :
Destinations : 3 Routes : 3
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.1.10.0/24 OSPF 10 2 D 172.16.101.1 GigabitEthernet
0/0/0
11.1.50.0/24 OSPF 10 3 D 172.16.102.2 GigabitEthernet
0/0/1
172.16.103.0/24 OSPF 10 2 D 172.16.102.2 GigabitEthernet
0/0/1
OSPF routing table status :
Destinations : 0 Routes : 0
配置RTC
sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname RTC
[RTC]router id 172.16.103.2
Info: Router ID has been modified, please reset the relative protocols manually
to update the Router ID.
[RTC]ospf 1
[RTC-ospf-1]area 0
[RTC-ospf-1-area-0.0.0.0]network 172.16.102.0 0.0.0.255
[RTC-ospf-1-area-0.0.0.0]qu
[RTC-ospf-1]area 2
[RTC-ospf-1-area-0.0.0.2]network 172.16.103.0 0.0.0.255
[RTC-ospf-1-area-0.0.0.2]qu
[RTC-ospf-1]qu
[RTC]
#各路由器都配置ospf后
[RTC]display IP routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 13 Routes : 13
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.1.10.0/24 OSPF 10 3 D 172.16.102.1 GigabitEthernet
0/0/1
11.1.50.0/24 OSPF 10 2 D 172.16.103.1 GigabitEthernet
0/0/0
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
172.16.101.0/24 OSPF 10 2 D 172.16.102.1 GigabitEthernet
0/0/1
172.16.102.0/24 Direct 0 0 D 172.16.102.2 GigabitEthernet
0/0/1
172.16.102.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/1
172.16.102.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/1
172.16.103.0/24 Direct 0 0 D 172.16.103.2 GigabitEthernet
0/0/0
172.16.103.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
172.16.103.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
[RTC]display IP routing-table protocol ospf
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 3 Routes : 3
OSPF routing table status :
Destinations : 3 Routes : 3
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.1.10.0/24 OSPF 10 3 D 172.16.102.1 GigabitEthernet
0/0/1
11.1.50.0/24 OSPF 10 2 D 172.16.103.1 GigabitEthernet
0/0/0
172.16.101.0/24 OSPF 10 2 D 172.16.102.1 GigabitEthernet
0/0/1
OSPF routing table status :
Destinations : 0 Routes : 0
配置RTD
sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname RTD
[RTD]router id 11.1.50.1
Info: Router ID has been modified, please reset the relative protocols manually
to update the Router ID.
[RTD]ospf 1
[RTD-ospf-1]area 2
[RTD-ospf-1-area-0.0.0.2]network 11.1.50.0 0.0.0.255
[RTD-ospf-1-area-0.0.0.2]network 172.16.103.0 0.0.0.255
[RTD-ospf-1-area-0.0.0.2]qu
[RTD-ospf-1]qu
[RTD]
[RTD]display IP routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 13 Routes : 13
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.1.10.0/24 OSPF 10 4 D 172.16.103.2 GigabitEthernet
0/0/0
11.1.50.0/24 Direct 0 0 D 11.1.50.1 GigabitEthernet
0/0/2
11.1.50.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/2
11.1.50.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/2
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
172.16.101.0/24 OSPF 10 3 D 172.16.103.2 GigabitEthernet
0/0/0
172.16.102.0/24 OSPF 10 2 D 172.16.103.2 GigabitEthernet
0/0/0
172.16.103.0/24 Direct 0 0 D 172.16.103.1 GigabitEthernet
0/0/0
172.16.103.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
172.16.103.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
[RTD]display IP routing-table protocol ospf
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 3 Routes : 3
OSPF routing table status :
Destinations : 3 Routes : 3
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.1.10.0/24 OSPF 10 4 D 172.16.103.2 GigabitEthernet
0/0/0
172.16.101.0/24 OSPF 10 3 D 172.16.103.2 GigabitEthernet
0/0/0
172.16.102.0/24 OSPF 10 2 D 172.16.103.2 GigabitEthernet
0/0/0
OSPF routing table status :
Destinations : 0 Routes : 0
可以用以下命令查看配置结果
# 查看OSPE的概要信息。
displayospf brief
display ospf l brief
# 查看OSPE的接口信息。
displayospf interface all
display ospf interface gigabitethernet 0/0/0
#查看OSPE的链路状态数据库(LSDB)详细信息。
display ospf lsdb
display ospf 1lsdb
# 查看 OSPE的链路状态数据库(LSDB)概要信息
display ospf lsdb brief
displayospf1 lsdb brief
# 查看OSPE链路状态数据库中 Router LSA的相关信息
display ospf lsdb router
display ospf 1 lsdb router
# 查看OSPE链路状态数据库中Network LSA的相关信息
display ospf lsdb network 10.1.10.1
display ospf 1 lsdb network 172.16.101.0
# 查看OSPE 中各区域邻居的详细信息
display ospf peer
#查看OSPE 中各区域邻居的概要信息
display ospf l peer brief
# 查看OSPE路由表的信息。
display ospf routing
display ospf l routing router-id 172.16.103.2
#查看路由器IP路由表。
display IP routing-table
# 查看路由器 IP路由表中的OSPE路由
display IP routing-table protocol ospf
两个PC互ping
PC>ping 11.1.50.1
Ping 11.1.50.1: 32 data bytes, Press Ctrl_C to break
From 11.1.50.1: bytes=32 seq=1 ttl=252 time=47 ms
From 11.1.50.1: bytes=32 seq=2 ttl=252 time=31 ms
From 11.1.50.1: bytes=32 seq=3 ttl=252 time=47 ms
From 11.1.50.1: bytes=32 seq=4 ttl=252 time=31 ms
From 11.1.50.1: bytes=32 seq=5 ttl=252 time=32 ms
--- 11.1.50.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 31/37/47 ms
PC>tracert 11.1.50.11
traceroute to 11.1.50.11, 8 hops max
(ICMP), press Ctrl+C to stop
1 10.1.10.1 16 ms <1 ms 15 ms
2 172.16.101.2 16 ms <1 ms 16 ms
3 172.16.102.2 31 ms 15 ms 16 ms
4 172.16.103.1 31 ms 32 ms 15 ms
5 11.1.50.11 31 ms 32 ms 15 ms
Ping 10.1.10.11: 32 data bytes, Press Ctrl_C to break
From 10.1.10.11: bytes=32 seq=1 ttl=124 time=31 ms
From 10.1.10.11: bytes=32 seq=2 ttl=124 time=31 ms
From 10.1.10.11: bytes=32 seq=3 ttl=124 time=32 ms
From 10.1.10.11: bytes=32 seq=4 ttl=124 time=31 ms
From 10.1.10.11: bytes=32 seq=5 ttl=124 time=31 ms
--- 10.1.10.11 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 31/31/32 ms
PC>tracert 10.1.10.11
traceroute to 10.1.10.11, 8 hops max
(ICMP), press Ctrl+C to stop
1 11.1.50.1 15 ms <1 ms 16 ms
2 172.16.103.2 15 ms 16 ms <1 ms
3 172.16.102.1 31 ms 16 ms 31 ms
4 172.16.101.1 16 ms 31 ms 16 ms
5 10.1.10.11 31 ms 31 ms 16 ms
跟上个实验一样,关闭RTD的g0/0/0端口,对RTB的g0/0/0端口进行抓包,可以看到ospf的包明显增多了(LSU,LSA,DD),因为在单区域抓包中,主要捕获到区域内的报文,包括网络、路由器和链路状态信息。而在多区域抓包中,会捕获到 ABR(区域边界路由器) 之间交换的报文,这些报文包含了不同区域之间的路由信息和汇总信息。
开启RTC的g0/0/0端口 ,对RTC的g0/0/0端口进行抓包
可以注意到一点,多区域ospf响应要比单区域慢一些,这是因为 多区域OSPF 使用了洪泛(flooding)机制来传播 LSA 更新信息,每个路由器都需要将 LSA 发送给它的邻居,然后邻居再将其转发给它们的邻居,以此类推,直到 LSA 到达整个网络。
以下是RTB的g0/0/0端口的抓包,这里可以比较清楚的看到ospf的更新机制
1.DR使用LSA包回复发生变化的路由器,并使用组播地址224.0.0.5向其他路由器发送LSU包泛洪,每一个收到泛洪的路由器使用LSA包回复DR。
注:如果一个路由器被连接到其他网络,它便转发LSU泛洪分组给这个网络的DR,DR再转发到这个网络中的其他路由器。
2.收到LSU更新包的路由器,更新自己的链路状态数据库(LSDB),并通过最短生成树算法计算出最短路径更新到路由表。
1.ospf多区域通过划分不同的区域,实现了对每个区域进行独立的配置和管理。
2.OSPF 多区域允许跨区域进行路由,通过主干区域将不同区域连接起来。这样可以实现更高效的路径选择和数据流转发。
3.如果某个区域发生故障,其他区域仍然可以正常工作,提高了整个网络的可用性和容错性。
如果佬们发现什么错误或者有抓包的更多细节,请不吝赐教,感谢佬们!!