学习目标
– 掌握OSPF中Router ID的配置方法
– 掌握OSPF的配置方法
– 掌握通过display命令查看OSPF运行状态的方法
– 掌握使用OSPF发布缺省路由的方法
– 掌握修改OSPF hello和dead时间的配置方法
– 理解多路访问网络中的DR或BDR选举
– 掌握OSPF路由优先级的修改方法
拓扑图
图2.2 OSPF单域配置实验拓扑图
场景
您是公司的网络管理员。现在公司网络中需要使用OSPF协议来进行路由信息的传递。规划网络中所有路由器属于OSPF的区域0。实际使用中需要向OSPF发布默认路由,此外您也希望通过这次部署了解DR/BDR选举的机制。
操作步骤
步骤一 实验环境准备
关于Router ID的要求,分别在R1,R2,R3上配置loopback0环回口地址作为Router ID,其中R1的地址为10.1.0.1/32,R2的地址为10.1.0.2/32,R3的地址为10.1.0.3/32。
基本配置以及IP编址。
- 配置R1
sysname R1
interface GigabitEthernet0/0/0
ip address 10.1.1.254 255.255.255.0
interface GigabitEthernet0/0/1
ip address 10.1.12.1 255.255.255.0
interface GigabitEthernet0/0/2
ip address 10.1.13.1 255.255.255.0
interface LoopBack0
ip address 10.1.0.1 255.255.255.255
- 配置R2
sysname R2
interface GigabitEthernet0/0/0
ip address 172.16.1.254 255.255.255.0
interface GigabitEthernet0/0/1
ip address 10.1.12.2 255.255.255.0
interface GigabitEthernet0/0/2
ip address 10.1.23.2 255.255.255.0
interface LoopBack0
ip address 10.1.0.2 255.255.255.255
- 配置R3
sysname R2
interface GigabitEthernet0/0/0
ip address 192.168.1.254 255.255.255.0
interface GigabitEthernet0/0/1
ip address 10.1.13.3 255.255.255.0
interface GigabitEthernet0/0/2
ip address 10.1.23.3 255.255.255.0
interface LoopBack0
ip address 10.1.0.3 255.255.255.255
基本配置完成后,确保每台设备用到的接口都是UP的状态,并且直连网络能通。
测试命令:
display ip interface brief
ping ….
R1上ping 10.1.1.1、10.1.12.2、10.1.13.3
R2上ping 10.1.23.3、172.16.1.2
R3上ping 192.168.1.3
步骤二 配置OSPF
将R1的Router ID配置为10.1.0.1,开启OSPF进程1,并将网段10.1.0.1/32、10.1.1.0/24、10.1.12.0/24和10.1.13.0/24发布到OSPF区域0。
[R1]ospf 1 router-id 10.1.0.1
[R1-ospf-1]area 0
[R1-ospf-1-area-0.0.0.0]network 10.1.0.1 0.0.0.0
[R1-ospf-1-area-0.0.0.0]network 10.1.1.0 0.0.0.255
[R1-ospf-1-area-0.0.0.0]network 10.1.12.0 0.0.0.255
[R1-ospf-1-area-0.0.0.0]network 10.1.13.0 0.0.0.255
注意:同一个路由器可以开启多个OSPF进程,默认进程号为1,由于进程号只具有本地意义,所以同一路由域的不同路由器可以使用相同或不同的OSPF进程号。另外network命令后面需使用反掩码。
将R2的Router ID配置为10.1.0.2,开启OSPF进程1,并将网段10.1.0.2/32、10.1.12.0/24、10.1.23.0/24和172.16.1.0/24发布到OSPF区域0。
[R2]ospf 1 router-id 10.1.0.2
[R2-ospf-1]area 0
[R2-ospf-1-area-0.0.0.0]network 10.1.0.2 0.0.0.0
[R2-ospf-1-area-0.0.0.0]network 10.0.12.0 0.0.0.255
[R2-ospf-1-area-0.0.0.0]network 10.0.23.0 0.0.0.255
[R2-ospf-1-area-0.0.0.0]network 172.16.1.0 0.0.0.255
output omit
Mar 30 2016 09:41:39+00:00 R2 %%01OSPF/4/NBR_CHANGE_E(l)[5]:Neighbor changes event: neighbor status changed. (ProcessId=1, NeighborAddress=10.1.12.1, NeighborEvent=LoadingDone, NeighborPreviousState=Loading, NeighborCurrentState=Full)
当回显信息中包含“NeighborCurrentState=Full”信息时,表明邻接关系已经建立。
将R3的Router ID配置为10.1.0.3,开启OSPF进程1,并将网段10.1.0.3/32、10.1.13.0/24、10.1.23.0/24和192.168.1.0/24发布到OSPF区域0。
[R3]ospf 1 router-id 10.1.0.3
[R3-ospf-1]area 0
[R3-ospf-1-area-0.0.0.0]network 10.1.0.3 0.0.0.0
[R3-ospf-1-area-0.0.0.0]network 10.1.13.0 0.0.0.255
[R3-ospf-1-area-0.0.0.0]network 10.1.23.0 0.0.0.255
[R3-ospf-1-area-0.0.0.0]network 192.168.1.0 0.0.0.255
这步配置完成后,正常会有以下回显信息。
…output omit…
Mar 30 2016 16:05:34+00:00 R3 %%01OSPF/4/NBR_CHANGE_E(l)[5]:Neighbor changes event: neighbor status changed. (ProcessId=1, NeighborAddress=10.1.13.1, NeighborEvent=LoadingDone, NeighborPreviousState=Loading, NeighborCurrentState=Full)
步骤三 验证OSPF配置
待OSPF收敛完成后,查看R1、R2和R3上的路由表。
[R1]display ip routing-table
Route Flags: R - relay D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 19 Routes : 20
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.1.0.1/32 Direct 0 0 D 127.0.0.1 LoopBack0
10.1.0.2/32 OSPF 10 1 D 10.1.12.2 GigabitEthernet0/0/1
10.1.0.3/32 OSPF 10 1 D 10.1.13.3 GigabitEthernet0/0/2
10.1.23.0/24 OSPF 10 2 D 10.1.12.2 GigabitEthernet0/0/1
OSPF 10 2 D 10.1.13.3 GigabitEthernet0/0/2
172.16.1.0/24 OSPF 10 2 D 10.1.12.2 GigabitEthernet0/0/1
192.168.1.0/24 OSPF 10 2 D 10.1.13.3 GigabitEthernet0/0/2
[R2]display ip routing-table
Route Flags: R - relay D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 19 Routes : 20
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.1.0.1/32 OSPF 10 1 D 10.1.12.1 GigabitEthernet0/0/1
10.1.0.3/32 OSPF 10 1 D 10.1.23.3 GigabitEthernet0/0/2
10.1.1.0/24 OSPF 10 2 D 10.1.12.1 GigabitEthernet0/0/1
10.1.13.0/24 OSPF 10 2 D 10.1.12.1 GigabitEthernet0/0/1
OSPF 10 2 D 10.1.23.3 GigabitEthernet0/0/2
192.168.1.0/24 OSPF 10 2 D 10.1.23.3 GigabitEthernet0/0/2
<R3>display ip routing-table
[R3]display ip routing-table
Route Flags: R - relay D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 19 Routes : 20
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.1.0.1/32 OSPF 10 1 D 10.1.13.1 GigabitEthernet0/0/1
10.1.0.2/32 OSPF 10 1 D 10.1.23.2 GigabitEthernet0/0/2
10.1.1.0/24 OSPF 10 2 D 10.1.13.1 GigabitEthernet0/0/1
10.1.12.0/24 OSPF 10 2 D 10.1.13.1 GigabitEthernet0/0/1
OSPF 10 2 D 10.1.23.2 GigabitEthernet0/0/2
172.16.1.0/24 OSPF 10 2 D 10.1.23.2 GigabitEthernet0/0/2
检测PC1、PC2和PC3之间的连通性。
在PC1 ping PC2测试
PC1>ping 172.16.1.2
Ping 172.16.1.2: 32 data bytes, Press Ctrl_C to break
From 172.16.1.2: bytes=32 seq=1 ttl=126 time=31 ms
From 172.16.1.2: bytes=32 seq=2 ttl=126 time=15 ms
From 172.16.1.2: bytes=32 seq=3 ttl=126 time=15 ms
From 172.16.1.2: bytes=32 seq=4 ttl=126 time=16 ms
From 172.16.1.2: bytes=32 seq=5 ttl=126 time=31 ms
在PC1 ping PC3测试
PC1>ping 192.168.1.3
Ping 192.168.1.3: 32 data bytes, Press Ctrl_C to break
From 192.168.1.3: bytes=32 seq=1 ttl=126 time=31 ms
From 192.168.1.3: bytes=32 seq=2 ttl=126 time=16 ms
From 192.168.1.3: bytes=32 seq=3 ttl=126 time=16 ms
From 192.168.1.3: bytes=32 seq=4 ttl=126 time=31 ms
From 192.168.1.3: bytes=32 seq=5 ttl=126 time=15 ms
在PC2 ping PC3测试
PC2>ping 192.168.1.3
Ping 192.168.1.3: 32 data bytes, Press Ctrl_C to break
From 192.168.1.3: bytes=32 seq=1 ttl=126 time=15 ms
From 192.168.1.3: bytes=32 seq=2 ttl=126 time=15 ms
From 192.168.1.3: bytes=32 seq=3 ttl=126 time=15 ms
From 192.168.1.3: bytes=32 seq=4 ttl=126 time=15 ms
From 192.168.1.3: bytes=32 seq=5 ttl=126 time=15 ms
执行display ospf peer命令,查看OSPF邻居详细状态
[R1]disp ospf peer
OSPF Process 1 with Router ID 10.1.0.1
Neighbors
Area 0.0.0.0 interface 10.1.12.1(GigabitEthernet0/0/1)'s neighbors
Router ID: 10.1.0.2 Address: 10.1.12.2
State: Full Mode:Nbr is Master Priority: 1
DR: 10.1.12.1 BDR: 10.1.12.2 MTU: 0
Dead timer due in 38 sec
Retrans timer interval: 5
Neighbor is up for 00:26:16
Authentication Sequence: [ 0 ]
Neighbors
Area 0.0.0.0 interface 10.1.13.1(GigabitEthernet0/0/2)'s neighbors
Router ID: 10.1.0.3 Address: 10.1.13.3
State: Full Mode:Nbr is Master Priority: 1
DR: 10.1.13.1 BDR: 10.1.13.3 MTU: 0
Dead timer due in 36 sec
Retrans timer interval: 5
Neighbor is up for 00:21:21
Authentication Sequence: [ 0 ]
display ospf peer 命令显示所有OSPF邻居的详细信息。本任务中,在10.1.12.0网段上R1是DR。由于DR选举是非抢占模式,如果OSPF进程不重启,R2将不会取代R1的DR角色。
执行display ospf peer brief命令,可以查看简要的OSPF邻居信息。
[R1]disp ospf peer brief
OSPF Process 1 with Router ID 10.1.0.1
Peer Statistic Information
------------------------------------------------------------------------------------
Area Id Interface Neighbor id State
0.0.0.0 GigabitEthernet0/0/1 10.1.0.2 Full
0.0.0.0 GigabitEthernet0/0/2 10.1.0.3 Full
------------------------------------------------------------------------------------
[R2]display ospf peer brief
OSPF Process 1 with Router ID 10.1.0.2
Peer Statistic Information
------------------------------------------------------------------------------------
Area Id Interface Neighbor id State
0.0.0.0 GigabitEthernet0/0/1 10.1.0.1 Full
0.0.0.0 GigabitEthernet0/0/2 10.1.0.3 Full
------------------------------------------------------------------------------------
[R3]display ospf peer brief
OSPF Process 1 with Router ID 10.1.0.3
Peer Statistic Information
------------------------------------------------------------------------------------
Area Id Interface Neighbor id State
0.0.0.0 GigabitEthernet0/0/1 10.1.0.1 Full
0.0.0.0 GigabitEthernet0/0/2 10.1.0.2 Full
------------------------------------------------------------------------------------
步骤四 修改OSPF hello和dead时间参数
在R1上执行display ospf interface GigabitEthernet 0/0/1命令,查看OSPF默认的hello和dead时间。
[R1]display ospf interface GigabitEthernet 0/0/1
OSPF Process 1 with Router ID 10.1.0.1
Interfaces
Interface: 10.1.12.1 (GigabitEthernet0/0/1)
Cost: 1 State: DR Type: Broadcast MTU: 1500
Priority: 1
Designated Router: 10.1.12.1
Backup Designated Router: 10.1.12.2
Timers: Hello 10 Dead 40 Poll 120 Retransmit 5 Transmit Delay 1
在R1的GE0/0/1接口执行ospf timer命令,将OSPF hello和dead时间分别修改为15秒和60秒。
[R1]interface GigabitEthernet 0/0/1
[R1-GigabitEthernet0/0/1]ospf timer hello 15
[R1-GigabitEthernet0/0/1]ospf timer dead 60
这步配置完成后,正常会有以下回显信息。
Mar 14 2020 17:33:16-08:00 R1 %%01OSPF/3/NBR_CHG_DOWN(l)[0]:Neighbor event:neigh
bor state changed to Down. (ProcessId=256 NeighborAddress=2.0.1.10 NeighborEve
nt=InactivityTimer NeighborPreviousState=Full NeighborCurrentState=Down)
Mar 14 2020 17:33:16-08:00 R1 %%01OSPF/3/NBR_DOWN_REASON(l)[1]:Neighbor state le
aves full or changed to Down. (ProcessId=256 NeighborRouterId=2.0.1.10 Neighbo
rAreaId=0 NeighborInterface=GigabitEthernet0/0/1NeighborDownImmediate reason=N
eighbor Down Due to Inactivity NeighborDownPrimeReason=Interface Parameter Mism
atch NeighborChangeTime=2020-03-14 17:33:16-08:00)
[R1]display ospf interface g0/0/1
OSPF Process 1 with Router ID 10.1.0.1
Interfaces
Interface: 10.1.12.1 (GigabitEthernet0/0/1)
Cost: 1 State: DR Type: Broadcast MTU: 1500
Priority: 1
Designated Router: 10.1.12.1
Backup Designated Router: 0.0.0.0
Timers: Hello 15 Dead 60 Poll 120 Retransmit 5 Transmit Delay 1
在R1上查看OSPF邻居状态。
[R1]display ospf peer brief
OSPF Process 1 with Router ID 10.1.0.1
Peer Statistic Information
------------------------------------------------------------------------------------------
Area Id Interface Neighbor id State
0.0.0.0 GigabitEthernet0/0/2 10.1.0.3 Full
------------------------------------------------------------------------------------------
上述回显信息表明,R1只有一个邻居,那就是R3。因为R1和R2上的OSPF hello和dead时间取值不同,所以R1无法与R2建立OSPF邻居关系。
在R2的GE0/0/1接口执行ospf timer命令,将OSPF hello和dead时间分别修改为15秒和60秒。
[R2]interface GigabitEthernet 0/0/1
[R2-GigabitEthernet0/0/1]ospf timer hello 15
[R2-GigabitEthernet0/0/1]ospf timer dead 60
…output omit…
Mar 14 2020 17:40:58-08:00 R2 %%01OSPF/4/NBR_CHANGE_E(l)[4]:Neighbor changes eve
nt: neighbor status changed. (ProcessId=256 NeighborAddress=1.12.1.10 Neighbor
Event=LoadingDone NeighborPreviousState=Loading NeighborCurrentState=Full)
再次在R1上查看OSPF邻居状态。
[R1]display ospf peer brief
OSPF Process 1 with Router ID 10.1.0.1
Peer Statistic Information
------------------------------------------------------------------------------------------
Area Id Interface Neighbor id State
0.0.0.0 GigabitEthernet0/0/1 10.1.0.2 Full
0.0.0.0 GigabitEthernet0/0/2 10.1.0.3 Full
------------------------------------------------------------------------------------------
两端时间匹配后,以上回显表示R1和R2正常建立邻居状态。
步骤五 OSPF缺省路由发布及验证
在R1上配置缺省路由并发布到OSPF域内。
配置R1:
interface LoopBack1
ip address 10.10.10.10 255.255.255.0
[R1]ip route-static 0.0.0.0 0.0.0.0 LoopBack 1
[R1]ospf 1
[R1-ospf-1]default-route-advertise
查看R2和R3的路由表。可以看到,R2和R3均已经学习到了R1发布的缺省路由。
[R2]display ip routing-table
Route Flags: R - relay D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 20 Routes : 21
Destination/Mask Proto Pre Cost Flags NextHop Interface
0.0.0.0/0 O_ASE 150 1 D 10.1.12.1 GigabitEthernet0/0/1
[R3]display ip routing-table
Route Flags: R - relay D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 20 Routes : 21
Destination/Mask Proto Pre Cost Flags NextHop Interface
0.0.0.0/0 O_ASE 150 1 D 10.1.13.1 GigabitEthernet0/0/1
使用ping命令,检测R2和R3与10.10.10.10/24网段之间的连通性,验证默认路由的有效性。
[R2]ping 10.10.10.10
PING 10.10.10.10: 56 data bytes press CTRL_C to break
Reply from 10.10.10.10: bytes=56 Sequence=1 ttl=255 time=50 ms
Reply from 10.10.10.10: bytes=56 Sequence=2 ttl=255 time=20 ms
Reply from 10.10.10.10: bytes=56 Sequence=3 ttl=255 time=30 ms
Reply from 10.10.10.10: bytes=56 Sequence=4 ttl=255 time=20 ms
Reply from 10.10.10.10: bytes=56 Sequence=5 ttl=255 time=30 ms
[R3]ping 10.10.10.10
PING 10.10.10.10: 56 data bytes press CTRL_C to break
Reply from 10.10.10.10: bytes=56 Sequence=1 ttl=255 time=50 ms
Reply from 10.10.10.10: bytes=56 Sequence=2 ttl=255 time=20 ms
Reply from 10.10.10.10: bytes=56 Sequence=3 ttl=255 time=30 ms
Reply from 10.10.10.10: bytes=56 Sequence=4 ttl=255 time=30 ms
Reply from 10.10.10.10: bytes=56 Sequence=5 ttl=255 time=40 ms
步骤六 控制OSPF DR/BDR的选举
执行display ospf peer命令,查看R1和R2的DR/BDR角色。
[R1]display ospf peer 10.1.0.2
OSPF Process 1 with Router ID 10.1.0.1
Neighbors
Area 0.0.0.0 interface 10.1.12.1(GigabitEthernet0/0/1)'s neighbors
Router ID: 10.1.0.2 Address: 10.1.12.2
State: Full Mode:Nbr is Master Priority: 1
DR: 10.1.12.2 BDR: 10.1.12.1 MTU: 0
Dead timer due in 53 sec
Retrans timer interval: 0
Neighbor is up for 00:24:49
Authentication Sequence: [ 0 ]
上述回显信息表明,由于默认OSPF路由器优先级(数值为1)相同,但R2的Router ID 10.1.0.2大于R1的Router ID 10.1.0.1,所以R2为DR,R1为BDR。
执行ospf dr-priority命令,修改R1的DR优先级。
[R1]interface GigabitEthernet 0/0/1
[R1-GigabitEthernet0/0/1]ospf dr-priority 200
默认情况下,DR/BDR的选举采用的是非抢占模式。路由器优先级修改后,不会自动重新选举DR。因此,需要重置R1和R2间的OSPF邻居关系。
先关闭然后再打开R1上的Gigabit Ethernet 0/0/1接口,重置R1和R2间的OSPF邻居关系。
[R1]interface GigabitEthernet0/0/1
[R1-GigabitEthernet0/0/1]shutdown
[R1-GigabitEthernet0/0/1]undo shutdown
执行display ospf peer命令,查看R1和R2的DR/BDR角色。
[R1]disp ospf peer 10.1.0.2
OSPF Process 1 with Router ID 10.1.0.1
Neighbors
Area 0.0.0.0 interface 10.1.12.1(GigabitEthernet0/0/1)'s neighbors
Router ID: 10.1.0.2 Address: 10.1.12.2
State: Full Mode:Nbr is Master Priority: 1
DR: 10.1.12.1 BDR: 10.1.12.2 MTU: 0
Dead timer due in 58 sec
Retrans timer interval: 5
Neighbor is up for 00:00:02
Authentication Sequence: [ 0 ]
上述信息表明,R1的DR优先级高于R2,因此R1被选举为DR,而R2成为了BDR。
配置文件
<R1>display current-configuration
<R2>display current-configuration
<R3>display current-configuration