OSPF协议基本配置注意:此实验拓扑图是以机房的实验拓扑画的,如果是使用模拟器来做此实验,请根据模拟器的拓扑来更改。
实验目的:1.能够独立的配置OSPF的单区域,实现整个区域之间的网络通信。
2.能够使用各种SHOW命令进行检查。
3.理解DR/BDR的选举原则,OSPF的邻接关系的建立过程。
4.邻接关系建立的必须匹配的几个参数5.3张表的形成过程,OSPF协议的基本原理实验要求:1.按照拓扑图把基本的链路连接配置起来,并且配置完成以后检查基本的链路通信(检查直连链路之间能否进行通信)2.运行OSPF协议,实现整个网络之间可达。
(配置OSPF单区域)3.保证R1成为DR,其他的路由器成为DROTHER实验配置:(基本的常见配置和链路配置这里不给出)R1上的配置:R1(config)#int loopback 0R1(config-if)#ip address 11.11.11.11 255.255.255.0 //回环接口,一般回环接口我们主要用来做测试或者模拟网段的时候使用,需要注意回环接口是一个逻辑上的接口。
没有真实的物理接口和他对应,但是回环接口基本上具有所有物理借口的特性R1(config-if)#R1(config)#router ospf 1 //运行OSPF协议,进程ID为1。
进程ID只是为了识别路由器本地运行了几个OSPF进程。
R1(config-router)#router-id 1.1.1.1 //指定R1的router-id为1.1.1.1R1(config-router)#network 12.12.12.0 0.0.0.255 area 0 //将属于12.12.12.0/24这个网段的所有接口公告到区域0里去。
R1(config-router)#network 172.16.1.0 0.0.0.255 area 0R1(config-router)#R2上的配置:R2(config)#router ospf 1R2(config-router)#router-id 2.2.2.2R2(config-router)#network 12.12.12.0 0.0.0.255 area 0R2(config-router)#network 13.13.13.0 0.0.0.255 area 0R2(config-router)#network 172.16.1.0 0.0.0.255 area 0R2(config-router)#R3上的配置:R3(config)#interface loopback 0R3(config-if)#ip address 33.33.33.33 255.255.255.0R3(config)#router ospf 1R3(config-router)#router-id 3.3.3.3R3(config-router)#network 13.13.13.0 0.0.0.255 area 0R3(config-router)#network 172.16.1.0 0.0.0.255 area 0R3(config-router)#network 33.33.33.0 0.0.0.255 area 0当完成上述配置以后我们可以发现已经可以实现整个网络之间的相互通信了。
当做完以后使用各种SHOW命令进行检查。
R1#sh ip ospf neighbor//查看OSPF的邻接关系表,需要注意这里所看到的都是邻居的信息。
Neighbor ID Pri State Dead Time Address Interface2.2.2.2 1 FULL/BDR 00:00:29 172.16.1.2 Ethernet03.3.3.3 1 FULL/DROTHER 00:00:37 172.16.1.3 Ethernet0 2.2.2.2 0 FULL/ - 00:00:30 12.12.12.2 Serial0R1#Neighbor ID下面看到的是邻居的router-idPri 是邻居的接口优先级,进行DR和BDR选举的时候需要比较的参数State 我和邻居之间的状态,是什么邻居关系FULL表示是完全的邻居关系,如果能够看到BDR之类的参数表示邻居是BDRDead Time 死亡时间,多少秒之类没有收到邻居发送过来的HELLO小心就认为邻居DOWN掉了,如果时间变成了00:00:00就表示邻居DOWN了,路由器会把这个邻居关系删除掉。
Address 邻居通过什么IP地址和我相连Interface 邻居和我相连的接口R1#show ip ospf interface brief //检查那些接口被我公告出去了,需要注意有些IOS不支持此命令Interface PID Area IP Address/Mask Cost State Nbrs F/CLo0 1 0 11.11.11.11/24 1 LOOP 0/0Et0 1 0 172.16.1.1/24 10 DR 2/2Se0 1 0 12.12.12.1/24 64 P2P 1/1 Interface 显示被我NETWORK的接口PID 接口的优先级Area 公布到那个区域里去了IP Address/Mask 接口的IP地址和掩码Cost 接口的COST值State 接口的网络类型R1#show ip ospf database //检查OSPF的链路状态数据库OSPF Router with ID (1.1.1.1) (Process ID 1)Router Link States (Area 0)Link ID ADV Router Age Seq# Checksum Link count1.1.1.1 1.1.1.1 1578 0x80000006 0x009ED3 42.2.2.2 2.2.2.2 1650 0x80000006 0x003975 53.3.3.3 3.3.3.3 1448 0x80000005 0x006898 4Net Link States (Area 0)Link ID ADV Router Age Seq# Checksum172.16.1.1 1.1.1.1 1634 0x80000002 0x003A20R1#表示的含义在后面的章节讲到R1#show ip route //检查路由表Codes: C - connected, S - static, R - RIP, M - mobile, B - BGPD - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter areaN1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2E1 - OSPF external type 1, E2 - OSPF external type 2i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area* - candidate default, U - per-user static route, o - ODRP - periodic downloaded static routeGateway of last resort is not set33.0.0.0/32 is subnetted, 1 subnetsO 33.33.33.33 [110/11] via 172.16.1.3, 00:25:22, Ethernet0172.16.0.0/24 is subnetted, 1 subnetsC 172.16.1.0 is directly connected, Ethernet011.0.0.0/24 is subnetted, 1 subnetsC 11.11.11.0 is directly connected, Loopback012.0.0.0/24 is subnetted, 1 subnetsC 12.12.12.0 is directly connected, Serial013.0.0.0/24 is subnetted, 1 subnetsO 13.13.13.0 [110/74] via 172.16.1.2, 00:25:22, Ethernet0[110/74] via 172.16.1.3, 00:25:22, Ethernet0R1#O 表示是通过OSPF协议学到的路由信息[110/11] 前面的110表示OSPF的管理距离是110后面的11表示本路由器到达改网段的距离R1#show ip ospf interface s0 //检查这个接口OSPF的信息Serial0 is up, line protocol is upInternet Address 12.12.12.1/24, Area 0Process ID 1, Router ID 1.1.1.1, Network Type POINT_TO_POINT, Cost: 64 Transmit Delay is 1 sec, State POINT_TO_POINT,Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5oob-resync timeout 40Hello due in 00:00:04Index 1/1, flood queue length 0Next 0x0(0)/0x0(0)Last flood scan length is 1, maximum is 1Last flood scan time is 4 msec, maximum is 4 msecNeighbor Count is 1, Adjacent neighbor count is 1Adjacent with neighbor 2.2.2.2Suppress hello for 0 neighbor(s)R1#Process ID OSPF的进程IDRouter ID 本路由器的router-idNetwork Type 接口的网络类型Cost: 路径成本Hello 10, Dead 40 hello时间和死亡时间第3个要求的配置:R1(config)#interface e0R1(config-if)#ip ospf priority 255 //修改接口的优先级,OSPF里的接口优先级是越大越优先R2(config)#int e0R2(config-if)#ip ospf priority 0 //当优先级为0的时候表示不参与DR和BDR选举,直接成为DROTHERR3(config-router)#int e0R3(config-if)#ip ospf priority 0需要注意的是如果改了以后需要使用clear ip ospf process清楚掉OSPF进程让路由器之间从新建立OSPF邻居关系R1#clear ip ospf processReset ALL OSPF processes? [no]: yR1#清除掉以后我们在来看看R1#show ip ospf neighborNeighbor ID Pri State Dead Time Address Interface2.2.2.2 0 FULL/DROTHER 00:00:38 172.16.1.2 Ethernet03.3.3.3 0 FULL/DROTHER 00:00:36 172.16.1.3 Ethernet02.2.2.2 0 FULL/ - 00:00:30 12.12.12.2 Serial0R1#我们可以看到R2和R3是DROTHER路由器,另外我们在去R2上看看R2#sh ip ospf neighborNeighbor ID Pri State Dead Time Address Interface3.3.3.3 0 2WAY/DROTHER 00:00:31 172.16.1.3 Ethernet0 1.1.1.1 255 FULL/DR 00:00:31 172.16.1.1 Ethernet03.3.3.3 1 FULL/ - 00:00:34 13.13.13.3 Serial11.1.1.1 1 FULL/ - 00:00:31 12.12.12.1 Serial0R2#R2和R3之间的邻居关系只是2WAY状态,为什么是2WAY了,DROTHER和DROTHER 之间不建立起完全的邻接关系,他们之间的关系只到2WAY状态如果是想查看OSPF之间邻接关系建立的详细过程可以使用debug ip ospf adj进行查看,这里只给出R1和R2之间S0建立邻接关系的过程Mar 1 01:01:25.039: OSPF: Build router LSA for area 0, router ID 1.1.1.1, seq 0x8000000C *Mar 1 01:01:34.563: OSPF: Rcv DBD from 2.2.2.2 on Serial0 seq 0x879 opt 0x42 flag 0x7 len 32 mtu 1500 state INIT*Mar 1 01:01:34.567: OSPF: 2 Way Communication to 2.2.2.2 on Serial0, state 2WAY*Mar 1 01:01:34.571: OSPF: Send DBD to 2.2.2.2 on Serial0 seq 0x15E2 opt 0x52 flag 0x7 len 32*Mar 1 01:01:34.575: OSPF: NBR Negotiation Done. We are the SLA VE*Mar 1 01:01:34.579: OSPF: Send DBD to 2.2.2.2 on Serial0 seq 0x879 opt 0x52 flag 0x2 len 92*Mar 1 01:01:34.627: OSPF: Rcv DBD from 2.2.2.2 on Serial0 seq 0x87A opt 0x42 flag 0x3 len 92 mtu 1500 state EXCHANGE*Mar 1 01:01:34.631: OSPF: Send DBD to 2.2.2.2 on Serial0 seq 0x87A opt 0x52 flag 0x0 len 32*Mar 1 01:01:34.635: OSPF: Database request to 2.2.2.2*Mar 1 01:01:34.639: OSPF: sent LS REQ packet to 12.12.12.2, length 24*Mar 1 01:01:34.659: OSPF: Rcv DBD from 2.2.2.2 on Serial0 seq 0x87B opt 0x42 flag 0x1 len 32 mtu 1500 state EXCHANGE*Mar 1 01:01:34.663: OSPF: Exchange Done with 2.2.2.2 on Serial0*MaR1(confr 1 01:01:34.667: OSPF: Send DBD to 2.2.2.2 on Serial0 seq 0x87B opt 0x52 flag 0x0 len 32*Mar 1 01:01:34.687: OSPF: Synchronized with 2.2.2.2 on Serial0, state FULL*Mar 1 01:01:35.199: OSPF: Build router LSA for area 0, router ID 1.1.1.1, seq 0x8000000DR1(config-if)#。