配置OSPF基本功能示例
介绍OSPF基本功能的配置过程,包括在各设备上使能OSPF、指定不同区域内的网段。
组网需求
如图5-7所示,所有的路由器都运行OSPF,并将整个自治系统划分为3个区域,其中DeviceA和DeviceB作为ABR来转发区域之间的路由。
配置完成后,每台路由器都应学到自治系统内的到所有网段的路由。
配置注意事项
在配置过程中,需注意以下事项:
骨干区域负责区域之间的路由,非骨干区域之间的路由信息必须通过骨干区域来转发。对此,OSPF有两个规定:
- 所有非骨干区域必须与骨干区域保持连通;
- 骨干区域自身也必须保持连通。
- 本路由器接口发送Hello、Dead和Poll报文的时间间隔要和邻接路由器的参数保持一致,否则双方不能建立邻居。
数据准备
为完成此配置例,需准备如下的数据:
设备 |
Router ID |
Process ID |
IP地址 |
DeviceA |
1.1.1.1 |
1 |
区域0:192.168.0.0/24 区域1:192.168.1.0/24 |
DeviceB |
2.2.2.2 |
1 |
区域0:192.168.0.0/24 区域2:192.168.2.0/24 |
DeviceC |
3.3.3.3 |
1 |
区域1:192.168.1.0/24、172.16.1.0/24 |
DeviceD |
4.4.4.4 |
1 |
区域2:192.168.2.0/24、172.17.1.0/24 |
DeviceE |
5.5.5.5 |
1 |
区域1:172.16.1.0/24 |
DeviceF |
6.6.6.6 |
1 |
区域2:172.17.1.0/24 |
操作步骤
- 配置各接口的IP地址(略)
- 配置OSPF基本功能
# 配置DeviceA。
[~DeviceA] router id 1.1.1.1
[~DeviceA] ospf 1
[*DeviceA-ospf-1] area 0
[*DeviceA-ospf-1-area-0.0.0.0] network 192.168.0.0 0.0.0.255
[*DeviceA-ospf-1-area-0.0.0.0] quit
[*DeviceA-ospf-1] area 1
[*DeviceA-ospf-1-area-0.0.0.1] network 192.168.1.0 0.0.0.255
[*DeviceA-ospf-1-area-0.0.0.1] quit
[*DeviceA-ospf-1] commit
# 配置DeviceB。
[~DeviceB] router id 2.2.2.2
[~DeviceB] ospf 1
[*DeviceB-ospf-1] area 0
[*DeviceB-ospf-1-area-0.0.0.0] network 192.168.0.0 0.0.0.255
[*DeviceB-ospf-1-area-0.0.0.0] quit
[*DeviceB-ospf-1] area 2
[*DeviceB-ospf-1-area-0.0.0.2] network 192.168.2.0 0.0.0.255
[*DeviceB-ospf-1-area-0.0.0.2] quit
[*DeviceB-ospf-1] commit
# 配置DeviceC。
[~DeviceC] router id 3.3.3.3
[~DeviceC] ospf 1
[*DeviceC-ospf-1] area 1
[*DeviceC-ospf-1-area-0.0.0.1] network 192.168.1.0 0.0.0.255
[*DeviceC-ospf-1-area-0.0.0.1] network 172.16.1.0 0.0.0.255
[*DeviceC-ospf-1-area-0.0.0.1] commit
[~DeviceC-ospf-1-area-0.0.0.1] quit
# 配置DeviceD。
[~DeviceD] router id 4.4.4.4
[~DeviceD] ospf 1
[*DeviceD-ospf-1] area 2
[*DeviceD-ospf-1-area-0.0.0.2] network 192.168.2.0 0.0.0.255
[*DeviceD-ospf-1-area-0.0.0.2] network 172.17.1.0 0.0.0.255
[*DeviceD-ospf-1-area-0.0.0.2] commit
[~DeviceD-ospf-1-area-0.0.0.2] quit
# 配置DeviceE。
[~DeviceE] router id 5.5.5.5
[~DeviceE] ospf 1
[*DeviceE-ospf-1] area 1
[*DeviceE-ospf-1-area-0.0.0.1] network 172.16.1.0 0.0.0.255
[*DeviceE-ospf-1-area-0.0.0.1] commit
[~DeviceE-ospf-1-area-0.0.0.1] quit
# 配置DeviceF。
[~DeviceF] router id 6.6.6.6
[~DeviceF] ospf 1
[*DeviceF-ospf-1] area 2
[*DeviceF-ospf-1-area-0.0.0.2] network 172.17.1.0 0.0.0.255
[*DeviceF-ospf-1-area-0.0.0.2] commit
[~DeviceF-ospf-1-area-0.0.0.2] quit
- 验证配置结果
# 查看DeviceA的OSPF邻居。
[~DeviceA] display ospf peer
OSPF Process 1 with Router ID 1.1.1.1 Neighbors Area 0.0.0.0 interface 192.168.0.1(GigabitEthernet0/1/0)'s neighbors Router ID: 2.2.2.2 Address: 192.168.0.2 State: Full Mode:Nbr is Master Priority: 1 DR: 192.168.1.2 BDR: 192.168.1.1 MTU: 0 Dead timer due in 36 sec Retrans timer interval: 5 Neighbor is up for 00:15:04 Authentication Sequence: [ 0 ] Area 0.0.0.1 interface 192.168.1.1(GigabitEthernet0/2/0)'s neighbors Router ID: 3.3.3.3 Address: 192.168.1.2 State: Full Mode:Nbr is Master Priority: 1 DR: 192.168.1.2 BDR: 192.168.1.1 MTU: 0 Dead timer due in 39 sec Retrans timer interval: 5 Neighbor is up for 00:07:32 Authentication Sequence: [ 0 ]
# 显示DeviceA的OSPF路由信息。
[~DeviceA] display ospf routing
OSPF Process 1 with Router ID 1.1.1.1 Routing Tables Routing for Network Destination Cost Type NextHop AdvRouter Area 172.16.1.0/24 2 Transit 192.168.1.2 3.3.3.3 0.0.0.1 172.17.1.0/24 3 Inter-area 192.168.0.2 2.2.2.2 0.0.0.0 192.168.2.0/24 2 Inter-area 192.168.0.2 2.2.2.2 0.0.0.0 Total Nets: 3 Intra Area: 1 Inter Area: 2 ASE: 0 NSSA: 0
# 显示DeviceA的LSDB。
[~DeviceA] display ospf lsdb
OSPF Process 1 with Router ID 1.1.1.1 Link State Database Area: 0.0.0.0 Type LinkState ID AdvRouter Age Len Sequence Metric Router 1.1.1.1 1.1.1.1 93 48 80000004 1 Router 2.2.2.2 2.2.2.2 92 48 80000004 1 Sum-Net 172.16.1.0 1.1.1.1 1287 28 80000002 2 Sum-Net 192.168.1.0 1.1.1.1 1716 28 80000001 1 Sum-Net 172.17.1.0 2.2.2.2 1336 28 80000001 2 Sum-Net 192.168.2.0 2.2.2.2 87 28 80000002 1 Area: 0.0.0.1 Type LinkState ID AdvRouter Age Len Sequence Metric Router 1.1.1.1 1.1.1.1 1420 48 80000002 1 Router 3.3.3.3 3.3.3.3 1294 60 80000003 1 Router 5.5.5.5 5.5.5.5 1296 36 80000002 1 Network 172.16.1.1 3.3.3.3 1294 32 80000001 0 Sum-Net 172.17.1.0 1.1.1.1 1325 28 80000001 3 Sum-Net 192.168.0.0 1.1.1.1 1717 28 80000001 1 Sum-Net 192.168.2.0 1.1.1.1 1717 28 80000001 2
# 查看DeviceD的路由表,并使用Ping进行测试连通性。
[~DeviceD] display ospf routing
OSPF Process 1 with Router ID 4.4.4.4 Routing Tables Routing for Network Destination Cost Type NextHop AdvRouter Area 172.16.1.0/24 4 Inter-area 192.168.2.1 2.2.2.2 0.0.0.2 192.168.0.0/24 2 Inter-area 192.168.2.1 2.2.2.2 0.0.0.2 192.168.1.0/24 3 Inter-area 192.168.2.1 2.2.2.2 0.0.0.2 Total Nets: 3 Intra Area: 0 Inter Area: 3 ASE: 0 NSSA: 0
[~DeviceD] 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
配置文件
DeviceA的配置文件
#
sysname DeviceA
#
router id 1.1.1.1
#
interface GigabitEthernet0/1/0
undo shutdown
ip address 192.168.0.1 255.255.255.0
#
interface GigabitEthernet0/2/0
undo shutdown
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
#
return
DeviceB的配置文件
#
sysname DeviceB
#
router id 2.2.2.2
#
interface GigabitEthernet0/1/0
undo shutdown
ip address 192.168.0.2 255.255.255.0
#
interface GigabitEthernet0/2/0
undo shutdown
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
#
return
DeviceC的配置文件
#
sysname DeviceC
#
router id 3.3.3.3
#
interface GigabitEthernet0/1/0
undo shutdown
ip address 192.168.1.2 255.255.255.0
#
interface GigabitEthernet0/2/0
undo shutdown
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
#
return
DeviceD的配置文件
#
sysname DeviceD
#
router id 4.4.4.4
#
interface GigabitEthernet0/1/0
undo shutdown
ip address 192.168.2.2 255.255.255.0
#
interface GigabitEthernet0/2/0
undo shutdown
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
#
return
DeviceE的配置文件
#
sysname DeviceE
#
router id 5.5.5.5
#
interface GigabitEthernet0/2/0
undo shutdown
ip address 172.16.1.2 255.255.255.0
#
ospf 1
area 0.0.0.1
network 172.16.1.0 0.0.0.255
#
return
DeviceF的配置文件
#
sysname DeviceF
#
router id 6.6.6.6
#
interface GigabitEthernet0/2/0
undo shutdown
ip address 172.17.1.2 255.255.255.0
#
ospf 1
area 0.0.0.2
network 172.17.1.0 0.0.0.255
#
return