實驗步驟:
1.首先在3臺路由器上配 置物理接口,並且使用ping命令確保物理鏈路的暢通。
2.在路由器上配置loopback接口:
R1(config)#int loopback 0
R1(config-if)#ip add 1.1.1.1 255.255.255.0
R2(config)#int loopback 0
R2(config-if)#ip add 2.2.2.2 255.255.255.0
R3(config)#int loopback 0
R3(config-if)#ip add 3.3.3.3 255.255.255.0
路由器的RID是路由器接口的最高的IP地址,當有環回口存在是,路由器將使用環回口的最高IP地址作爲起RID,從而保證RID的穩定。
3. 在3臺路由器上分別啓動ospf進程,並且宣告直連接口的網絡。
R1(config)#router ospf 10
R1(config-router)#network 192.168.1.0 0.0.0.255 area 0
R1(config-router)#network 1.1.1.0 0.0.0.255 area 0
R1(config-router)#network 192.168.3.0.0.0.255 area 0
ospf的進程號只有本地意義,既在不同路由器上的進程號可以不相同。但是爲了日後維護的方便,一般啓用相同的進程號。
ospf使用反向掩碼。Area 0表示骨幹區域,在設計ospf網絡時,所有的非骨幹區域都需要和骨幹區域直連!
R2,R3的配置和R1類似,這裏省略。不同的是我們在R2和R3上不宣告各自的環回口。
*Aug 13 17:58:51.411: %OSPF-5-ADJCHG: Process 10, Nbr 2.2.2.2 on Serial1/0 from LOADING to FULL, Loading Done
配置結束後,我們可以看到鄰居關係已經到達FULL狀態。
4. 在R1上查看路由表,可以看到以下信息:
R1#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
1.0.0.0/24 is subnetted, 1 subnets
C 1.1.1.0 is directly connected, Loopback0
C 192.168.1.0/24 is directly connected, Serial1/0
O 192.168.2.0/24 [110/65] via 192.168.1.2, 00:03:42, Serial1/0
C 192.168.3.0/24 is directly connected, FastEthernet0/
我們看到R1學到了192.168.2.0/24這個網段的路由。後面的數字[110/65],分別表示OSPF的管理距離(AD)和路由的Metric 值
OSPF的Metric值是由cost值逐跳累加的。Cost=100Mb/帶寬值。
5. 在R1上show ip ospf neighbor 、show ip ospf interface
R1#show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
3.3.3.3 1 FULL/BDR 00:00:34 192.168.3.3 FastEthernet0/0
2.2.2.2 0 FULL/ - 00:00:32 192.168.1.2 Serial1/0
我們看到R1和R3選取了DR和BDR,而R1和R2沒有選取。
在ospf的五種網絡類型中。Point-to-Point,Point-to-Multipoint(廣播與非廣播)這三種網絡類型不選取DR與 BDR; Broadcast,NBMA選取DR與BDR。
R1#show ip ospf interface
FastEthernet0/0 is up, line protocol is up
Internet Address 192.168.3.1/24, Area 0
Process ID 10, Router ID 1.1.1.1, Network Type BROADCAST, Cost: 1
Transmit Delay is 1 sec, State DR, Priority 1
Designated Router (ID) 1.1.1.1, Interface address 192.168.3.1
Backup Designated router (ID) 3.3.3.3, Interface address 192.168.3.3
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
oob-resync timeout 40
Hello due in 00:00:03
Index 3/3, flood queue length 0
Next 0x0(0)/0x0(0)
Last flood scan length is 1, maximum is 1
Last flood scan time is 0 msec, maximum is 0 msec
Neighbor Count is 1, Adjacent neighbor count is 1
Adjacent with neighbor 3.3.3.3 (Backup Designated Router)
Suppress hello for 0 neighbor(s)
Serial1/0 is up, line protocol is up
Internet Address 192.168.1.1/24, Area 0
Process ID 10, 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 5
oob-resync timeout 40
Hello due in 00:00:02
Index 1/1, flood queue length 0
Next 0x0(0)/0x0(0)
Last flood scan length is 1, maximum is 1
Last flood scan time is 4 msec, maximum is 4 msec
Neighbor Count is 1, Adjacent neighbor count is 1
Adjacent with neighbor 2.2.2.2
Suppress hello for 0 neighbor(s)
Loopback0 is up, line protocol is up
Internet Address 1.1.1.1/24, Area 0
Process ID 10, Router ID 1.1.1.1, Network Type LOOPBACK, Cost: 1
Loopback interface is treated as a stub Host
在這裏我們看到環回口的網絡網絡類型是Loopback,這是一種特殊的網絡類型,只針對環回口存在。我們到R2上看看路由表:
R2#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
1.0.0.0/32 is subnetted, 1 subnets
O 1.1.1.1 [110/65] via 192.168.1.1, 00:12:34, Serial1/0
2.0.0.0/24 is subnetted, 1 subnets
C 2.2.2.0 is directly connected, Loopback0
C 192.168.1.0/24 is directly connected, Serial1/0
C 192.168.2.0/24 is directly connected, Serial1/1
O 192.168.3.0/24 [110/65] via 192.168.1.1, 00:12:34, Serial1/0
[110/65] via 192.168.2.3, 00:12:34, Serial1/1
R2的路由表顯示來自環回口的路由,掩碼爲/32,既我們所說的“主機路由”。在實際應用中,環回口以32位的居多,用作ospf的管理接口。但是如果你 想讓環回口模擬一個網段,我們可以通過以下配置來消除。
R1(config)#int loopback 0
R1(config-if)#ip ospf network point-to-point
環回口只能配置成point-to-point這種類型,不可以配置成其它的類型。
回到R2查看路由表:
R2#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
1.0.0.0/24 is subnetted, 1 subnets
O 1.1.1.0 [110/65] via 192.168.1.1, 00:00:24, Serial1/0
2.0.0.0/24 is subnetted, 1 subnets
C 2.2.2.0 is directly connected, Loopback0
C 192.168.1.0/24 is directly connected, Serial1/0
C 192.168.2.0/24 is directly connected, Serial1/1
O 192.168.3.0/24 [110/65] via 192.168.1.1, 00:00:24, Serial1/0
[110/65] via 192.168.2.3, 00:00:24, Serial1/1
我們看到主機路由沒有了,取而代之的是一個/24的網段。