1、十十.OSPF单区域单区域路由路由配置配置场景场景 你是公司的网络管理员。现在公司的网络准备使用OSPF协议来进行路由信息的传递。规划网络中所有路由器属于OSPF的区域0实际使用中需要向OSPF发布默认路由,此外你也希望通过这次部署了解DR/BDR选举的机制。网络拓扑10.0.12.2/2410.0.12.1/24Loopback 010.0.2.2/24Loopback 010.0.1.1/24Loopback 010.0.3.3/2410.0.23.2/2410.0.23.1/24注:loopback不是一个设备,是在路由器里设置出来的Loopback 2172.0.16.1/24步骤一步
2、骤一.基本配置与基本配置与IP编址编址R1的基本配置undo ter monsysHuaweisysname R1R1int s0/0/0R1-Serial0/0/0ip addr 10.0.12.1 24R1-Serial0/0/0undo shutR1-Serial0/0/0int loopback 0R1-LoopBack0ip addr 10.0.1.1 24R2的基本配置undo ter monsysHuaweisysname R2R2int s0/0/0R2-Serial0/0/0ip addr 10.0.12.2 24R2-Serial0/0/0undo shutR2-Seria
3、l0/0/0int s0/0/1R2-Serial0/0/1ip addr 10.0.23.2 24R2-Serial0/0/1undo shutR2-Serial0/0/1int loopback 0R2-LoopBack0ip addr 10.0.2.2 24R3的基本配置undo ter monsysHuaweisysname R3R3int s0/0/1R3-Serial0/0/1ip addr 10.0.23.1 24R3-Serial0/0/1undo shutR3-Serial0/0/1int loopback 0R3-LoopBack0ip addr 10.0.3.3 24步骤
4、二步骤二.OSPF配置配置 定义R1的Loopback0接口地址10.0.1.1作为R1的Router ID,使用默认的OSPF进程号1,将10.0.12.0/24、10.0.1.0/24网段定义到OSPF区域0。R1ospf 1 router-id 10.0.1.1 设置OSPF进程号1,路由器的身份编号(ID)为10.0.1.1R1-ospf-1area 0 设置ospf的区域0R1-ospf-1-area-0.0.0.0network 10.0.1.0 0.0.0.255 将网络10.0.1.0 通告给OSPF协议,0.0.0.255是该网络的反掩码R1-ospf-1-area-0.0.
5、0.0network 10.0.12.0 0.0.0.255R1-ospf-1-area-0.0.0.0quitR1-ospf-1解释:同一个路由器可以开启多个OSPF进程,默认进程号为1,由于进程号只具有本地意义,所以同一路由域的不同路由器可以使用相同或不同的OSPF进程号;network命令后面需使用反掩码。定义R2的Loopback0接口地址10.0.2.2作为R2的Router ID,配置使用OSPF进程号10,将10.0.12.0/24、10.0.23.0/24和10.0.2.0/24两个网段定义到OSPF区域0。R2ospf 10 router-id 10.0.2.2R2-ospf
6、-10area 0R2-ospf-10-area-0.0.0.0network 10.0.2.0 0.0.0.255R2-ospf-10-area-0.0.0.0network 10.0.12.0 0.0.0.255R2-ospf-10-area-0.0.0.0network 10.0.23.0 0.0.0.255R2-ospf-10-area-0.0.0.0quitR2-ospf-10quit定义R3的Loopback0接口地址10.0.3.3作为R3的Router ID,配置使用OSPF进程号100,将10.0.23.0/24和10.0.3.0/24两个网段定义到OSPF区域0。R3osp
7、f 100 router-id 10.0.3.3 R3-ospf-100area 0R3-ospf-100-area-0.0.0.0network 10.0.3.0 0.0.0.255R3-ospf-100-area-0.0.0.0network 10.0.23.0 0.0.0.255R3-ospf-100-area-0.0.0.0quitR3-ospf-100quitR3步骤三步骤三.检查路由无误检查路由无误查看R1、R2和R3的路由表,确认各路由器已经学习到以下红色突出显示部分的RIP路由。R1display ip routing-tableRoute Flags:R-relay,D-do
8、wnload to fib-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 LoopBack0 10.0.2.2/32 OSPF 10 1562 D 10.0.12.2 Serial0/0/0 10.0.3.3/32 OSPF 10 3124 D 10.0.12.2 Serial0/0/0 10.0.12.0/24 Direct 0 0 D 10.0.12.1 Serial0/0/0 10.0.12.1/32 Direct 0 0 D 127.0.0.1 Serial0/0/0 10.
9、0.12.2/32 Direct 0 0 D 10.0.12.2 Serial0/0/0 10.0.23.0/24 OSPF 10 3124 D 10.0.12.2 Serial0/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查看R2的路由表R2dis ip routDestination/Mask Proto Pre Cost Flags NextHop Interface 10.0.1.1/32 OSPF 10 1562 D 10.0.12
10、.1 Serial0/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 LoopBack0 10.0.3.3/32 OSPF 10 1562 D 10.0.23.1 Serial0/0/1 10.0.12.0/24 Direct 0 0 D 10.0.12.2 Serial0/0/0 10.0.12.1/32 Direct 0 0 D 10.0.12.1 Serial0/0/0 10.0.12.2/32 Direct 0 0 D 127.0.0.1 Serial0/0/0 10.
11、0.23.0/24 Direct 0 0 D 10.0.23.2 Serial0/0/1 10.0.23.1/32 Direct 0 0 D 10.0.23.1 Serial0/0/1 10.0.23.2/32 Direct 0 0 D 127.0.0.1 Serial0/0/1 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查看R3的路由表R3dis ip routRoute Flags:R-relay,D-download to fib-10.0.1
12、.1/32 OSPF 10 3124 D 10.0.23.2 Serial0/0/1 10.0.2.2/32 OSPF 10 1562 D 10.0.23.2 Serial0/0/1 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 LoopBack0 10.0.12.0/24 OSPF 10 3124 D 10.0.23.2 Serial0/0/1 10.0.23.0/24 Direct 0 0 D 10.0.23.1 Serial0/0/1 10.0.23.1/32 Direct 0
13、 0 D 127.0.0.1 Serial0/0/1 10.0.23.2/32 Direct 0 0 D 10.0.23.2 Serial0/0/1 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用ping来测试连通性ping 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=254 time=50
14、ms Reply from 10.0.1.1:bytes=56 Sequence=2 ttl=254 time=50 ms Reply from 10.0.1.1:bytes=56 Sequence=3 ttl=254 time=60 ms Reply from 10.0.1.1:bytes=56 Sequence=4 ttl=254 time=50 ms Reply from 10.0.1.1:bytes=56 Sequence=5 ttl=254 time=60 ms -10.0.1.1 ping statistics-5 packet(s)transmitted 5 packet(s)r
15、eceived 0.00%packet loss round-trip min/avg/max=50/54/60 ms步骤四步骤四.查看其他信息查看其他信息使用display ip routing-table protocol ospf命令可以查看通过OSPF学到的路由,同样可以在R2和R3上进行相同操作。dis ip rout protocol ospfRoute Flags:R-relay,D-download to fib-Public routing table:OSPF Destinations:3 Routes:3 OSPF routing table status:Destina
16、tions:3 Routes:3Destination/Mask Proto Pre Cost Flags NextHop Interface 10.0.2.2/32 OSPF 10 1562 D 10.0.12.2 Serial0/0/0 10.0.3.3/32 OSPF 10 3124 D 10.0.12.2 Serial0/0/0 10.0.23.0/24 OSPF 10 3124 D 10.0.12.2 Serial0/0/0OSPF routing table status:Destinations:0 Routes:0使用display ospf peer命令查看OSPF邻居状态。
17、display ospf peer OSPF Process 10 with Router ID 10.0.2.2 Neighbors Area 0.0.0.0 interface 10.0.12.2(Serial0/0/0)s neighbors Router ID:10.0.12.1 Address:10.0.12.1 State:Full Mode:Nbr is Master Priority:1 DR:None BDR:None MTU:0 Dead timer due in 34 sec Retrans timer interval:5 Neighbor is up for 00:2
18、1:43 Authentication Sequence:0 续下页接上页Neighbors Area 0.0.0.0 interface 10.0.23.2(Serial0/0/1)s neighbors Router ID:10.0.3.3 Address:10.0.23.1 State:Full Mode:Nbr is Master Priority:1 DR:None BDR:None MTU:0 Dead timer due in 29 sec Retrans timer interval:5 Neighbor is up for 00:21:32 Authentication Se
19、quence:0 使用display ospf peer命令可以显示邻居的详细信息,由上输出可以看出,R2有两个邻居R1(Router ID:10.0.12.1)和R2(Router ID:10.0.3.3),而且邻居状态都是完全邻接状态。也可以使用display ospf peer brief命令以更简洁的方式查看邻居状态。dis 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 Seria
20、l0/0/0 10.0.12.1 Full 0.0.0.0 Serial0/0/1 10.0.3.3 Full 步骤五步骤五.OSPF缺省路由发布及验证缺省路由发布及验证 1.先给R3增加1个loopback接口,设置IP为172.0.16.1/24 R3 int loopback 2R3-LoopBack2ip addr 172.0.16.1 242.在R3上配置默认路由并发布到OSPF域内。R3ip route-static 0.0.0.0 0 LoopBack 2 一条默认路由,0.0.0.0表示到任何网络,后边的0是反掩码,这条默认路由说明默认情况下到其他网络都通过接口loopback
21、2发送。3.默认路由发布R3ospf 100 R3-ospf-100default-route-advertise 将默认路由发布到OSPF域内在R2上可以看到这条路由已经被学到R2dis ip routRoute Flags:R-relay,D-download to fib-Routing Tables:Public Destinations:13 Routes:13 Destination/Mask Proto Pre Cost Flags NextHop Interface 0.0.0.0/0 O_ASE 150 1 D 10.0.23.1 Serial0/0/1 10.0.1.1/32 OSPF 10 1562 D 10.0.12.1 Serial0/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 LoopBack0 10.0.3.3/32 OSPF 10 1562 D 10.0.23.1 Serial0/0/1 10.0.12.0/24 Direct 0 0 D 10.0.12.2 Serial0/0/0