23-OSPF典型配置举例
本章节下载: 23-OSPF典型配置举例 (173 KB)
目 录
本章介绍了OSPF路由协议的各种典型配置。
表1 配置适用的产品与软件版本关系
产品 |
软件版本 |
S5830V2&S5820V2系列以太网交换机 |
Release 2208P01,Release 2210 |
如图1所示网络,通过配置OSPF基本功能实现网络内所有设备的路由互通,每台设备都能学习到网络中所有网段的路由。配置时将网络划分为3个OSPF区域,Area 1、Area 2均与骨干区域Area 0保持连接。
图1 OSPF基本配置组网图
Router ID用来在一个自治系统中唯一的标识一台路由器,Router ID需要保证在同一个自治系统中不重复。
(1) 配置各接口的IP地址(略)
(2) 配置OSPF基本功能
# 配置Switch A。
<SwitchA> system-view
[SwitchA] ospf 1 router-id 192.168.1.1
[SwitchA-ospf-1] area 0
[SwitchA-ospf-1-area-0.0.0.0] network 192.168.0.0 0.0.0.255
[SwitchA-ospf-1-area-0.0.0.0] quit
[SwitchA-ospf-1] area 1
[SwitchA-ospf-1-area-0.0.0.1] network 192.168.1.0 0.0.0.255
[SwitchA-ospf-1-area-0.0.0.1] quit
[SwitchA-ospf-1] quit
# 配置Switch B。
<SwitchB> system-view
[SwitchA] ospf 1 router-id 192.168.2.1
[SwitchB-ospf-1] area 0
[SwitchB-ospf-1-area-0.0.0.0] network 192.168.0.0 0.0.0.255
[SwitchB-ospf-1-area-0.0.0.0] quit
[SwitchB-ospf-1] area 2
[SwitchB-ospf-1-area-0.0.0.2] network 192.168.2.0 0.0.0.255
[SwitchB-ospf-1-area-0.0.0.2] quit
[SwitchB-ospf-1] quit
# 配置Switch C。
<SwitchC> system-view
[SwitchA] ospf 1 router-id 192.168.1.2
[SwitchC-ospf-1] area 1
[SwitchC-ospf-1-area-0.0.0.1] network 192.168.1.0 0.0.0.255
[SwitchC-ospf-1-area-0.0.0.1] network 172.16.1.0 0.0.0.255
[SwitchC-ospf-1-area-0.0.0.1] quit
[SwitchC-ospf-1] quit
# 配置Switch D。
<SwitchD> system-view
[SwitchA] ospf 1 router-id 192.168.2.2
[SwitchD-ospf-1] area 2
[SwitchD-ospf-1-area-0.0.0.2] network 192.168.2.0 0.0.0.255
[SwitchD-ospf-1-area-0.0.0.2] network 172.17.1.0 0.0.0.255
[SwitchD-ospf-1-area-0.0.0.2] quit
[SwitchD-ospf-1] quit
# 查看Switch A的OSPF邻居,可以看到Switch A和Switch B、Switch C都形成了OSPF邻居。
[SwitchA] display ospf peer verbose
OSPF Process 1 with Router ID 192.168.1.1
Neighbors
Area 0.0.0.0 interface 192.168.0.1(Vlan-interface 100)'s neighbors
Router ID: 192.168.2.1 Address: 192.168.0.2 GR State: Normal
State: Full Mode:Nbr is Master Priority: 1
DR: 192.168.0.2 BDR: 192.168.0.1 MTU: 0
Dead timer due in 36 sec
Neighbor is up for 00:15:04
Authentication Sequence: [ 0 ]
Neighbor state change count: 3
Neighbors
Area 0.0.0.1 interface 192.168.1.1(Vlan-interface 200)'s neighbors
Router ID: 192.168.1.2 Address: 192.168.1.2 GR State: Normal
State: Full Mode:Nbr is Slave Priority: 1
DR: 192.168.1.2 BDR: 192.168.1.1 MTU: 0
Dead timer due in 39 sec
Neighbor is up for 00:07:32
Authentication Sequence: [ 0 ]
Neighbor state change count: 2
# 显示Switch A的OSPF路由信息,可以看到网络中所有网段的路由信息。
[SwitchA] display ospf routing
OSPF Process 1 with Router ID 192.168.1.1
Routing Tables
Routing for Network
Destination Cost Type NextHop AdvRouter Area
172.16.1.0/24 1563 Stub 192.168.1.2 172.16.1.1 0.0.0.1
172.17.1.0/24 3125 Inter 192.168.0.2 192.168.2.1 0.0.0.0
192.168.1.0/24 1562 Transit 192.168.1.1 192.168.0.1 0.0.0.1
192.168.2.0/24 3124 Inter 192.168.0.2 192.168.2.1 0.0.0.0
192.168.0.0/24 1562 Transit 192.168.0.1 192.168.0.1 0.0.0.0
Total Nets: 5
Intra Area: 3 Inter Area: 2 ASE: 0 NSSA: 0
# 查看Switch D的路由表,同样可以看到网络中所有网段的路由信息。
[SwitchD] display ospf routing
OSPF Process 1 with Router ID 192.168.2.2
Routing Tables
Routing for Network
Destination Cost Type NextHop AdvRouter Area
172.16.1.0/24 4687 Inter 192.168.2.1 192.168.2.1 0.0.0.2
172.17.1.0/24 1 Stub 172.17.1.1 192.168.2.2 0.0.0.2
192.168.1.0/24 4686 Inter 192.168.2.1 192.168.2.1 0.0.0.2
192.168.2.0/24 1562 Transit 192.168.2.2 192.168.2.2 0.0.0.2
192.168.0.0/24 3124 Inter 192.168.2.1 192.168.2.1 0.0.0.2
Total Nets: 5
Intra Area: 2 Inter Area: 3 ASE: 0 NSSA: 0
# 在Switch D上使用Ping进行测试连通性,可以成功ping通Switch C。
[SwitchD] ping 172.16.1.1
PING 172.16.1.1: 56 data bytes, press CTRL_C to break
Reply from 172.16.1.1: bytes=56 Sequence=1 ttl=253 time=62 ms
Reply from 172.16.1.1: bytes=56 Sequence=2 ttl=253 time=16 ms
Reply from 172.16.1.1: bytes=56 Sequence=3 ttl=253 time=62 ms
Reply from 172.16.1.1: bytes=56 Sequence=4 ttl=253 time=94 ms
Reply from 172.16.1.1: bytes=56 Sequence=5 ttl=253 time=63 ms
--- 172.16.1.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 16/59/94 ms
· Switch A
#
router id 192.168.1.1
#
vlan 100
#
vlan 200
#
interface Vlan-interface100
ip address 192.168.0.1 255.255.255.0
#
interface Vlan-interface200
ip address 192.168.1.1 255.255.255.0
#
ospf 1
area 0.0.0.0
network 192.168.0.0 0.0.0.255
area 0.0.0.1
network 192.168.1.0 0.0.0.255
#
· Switch B
#
router id 192.168.2.1
#
vlan 100
#
vlan 200
#
interface Vlan-interface100
ip address 192.168.0.2 255.255.255.0
#
interface Vlan-interface200
ip address 192.168.2.1 255.255.255.0
#
ospf 1
area 0.0.0.0
network 192.168.0.0 0.0.0.255
area 0.0.0.2
network 192.168.2.0 0.0.0.255
#
· Switch C
#
router id 192.168.1.2
#
vlan 200
#
vlan 300
#
interface Vlan-interface200
ip address 192.168.1.2 255.255.255.0
#
interface Vlan-interface300
ip address 172.16.1.1 255.255.255.0
#
ospf 1
area 0.0.0.1
network 192.168.1.0 0.0.0.255
network 172.16.1.0 0.0.0.255
#
· Switch D
#
router id 192.168.2.2
#
vlan 200
#
vlan 300
#
interface Vlan-interface200
ip address 192.168.2.2 255.255.255.0
#
interface Vlan-interface300
ip address 172.17.1.1 255.255.255.0
#
ospf 1
area 0.0.0.2
network 192.168.2.0 0.0.0.255
network 172.17.1.0 0.0.0.255
#
表2 配置适用的产品与软件版本关系
产品 |
软件版本 |
S5830V2&S5820V2系列以太网交换机 |
Release 2208P01,Release 2210 |
如图2所示网络,通过配置IETF标准方式GR(Graceful Restart,平滑重启)功能实现Switch B在主备倒换或者协议重启过程中不会产生路由振荡,报文转发路径也没有任何改变,整个系统可以不间断地转发数据。
图2 OSPF GR配置组网图
(1) 配置各接口的IP地址(略)
(2) 配置OSPF基本功能
# 配置Switch A。
<SwitchA> system-view
[SwitchA] ospf 1
[SwitchA-ospf-1] area 0
[SwitchA-ospf-1-area-0.0.0.0] network 10.1.1.0 0.0.0.255
[SwitchA-ospf-1-area-0.0.0.0] return
# 配置Switch B。
<SwitchB> system-view
[SwitchB] ospf 1
[SwitchB-ospf-1] area 0
[SwitchB-ospf-1-area-0.0.0.0] network 10.1.1.0 0.0.0.255
[SwitchB-ospf-1-area-0.0.0.0] network 10.2.1.0 0.0.0.255
[SwitchB-ospf-1-area-0.0.0.0] network 10.3.1.0 0.0.0.255
[SwitchB-ospf-1-area-0.0.0.0] return
# 配置Switch C,启动OSPF。
<SwitchC> system-view
[SwitchC] ospf 1
[SwitchC-ospf-1] area 0
[SwitchC-ospf-1-area-0.0.0.0] network 10.2.1.0 0.0.0.255
[SwitchC-ospf-1-area-0.0.0.0] return
# 配置Switch D,启动OSPF。
<SwitchD> system-view
[SwitchD] ospf 1
[SwitchD-ospf-1] area 0
[SwitchD-ospf-1-area-0.0.0.0] network 10.3.1.0 0.0.0.255
[SwitchD-ospf-1-area-0.0.0.0] return
(3) 配置交换机启用IETF标准方式的GR能力。
# 配置Switch B作为GR Restarter。
<SwitchB> system-view
[SwitchB] ospf 1
[SwitchB-ospf-1] graceful-restart ietf
运行稳定后,在Switch B上以GR方式重启OSPF进程。可以看到在GR过程中,所有交换机的路由表保持不变,网络保持畅通,此时可以通过ping命令验证GR过程中的网络连通性。
· Switch A
#
vlan 100
#
interface Vlan-interface100
ip address 10.1.1.2 255.255.255.0
#
ospf 1
area 0.0.0.0
network 10.1.1.0 0.0.0.255
#
· Switch B
#
vlan 100
#
vlan 200
#
vlan 300
#
interface Vlan-interface100
ip address 10.1.1.2 255.255.255.0
#
interface Vlan-interface200
ip address 10.2.1.2 255.255.255.0
#
interface Vlan-interface300
ip address 10.3.1.2 255.255.255.0
#
ospf 1
graceful-restart ietf
area 0.0.0.0
network 10.1.1.0 0.0.0.255
network 10.2.1.0 0.0.0.255
network 10.3.1.0 0.0.0.255
#
· Switch C
vlan 100
#
interface Vlan-interface100
ip address 10.2.1.2 255.255.255.0
#
ospf 1
area 0.0.0.0
network 10.2.1.0 0.0.0.255
#
· Switch D
#
vlan 300
#
interface Vlan-interface300
ip address 10.3.1.2 255.255.255.0
#
ospf 1
area 0.0.0.0
network 10.3.1.0 0.0.0.255
#
表3 配置适用的产品与软件版本关系
产品 |
软件版本 |
S5830V2&S5820V2系列以太网交换机 |
Release 2208P01,Release 2210 |
如图3所示网络,Switch A、 B、C上均运行OSPF,网络层相互可达。通过在Switch A和Switch B上配置OSPF BFD功能,监测通过L2 Switch通信的链路;当链路出现故障时设备能够快速感知并通告OSPF协议,快速切换到Switch C链路进行通信。
图3 OSPF与BFD联动配置组网图
设备 |
接口 |
IP地址 |
设备 |
接口 |
IP地址 |
Switch A |
Vlan-int10 |
10.1.0.102/24 |
Switch B |
Vlan-int10 |
10.1.0.100/24 |
|
Vlan-int11 |
11.1.1.1/24 |
|
Vlan-int13 |
13.1.1.1/24 |
Switch C |
Vlan-int11 |
11.1.1.2/24 |
|
|
|
|
Vlan-int13 |
13.1.1.2/24 |
|
|
|
· BFD control报文双向检测,需要建立OSPF邻居的两端设备均进行BFD配置。
· 创建BFD会话的通信双方必须处于同一个OSPF区域的同一网段。
(1) 配置各接口的IP地址(略)
(2) 配置OSPF基本功能
# 配置Switch A。
<SwitchA> system-view
[SwitchA] ospf
[SwitchA-ospf-1] area 0
[SwitchA-ospf-1-area-0.0.0.0] network 10.1.0.0 0.0.0.255
[SwitchA-ospf-1-area-0.0.0.0] network 11.1.1.0 0.0.0.255
[SwitchA-ospf-1-area-0.0.0.0] network 121.1.1.0 0.0.0.255
[SwitchA-ospf-1-area-0.0.0.0] quit
[SwitchA-ospf-1] quit
[SwitchA] interface vlan 11
[SwitchA-Vlan-interface11] ospf cost 2
[SwitchA-Vlan-interface11] quit
# 配置Switch B。
<SwitchB> system-view
[SwitchB] ospf
[SwitchB-ospf-1] area 0
[SwitchB-ospf-1-area-0.0.0.0] network 10.1.0.0 0.0.0.255
[SwitchB-ospf-1-area-0.0.0.0] network 13.1.1.0 0.0.0.255
[SwitchB-ospf-1-area-0.0.0.0] network 120.1.1.0 0.0.0.255
[SwitchB-ospf-1-area-0.0.0.0] quit
[SwitchB-ospf-1] quit
[SwitchB] interface vlan-interface 13
[SwitchB-Vlan-interface13] ospf cost 2
[SwitchA-Vlan-interface13] quit
# 配置Switch C。
<SwitchC> system-view
[SwitchC] ospf
[SwitchC-ospf-1] area 0
[SwitchC-ospf-1-area-0.0.0.0] network 11.1.1.0 0.0.0.255
[SwitchC-ospf-1-area-0.0.0.0] network 13.1.1.0 0.0.0.255
[SwitchC-ospf-1-area-0.0.0.0] quit
[SwitchC-ospf-1] quit
(3) 配置BFD功能
# 在Switch A与L2 Switch相连的接口上开启BFD检测功能。
[SwitchA] bfd session init-mode active
[SwitchA] interface vlan-interface 10
[SwitchA-Vlan-interface10] ospf bfd enable
[SwitchA-Vlan-interface10] quit
[SwitchA] quit
# 在Switch B与L2 Switch相连的接口上开启BFD检测功能。
[SwitchB] bfd session init-mode active
[SwitchB] interface vlan-interface 10
[SwitchB-Vlan-interface10] ospf bfd enable
下面以Switch A为例,Switch B和Switch A类似,不再赘述。
# 显示Switch A的BFD信息。
<SwitchA> display bfd session
Total Session Num: 1 Init Mode: Active
Session Working Under Ctrl Mode:
LD/RD SourceAddr DestAddr State Holdtime Interface
3/1 10.1.0.102 10.1.0.100 Up 1700ms vlan10
# 在Switch A上查看120.1.1.0/24的路由信息,可以看出Switch A和Switch B是通过L2 Switch进行通信的。
<SwitchA> display ip routing-table 120.1.1.0 verbose
Routing Table : Public
Summary Count : 1
Destination: 120.1.1.0/24
Protocol: OSPF Process ID: 0
Preference: 0 Cost: 2
IpPrecedence: QosLcId:
NextHop: 10.1.0.100 Interface: Vlan-interface10
BkNextHop: 0.0.0.0 BkInterface:
RelyNextHop: 0.0.0.0 Neighbor : 0.0.0.0
Tunnel ID: 0x0 Label: NULL
BKTunnel ID: 0x0 BKLabel: NULL
State: Active Adv Age: 00h58m10s
Tag: 0
关闭L2 Switch与Switch A连接的端口,再次查看Switch A的BFD信息,此时Switch A和Switch B的BFD会话已经被删除,没有任何输出信息。
<SwitchA> display bfd session
# 在Switch A上查看120.1.1.0/24的路由信息,可以看出Switch A和Switch B已经切换到Switch C进行通信。
<SwitchA> display ip routing-table 120.1.1.0 verbose
Routing Table : Public
Summary Count : 1
Destination: 120.1.1.0/24
Protocol: OSPF Process ID: 1
Preference: 10 Cost: 4
IpPrecedence: QosLcId:
NextHop: 11.1.1.2 Interface: Vlan-interface11
BkNextHop: 0.0.0.0 BkInterface:
RelyNextHop: 0.0.0.0 Neighbor : 0.0.0.0
Tunnel ID: 0x0 Label: NULL
BKTunnel ID: 0x0 BKLabel: NULL
State: Active Adv Age: 00h58m10s
Tag: 0
· Switch A
#
vlan 10
#
interface Vlan-interface10
ip address 10.1.0.102 255.255.255.0
ospf bfd enable
#
vlan 11
#
interface Vlan-interface11
ip address 11.1.1.1 255.255.255.0
#
vlan 12
#
interface Vlan-interface12
ip address 121.1.1.1 255.255.255.0
#
ospf 1
area 0.0.0.0
network 10.1.0.0 0.0.0.255
network 11.1.1.0 0.0.0.255
network 121.1.1.0 0.0.0.255
#
· Switch B
#
vlan 10
#
interface Vlan-interface10
ip address 10.1.0.100 255.255.255.0
ospf bfd enable
#
vlan 12
#
interface Vlan-interface12
ip address 120.1.1.1 255.255.255.0
#
vlan 13
#
interface Vlan-interface13
ip address 13.1.1.1 255.255.255.0
#
ospf 1
area 0.0.0.0
network 10.1.0.0 0.0.0.255
network 13.1.1.0 0.0.0.255
network 120.1.1.0 0.0.0.255
#
· Switch C
#
vlan 11
#
interface Vlan-interface11
ip address 11.1.1.2 255.255.255.0
#
vlan 13
#
interface Vlan-interface13
ip address 13.1.1.2 255.255.255.0
#
ospf 1
area 0.0.0.0
network 11.1.1.0 0.0.0.255
network 13.1.1.0 0.0.0.255
#
不同款型规格的资料略有差异, 详细信息请向具体销售和400咨询。H3C保留在没有任何通知或提示的情况下对资料内容进行修改的权利!