34、动态ospf

发布时间 2023-08-31 16:12:18作者: 五杀摇滚小拉夫

 ospf是典型的链路状态路由协议,使用最短路径算法计算与选择路由。一般中大型企业使用ospf动态路由协议。

ospf协议的有点:无环路、收敛速度快、扩展型好、支持认证。ospf报文封装在IP报文中,协议号是89。

 

ensp仿真平台搭建:

1、项目功能需求:配置ospf动态路由协议,实现全网互通。把所有的路由划分到区域,若是单区域,采用area0。

拓扑如下:

编辑

2、路由接口ip配置如下:

①、AR1配置如下

Enter system view, return user view with Ctrl+Z.
[Huawei]un in en
Info: Information center is disabled.
[Huawei]sysname AR1
[AR1]interface GigabitEthernet 0/0/0
[AR1-GigabitEthernet0/0/0]ip address 192.168.10.1 24
[AR1-GigabitEthernet0/0/0]quit
[AR1]interface GigabitEthernet 0/0/1
[AR1-GigabitEthernet0/0/1]ip address 10.1.10.254 24
[AR1-GigabitEthernet0/0/1]quit
[AR1]interface GigabitEthernet 0/0/2
[AR1-GigabitEthernet0/0/2]ip address 192.168.30.1 24
[AR1-GigabitEthernet0/0/2]quit
[AR1]quit
<AR1>save
  The current configuration will be written to the device. 
  Are you sure to continue? (y/n)[n]:y
  It will take several minutes to save configuration file, please wait.......
  Configuration file had been saved successfully
  Note: The configuration file will take effect after being activated
<AR1>

②、AR2配置如下

[Huawei]un in en
Info: Information center is disabled.
[Huawei]sysname AR2
[AR2]inter	
[AR2]interface G	
[AR2]interface GigabitEthernet 0/0/0
[AR2-GigabitEthernet0/0/0]ip add 192.168.10.2 24
[AR2-GigabitEthernet0/0/0]quit
[AR2]interface GigabitEthernet 0/0/1
[AR2-GigabitEthernet0/0/1]ip add 192.168.20.2 24
[AR2-GigabitEthernet0/0/1]quit
[AR2]interface GigabitEthernet 0/0/2
[AR2-GigabitEthernet0/0/2]ip add 60.222.227.130  24
[AR2-GigabitEthernet0/0/2]quit
[AR2]quit
<AR2>save
  The current configuration will be written to the device. 
  Are you sure to continue? (y/n)[n]:y
  It will take several minutes to save configuration file, please wait.......
  Configuration file had been saved successfully
  Note: The configuration file will take effect after being activated
<AR2>

③、AR3配置如下

<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]un in en
Info: Information center is disabled.
[Huawei]sys AR3
[AR3]inter G	
[AR3]inter GigabitEthernet 0/0/0
[AR3-GigabitEthernet0/0/0]ip add 192.168.20.3 24
[AR3-GigabitEthernet0/0/0]quit
[AR3]inter GigabitEthernet 0/0/1
[AR3-GigabitEthernet0/0/1]ip add 10.1.20.254 24
[AR3-GigabitEthernet0/0/1]quit
[AR3]inter GigabitEthernet 0/0/2
[AR3-GigabitEthernet0/0/2]ip add 192.168.40.3 24
[AR3-GigabitEthernet0/0/2]quit
[AR3]quit
<AR3>save
  The current configuration will be written to the device. 
  Are you sure to continue? (y/n)[n]:y
  It will take several minutes to save configuration file, please wait.......
  Configuration file had been saved successfully
  Note: The configuration file will take effect after being activated
<AR3>

④、AR4配置如下

<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]un in en
Info: Information center is disabled.
[Huawei]sysname AR4
[AR4]inter  G	
[AR4]inter  GigabitEthernet 0/0/0 
[AR4-GigabitEthernet0/0/0]ip add 60.222.227.1 24
[AR4-GigabitEthernet0/0/0]quit
[AR4]quit
<AR4>save
  The current configuration will be written to the device. 
  Are you sure to continue? (y/n)[n]:y
  It will take several minutes to save configuration file, please wait.......
  Configuration file had been saved successfully
  Note: The configuration file will take effect after being activated
<AR4>

⑤、AR5配置如下

<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]un in en
Info: Information center is disabled.
[Huawei]sysname AR5
[AR5]inter G	
[AR5]inter GigabitEthernet 0/0/0
[AR5-GigabitEthernet0/0/0]ip add 192.168.30.5 24
[AR5-GigabitEthernet0/0/0]quit
[AR5]inter GigabitEthernet 0/0/1
[AR5-GigabitEthernet0/0/1]ip add 192.168.40.5 24
[AR5-GigabitEthernet0/0/1]quit
[AR5]quit
<AR5>save
  The current configuration will be written to the device. 
  Are you sure to continue? (y/n)[n]:y
  It will take several minutes to save configuration file, please wait.......
  Configuration file had been saved successfully
  Note: The configuration file will take effect after being activated
<AR5>

3、路由器接口配置检查接口是否up状态:

AR2 的查询结果如下:display ip interface brief

编辑

4、路由器配置环回接口地址:

编辑

依次 配置如下: LoopBack 0

AR1        1.1.1.1 32

AR2        2.2.2.2 32

AR3        3.3.3.3 32

AR4        4.4.4.4 32

AR5        5.5.5.5 32

5、配置ospf 动态路由

配置ospf时,用Router ID 标识路由器身份。一般手动配置,没有手动配置默认选举路由器中的环回IP作为大的Router ID,当路由器没有配置环回的时候,路由器选择物理接口IP地址作为Router ID。通配符,一般用255.255.255.255 减去网段掩码,比如 192.168.1.1/24,在ospf中宣告得时候:network 192.168.1.1 0.0.0.0.255,通配符0表示精准值,255表示任意值。

配置如下:

<AR1>sys
Enter system view, return user view with Ctrl+Z.
[AR1]osp	
[AR1]ospf 1 ro	
[AR1]ospf 1 router-id 1.1.1.1
[AR1-ospf-1]area 0
[AR1-ospf-1-area-0.0.0.0]network 192.168.10.0 0.0.0.255
[AR1-ospf-1-area-0.0.0.0]network 192.168.30.0 0.0.0.255
[AR1-ospf-1-area-0.0.0.0]network 10.1.10.0    0.0.0.255
[AR1-ospf-1-area-0.0.0.0]network 1.1.1.1      0.0.0.255
[AR1-ospf-1-area-0.0.0.0]quit
[AR1-ospf-1]quit
[AR1]quit
<AR1>save
  The current configuration will be written to the device. 
  Are you sure to continue? (y/n)[n]:y
  It will take several minutes to save configuration file, please wait.......
  Configuration file had been saved successfully
  Note: The configuration file will take effect after being activated
<AR1>
[AR2]ospf 1 router-id 2.2.2.2
[AR2-ospf-1]area 0
[AR2-ospf-1-area-0.0.0.0]network 192.168.10.0 0.0.0.255
[AR2-ospf-1-area-0.0.0.0]network 192.168.20.0 0.0.0.255
[AR2-ospf-1-area-0.0.0.0]network 2.2.2.2      0.0.0.255
[AR2-ospf-1-area-0.0.0.0]quit
[AR2-ospf-1]quit
[AR2]quit
<AR2>save
  The current configuration will be written to the device. 
  Are you sure to continue? (y/n)[n]:y
  It will take several minutes to save configuration file, please wait.......
  Configuration file had been saved successfully
  Note: The configuration file will take effect after being activated
<AR2>
[AR3]ospf 1 router-id 3.3.3.3
[AR3-ospf-1]area 0
[AR3-ospf-1-area-0.0.0.0]network 192.168.20.0 0.0.0.255
[AR3-ospf-1-area-0.0.0.0]network 10.1.20.0    0.0.0.255
[AR3-ospf-1-area-0.0.0.0]network 3.3.3.3      0.0.0.255
[AR3-ospf-1-area-0.0.0.0]network 192.168.40.0 0.0.0.255
[AR3-ospf-1-area-0.0.0.0]quit
[AR3-ospf-1]quit
[AR3]quit
<AR3>save
  The current configuration will be written to the device. 
  Are you sure to continue? (y/n)[n]:y
  It will take several minutes to save configuration file, please wait.......
  Configuration file had been saved successfully
  Note: The configuration file will take effect after being activated
<AR3>
[AR5]ospf 1 router-id 5.5.5.5
[AR5-ospf-1]ar	
[AR5-ospf-1]area 0
[AR5-ospf-1-area-0.0.0.0]network 192.168.30.0 0.0.0.255
[AR5-ospf-1-area-0.0.0.0]network 192.168.40.0 0.0.0.255
[AR5-ospf-1-area-0.0.0.0]network 5.5.5.5      0.0.0.255
[AR5-ospf-1-area-0.0.0.0]quit
[AR5-ospf-1]quit
[AR5]quit
<AR5>save
  The current configuration will be written to the device. 
  Are you sure to continue? (y/n)[n]:y
  It will take several minutes to save configuration file, please wait.......
  Configuration file had been saved successfully
  Note: The configuration file will take effect after being activated
<AR5>

6、配置完成后,查看下配置邻居关系是否正确:

编辑

7、通信测试 pc2 ping pc1 通的

编辑

8、查看路由表信息

去往3.3.3.3  10.1.20.0 网段

编辑

P2-PC1 路径:

PC2-AR3-AR5-AR1-PC1

PC2-AR3-AR2-AR1-PC1

因为开销值cost是相同的,实现了负载分担的功能。通过修改cost值,改变流量走向。开销值越小,路径越优先。

例:[AR1-GigabitEthernet0/0/0]ospf cost 100  

编辑

编辑