1、实验 4-1 OSPF单区域配置 学习目的 理解 OSPF 路由器 Router ID 的意义 掌握在特定接口或网络启用 OSPF 的方法 掌握使用 display 命令查看 OSPF 工作情况的方法 掌握使用 OSPF 发布默认路由的方法 掌握修改 OSPF hello 和 dead 时间的方法 掌握修改 OSPF 优先级的方法 理解 OSPF 在以太网上的 DR/BDR 选择过程 拓扑图 场景 你是公司的网络管理员。现在公司的网络准备使用OSPF协议来进行路由信息的传递。规划网络中所有路由器属于OSPF 的区域0 。实际使用中需要向OSPF发布默认路由,此外你也希望通过这次部署了解DR/B
2、DR选举的机制。 学习任务 步骤一. 基本配置 system-view Enter system view, return user view with Ctrl+Z. Huaweisysname R1 R1interface serial1/0/0 R1-Serial1/0/0ip address 10.0.12.1 24 R1-Serial1/0/0interface GigabitEthernet 0/0/0 R1-GigabitEthernet0/0/0ip address 10.0.13.1 24 R1-GigabitEthernet0/0/0interface loopback 0
3、 R1-LoopBack0ip address 10.0.1.1 24 system-view Enter system view, return user view with Ctrl+Z. Huaweisysname R2 R2interface serial 1/0/0 R2-Serial1/0/0ip address 10.0.12.2 24 R2-Serial1/0/0interface loopback 0 R2-LoopBack0ip address 10.0.2.2 24 system-view Enter system view, return user view with
4、Ctrl+Z. Huaweisysname R3 R3interface GigabitEthernet 0/0/0 R3-GigabitEthernet0/0/0ip address 10.0.13.3 24 R3-GigabitEthernet0/0/0interface loopback 0 R3-LoopBack0ip address 10.0.3.3 24 R3-LoopBack0interface loopback 2 R3-LoopBack2ip address 172.16.0.1 24 步骤二. OSPF配置 定义R1的Loopback0 接口地址 10.0.1.1作为R1的
5、Router ID,使用默认的OSPF进程号1,将10.0.12.0/24 、10.0.13.0/24和10.0.1.0/24三个网段定义到OSPF区域0。 R1ospf 1 router-id 10.0.1.1 R1-ospf-1area 0 R1-ospf-1-area-0.0.0.0network 10.0.1.0 0.0.0.255 R1-ospf-1-area-0.0.0.0network 10.0.13.0 0.0.0.255 R1-ospf-1-area-0.0.0.0network 10.0.12.0 0.0.0.255 注意:同一个路由器可以开启多个OSPF 进程,默认进程号
6、为1 ,由于进程号只具有本地意义,所以同一路由域的不同路由器可以使用相同或不同的OSPF进程号;network命令后面需使用反掩码。 定义R2的Loopback0 接口地址 10.0.2.2作为R2的Router ID,配置使用OSPF进程号10 ,将10.0.12.0/24和10.0.2.0/24两个网段定义到OSPF区域0。 R2ospf 10 router-id 10.0.2.2 R2-ospf-10area 0 R2-ospf-10-area-0.0.0.0network 10.0.12.0 0.0.0.255 R2-ospf-10-area-0.0.0.0network 10.0.2
7、.0 0.0.0.255 定义R3的Loopback0 接口地址 10.0.3.3作为R3的Router ID,配置使用OSPF进程号100,将 10.0.13.0/24和10.0.3.0/24两个网段定义到OSPF区域0 。 R3ospf 100 router-id 10.0.3.3 R3-ospf-100area 0 R3-ospf-100-area-0.0.0.0network 10.0.13.0 0.0.0.255 R3-ospf-100-area-0.0.0.0network 10.0.3.0 0.0.0.255 步骤三. OSPF验证 查看R1、R2和R3的路由表。 display
8、 ip routing-table Route Flags: R - relay, D - download to fib - Routing Tables: Public Destinations : 16 Routes : 16 Destination/Mask Proto Pre Cost Flags NextHop Interface 10.0.1.0/24 Direct 0 0 D 10.0.1.1 LoopBack0 10.0.1.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0 10.0.1.255/32 Direct 0 0 D 127.0.0.1
9、 InLoopBack0 10.0.2.2/32 OSPF 10 1562 D 10.0.12.2 Serial1/0/0 10.0.3.3/32 OSPF 10 1 D 10.0.13.3 GigabitEthernet0/0/0 10.0.12.0/24 Direct 0 0 D 10.0.12.1 Serial1/0/0 10.0.12.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0 10.0.12.2/32 Direct 0 0 D 10.0.12.2 Serial1/0/0 10.0.12.255/32 Direct 0 0 D 127.0.0.1 I
10、nLoopBack0 10.0.13.0/24 Direct 0 0 D 10.0.13.1 GigabitEthernet0/0/0 10.0.13.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0 10.0.13.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 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
11、.1 InLoopBack0 255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 display ip routing-table Route Flags: R - relay, D - download to fib - Routing Tables: Public Destinations : 14 Routes : 14 Destination/Mask Proto Pre Cost Flags NextHop Interface 10.0.1.1/32 OSPF 10 1562 D 10.0.12.1 Serial1/0/0 10
12、.0.2.0/24 Direct 0 0 D 10.0.2.2 LoopBack0 10.0.2.2/32 Direct 0 0 D 127.0.0.1 InLoopBack0 10.0.2.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 10.0.3.3/32 OSPF 10 1563 D 10.0.12.1 Serial1/0/0 10.0.12.0/24 Direct 0 0 D 10.0.12.2 Serial1/0/0 10.0.12.1/32 Direct 0 0 D 10.0.12.1 Serial1/0/0 10.0.12.2/32 Dire
13、ct 0 0 D 127.0.0.1 InLoopBack0 10.0.12.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 10.0.13.0/24 OSPF 10 1563 D 10.0.12.1 Serial1/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 255.255.255.255/32 D
14、irect 0 0 D 127.0.0.1 InLoopBack0 display ip routing-table Route Flags: R - relay, D - download to fib - Routing Tables: Public Destinations : 16 Routes : 16 Destination/Mask Proto Pre Cost Flags NextHop Interface 10.0.1.1/32 OSPF 10 1 D 10.0.13.1 GigabitEthernet0/0/0 10.0.2.2/32 OSPF 10 1563 D 10.0
15、.13.1 GigabitEthernet0/0/0 10.0.3.0/24 Direct 0 0 D 10.0.3.3 LoopBack0 10.0.3.3/32 Direct 0 0 D 127.0.0.1 InLoopBack0 10.0.3.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 10.0.12.0/24 OSPF 10 1563 D 10.0.13.1 GigabitEthernet0/0/0 10.0.13.0/24 Direct 0 0 D 10.0.13.3 GigabitEthernet0/0/0 10.0.13.3/32 Dire
16、ct 0 0 D 127.0.0.1 InLoopBack0 10.0.13.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 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.0.0/24 Direct 0 0 D 172.16.0.1 LoopBack2 172.16.0.1/32 Direct 0
17、 0 D 127.0.0.1 InLoopBack0 172.16.0.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 测试 R2到 10.0.1.1和 10.0.3.3的连通性。 R2ping 10.0.1.1 PING 10.0.1.1: 56 data bytes, press CTRL_C to break Reply from 10.0.1.1: bytes=56 Sequence=1 ttl=255 time=37 ms Reply fro
18、m 10.0.1.1: bytes=56 Sequence=2 ttl=255 time=42 ms Reply from 10.0.1.1: bytes=56 Sequence=3 ttl=255 time=42 ms Reply from 10.0.1.1: bytes=56 Sequence=4 ttl=255 time=45 ms Reply from 10.0.1.1: bytes=56 Sequence=5 ttl=255 time=42 ms - 10.0.1.1 ping statistics - 5 packet(s) transmitted 5 packet(s) rece
19、ived 0.00% packet loss round-trip min/avg/max = 37/41/45 ms R2ping 10.0.3.3 PING 10.0.3.3: 56 data bytes, press CTRL_C to break Reply from 10.0.3.3: bytes=56 Sequence=1 ttl=254 time=37 ms Reply from 10.0.3.3: bytes=56 Sequence=2 ttl=254 time=42 ms Reply from 10.0.3.3: bytes=56 Sequence=3 ttl=254 tim
20、e=42 ms Reply from 10.0.3.3: bytes=56 Sequence=4 ttl=254 time=42 ms Reply from 10.0.3.3: bytes=56 Sequence=5 ttl=254 time=42 ms - 10.0.3.3 ping statistics - 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 37/41/42 ms 使用display ip routing-table protocol ospf命令可
21、以查看通过OSPF学到的路由,同样可以在R2和R3上进行相同操作。 R1display ip routing-table protocol ospf Route Flags: R - relay, D - download to fib - Public routing table : OSPF Destinations : 2 Routes : 2 OSPF routing table status : Destinations : 2 Routes : 2 Destination/Mask Proto Pre Cost Flags NextHop Interface 10.0.2.2/32
22、 OSPF 10 1562 D 10.0.12.2 Serial1/0/0 10.0.3.3/32 OSPF 10 1 D 10.0.13.3 GigabitEthernet0/0/0 OSPF routing table status : Destinations : 0 Routes : 0 使用display ospf peer命令查看OSPF 邻居状态。 R1display ospf peer OSPF Process 1 with Router ID 10.0.1.1 Neighbors Area 0.0.0.0 interface 10.0.12.1(Serial1/0/0)s n
23、eighbors Router ID: 10.0.2.2 Address: 10.0.12.2 State: Full Mode:Nbr is Master Priority: 1 DR: None BDR: None MTU: 0 Dead timer due in 30 sec Retrans timer interval: 5 Neighbor is up for 00:09:19 Authentication Sequence: 0 Neighbors Area 0.0.0.0 interface 10.0.13.1(GigabitEthernet0/0/0)s neighbors R
24、outer ID: 10.0.3.3 Address: 10.0.13.3 State: Full Mode:Nbr is Master Priority: 1 DR: 10.0.13.1 BDR: 10.0.13.3 MTU: 0 Dead timer due in 37 sec Retrans timer interval: 5 Neighbor is up for 00:10:04 Authentication Sequence: 0 使用display ospf peer命令可以显示邻居的详绅信息, 由上输出可以看出,R1有两个邻居R2(Router ID: 10.0.2.2)和R3(
25、Router ID: 10.0.3.3),而与邻居状态都是完全邻接状态。另外也可以使用display ospf peer brief命令以更简洁的方式查看邻居状态。 R1display ospf peer brief OSPF Process 1 with Router ID 10.0.1.1 Peer Statistic Information - Area Id Interface Neighbor id State 0.0.0.0 Serial1/0/0 10.0.2.2 Full 0.0.0.0 GigabitEthernet0/0/0 10.0.3.3 Full - R2displa
26、y ospf peer brief OSPF Process 10 with Router ID 10.0.2.2 Peer Statistic Information - Area Id Interface Neighbor id State 0.0.0.0 Serial1/0/0 10.0.1.1 Full - R3display ospf peer brief OSPF Process 100 with Router ID 10.0.3.3 Peer Statistic Information - Area Id Interface Neighbor id State 0.0.0.0 G
27、igabitEthernet0/0/0 10.0.1.1 Full - 步骤四. OSPF Hello 和Dead 时间参数修改 使用display命令查看R1接口G0/0/0运行的OSPF 默认的 Hello和Dead时间参数。 R1display ospf interface GigabitEthernet 0/0/0 OSPF Process 1 with Router ID 10.0.1.1 Interfaces Interface: 10.0.13.1 (GigabitEthernet0/0/0) Cost: 1 State: DR Type: Broadcast MTU: 1500
28、 Priority: 1 Designated Router: 10.0.13.1 Backup Designated Router: 10.0.13.3 Timers: Hello 10 , Dead 40 , Poll 120 , Retransmit 5 , Transmit Delay 1 使用ospf timer命令修改R1接口G0/0/0接口Hello和Dead时间参数,分别配置为15s和60s。 R1interface GigabitEthernet 0/0/0 R1-GigabitEthernet0/0/0ospf timer hello 15 R1-GigabitEthern
29、et0/0/0ospf timer dead 60 R1-GigabitEthernet0/0/0display ospf interface GigabitEthernet 0/0/0 OSPF Process 1 with Router ID 10.0.1.1 Interfaces Interface: 10.0.13.1 (GigabitEthernet0/0/0) Cost: 1 State: DR Type: Broadcast MTU: 1500 Priority: 1 Designated Router: 10.0.13.1 Backup Designated Router: 1
30、0.0.13.3 Timers: Hello 15 , Dead 60 , Poll 120 , Retransmit 5 , Transmit Delay 1 在R1上查看OSPF邻居状态。 R1-Ethernet3/0/0display ospf peer brief OSPF Process 1 with Router ID 10.0.1.1 Peer Statistic Information - Area Id Interface Neighbor id State 0.0.0.0 Serial1/0/0 10.0.2.2 Full - 由以上输出可以看出,此时R1只有一个邻居R2
31、。因为R1 与R3之间的Hello和Dead时间参数不匹配,无法建立邻居关系。 使用ospf timer命令修改R3接口G0/0/0接口Hello和Dead时间参数分别为为15s和60s。 R3interface GigabitEthernet 0/0/0 R3-GigabitEthernet0/0/0ospf timer hello 15 R3-GigabitEthernet0/0/0ospf timer dead 60 R3-GigabitEthernet0/0/0display ospf interface GigabitEthernet 0/0/0 OSPF Process 100 w
32、ith Router ID 10.0.3.3 Interfaces Interface: 10.0.13.3 (GigabitEthernet0/0/0) Cost: 1 State: DR Type: Broadcast MTU: 1500 Priority: 1 Designated Router: 10.0.13.3 Backup Designated Router: 10.0.13.1 Timers: Hello 15 , Dead 60 , Poll 120 , Retransmit 5 , Transmit Delay 1 再次在R1上查看OSPF邻居状态。 R1display o
33、spf peer brief OSPF Process 1 with Router ID 10.0.1.1 Peer Statistic Information - Area Id Interface Neighbor id State 0.0.0.0 Serial1/0/0 10.0.2.2 Full 0.0.0.0 GigabitEthernet0/0/0 10.0.3.3 Full - 步骤五. OSPF缺省路由发布及验证 在R3上配置默认路由并发布到OSPF域内。 R3ip route-static 0.0.0.0 0 LoopBack 2 R3ospf 100 R3-ospf-100
34、default-route-advertise 查看R1和R2的路由表,可以看到R1和R2 都学到了R3发布的默认路由。 R1display ip routing-table Route Flags: R - relay, D - download to fib - Routing Tables: Public Destinations : 17 Routes : 17 Destination/Mask Proto Pre Cost Flags NextHop Interface 0.0.0.0/0 O_ASE 150 1 D 10.0.13.3 GigabitEthernet0/0/0 10
35、.0.1.0/24 Direct 0 0 D 10.0.1.1 LoopBack0 10.0.1.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0 10.0.1.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 10.0.2.2/32 OSPF 10 1562 D 10.0.12.2 Serial1/0/0 10.0.3.3/32 OSPF 10 1 D 10.0.13.3 GigabitEthernet0/0/0 10.0.12.0/24 Direct 0 0 D 10.0.12.1 Serial1/0/0 10.0.12.1/
36、32 Direct 0 0 D 127.0.0.1 InLoopBack0 10.0.12.2/32 Direct 0 0 D 10.0.12.2 Serial1/0/0 10.0.12.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 10.0.13.0/24 Direct 0 0 D 10.0.13.1 GigabitEthernet0/0/0 10.0.13.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0 10.0.13.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 127.0.0.0
37、/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 255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 R2display ip routing-table Route Flags: R - relay, D - download to fib - Routing Tables: Public Destinatio
38、ns : 15 Routes : 15 Destination/Mask Proto Pre Cost Flags NextHop Interface 0.0.0.0/0 O_ASE 150 1 D 10.0.12.1 Serial1/0/0 10.0.1.1/32 OSPF 10 1562 D 10.0.12.1 Serial1/0/0 10.0.2.0/24 Direct 0 0 D 10.0.2.2 LoopBack0 10.0.2.2/32 Direct 0 0 D 127.0.0.1 InLoopBack0 10.0.2.255/32 Direct 0 0 D 127.0.0.1 I
39、nLoopBack0 10.0.3.3/32 OSPF 10 1563 D 10.0.12.1 Serial1/0/0 10.0.12.0/24 Direct 0 0 D 10.0.12.2 Serial1/0/0 10.0.12.1/32 Direct 0 0 D 10.0.12.1 Serial1/0/0 10.0.12.2/32 Direct 0 0 D 127.0.0.1 InLoopBack0 10.0.12.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 10.0.13.0/24 OSPF 10 1563 D 10.0.12.1 Serial1/
40、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 255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 使用ping命令测试从R2到172.16.0.1的连通性。 ping 172.16.0.1 PING 172.16.0.1: 56 data bytes, press CTRL_C to
41、 break Reply from 172.16.0.1: bytes=56 Sequence=1 ttl=254 time=47 ms Reply from 172.16.0.1: bytes=56 Sequence=2 ttl=254 time=37 ms Reply from 172.16.0.1: bytes=56 Sequence=3 ttl=254 time=37 ms Reply from 172.16.0.1: bytes=56 Sequence=4 ttl=254 time=37 ms Reply from 172.16.0.1: bytes=56 Sequence=5 tt
42、l=254 time=37 ms - 172.16.0.1 ping statistics - 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 37/39/47 ms 步骤六. OSPF DR/BDR选举控制 使用display ospf peer命令查看当前R1 和R3的DR/BDR角色信息。 R1display ospf peer 10.0.3.3 OSPF Process 1 with Router ID 10.0.1.1 Neighbors Area 0.0.
43、0.0 interface 10.0.13.1(GigabitEthernet0/0/0)s neighbors Router ID: 10.0.3.3 Address: 10.0.13.3 State: Full Mode:Nbr is Master Priority: 1 DR: 10.0.13.3 BDR: 10.0.13.1 MTU: 0 Dead timer due in 49 sec Retrans timer interval: 5 Neighbor is up for 00:17:40 Authentication Sequence: 0 以上输出表明,由于默认路由器优先级(数
44、值为1)相同,但 R3的Router ID 10.0.3.3大于R1的Router ID 10.0.1.1,所以R3 为DR,R1 为BDR。 使用ospf dr-priority命令修改R1和R3 的DR路由优先级。 R1interface GigabitEthernet 0/0/0 R1-GigabitEthernet0/0/0ospf dr-priority 200 R3interface GigabitEthernet 0/0/0 R3-GigabitEthernet0/0/0ospf dr-priority 100 由于DR/BDR选举默认为不抢占模式,因此在修改了路由器优先级后不会
45、自动重新选举DR,需要重置R1和R3的邻居关系。 关闭并重新开启R1或R3上的接口GigabitEthernet 0/0/0,使R1与R3邻居关系重置。 R1interface GigabitEthernet0/0/0 R1-GigabitEthernet0/0/0shutdown R1-GigabitEthernet0/0/0undo shutdown 使用display ospf peer命令查看当前R1 和R3的DR/BDR角色信息。 R1-GigabitEthernet 0/0/0display ospf peer 10.0.3.3 OSPF Process 1 with Router ID 10.0.1.1 Neighbors Area 0.0.0.0 interface 10.0.13.1(GigabitEthernet0/0/0)s neighbors Router ID: 10.0.3.3 Address: 10.0.13.3 Sta