OSPF(Open Shortest Path First开放式最短路径优先)是一个内部网关协议(Interior Gateway Protocol,简称IGP),用于在单一自治系统(autonomous system,AS)内决策路由。与RIP相对,OSPF是链路状态路由协议,而RIP是距离向量路由协议。
链路是路由器接口的另一种说法,因此OSPF也称为接口状态路由协议。OSPF通过路由器之间通告网络接口的状态来建立链路状态数据库,生成最短路径树,每个OSPF路由器使用这些最短路径构造路由表。
链路是路由器接口的另一种说法,因此OSPF也称为接口状态路由协议。OSPF通过路由器之间通告网络接口的状态来建立链路状态数据库,生成最短路径树,每个OSPF路由器使用这些最短路径构造路由表。
OSPF路由协议是一种典型的链路状态(Link-state)的路由协议,一般用于同一个路由域内。在这里,路由域是指一个自治系统(Autonomous System),即AS,它是指一组通过统一的路由政策或路由协议互相交换路由信息的网络。在这个AS中,所有的OSPF路由器都维护一个相同的描述这个AS结构的数据库,该数据库中存放的是路由域中相应链路的状态信息,OSPF路由器正是通过这个数据库计算出其OSPF路由表的。
作为一种链路状态的路由协议,OSPF将链路状态广播数据包LSA(Link State Advertisement)传送给在某一区域内的所有路由器,这一点与距离矢量路由协议不同。运行距离矢量路由协议的路由器是将部分或全部的路由表传递给与其相邻的路由器。
实验设备:3台路由器
实验目的:掌握OSPF单区域配置
实验拓扑图如下:
R1配置:
r1(config)#int f0/0
r1(config-if)#ip add 192.168.10.1 255.255.255.0 指定IP及掩码
r1(config-if)#no sh
r1(config)#int loopback 1 新增并进入环回地址1 (环回地址无需手工开启,默认开启)
r1(config-if)#ip add 1.1.1.1 255.255.255.0 设定IP及掩码
r1(config)#router ospf 100 启用OSPF协议并指定进程号100
r1(config-router)#network 192.168.10.0 0.0.0.255 area 0
r1(config-router)#network 1.1.1.0 0.0.0.255 area 0 宣告直连网段+反码,并设定区域(区域号是0的为骨干区域)
R2配置:
r2(config)#int f0/0
r2(config-if)#ip add 192.168.10.2 255.255.255.0 指定IP及掩码
r2(config-if)#no sh
r2(config)#int f0/1
r2(config-if)#ip add 192.168.20.1 255.255.255.0 设定IP及掩码
r2(config-if)#no sh
r2(config)#router ospf 100 启用OSPF协议并指定进程号100
r2(config-router)#network 192.168.10.0 0.0.0.255 area 0
r2(config-router)#network 192.168.20.0 0.0.0.255 area 0 宣告直连网段+反码,并设定区域(区域号是0的为骨干区域)
R3配置:
r3(config)#int f0/0
r3(config-if)#ip add 192.168.20.2 255.255.255.0 指定IP及掩码
r3(config-if)#no sh
r3(config)#int loopback 3 新增并进入环回地址3
r3(config-if)#ip add 3.3.3.3 255.255.255.0 设定IP及掩码
r3(config)#router ospf 100 启用OSPF协议并指定进程号100
r3(config-router)#network 192.168.20.0 0.0.0.255 area 0
r3(config-router)#network 3.3.3.0 0.0.0.255 area 0 宣告直连网段+反码,并设定区域(区域号是0的为骨干区域)
调试验证:
R1:
r1#sh ip router 查看路由表条目
Codes: C - connected, S - static, I - IGRP, 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, E - EGP
i - 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 - ODR
P - periodic downloaded static route
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, E - EGP
i - 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 - 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, Loopback1
3.0.0.0/32 is subnetted, 1 subnets 直连网段
O 3.3.3.3 [110/3] via 192.168.10.2, 00:27:40, FastEthernet0/0 有到3.3.3.3的路由
C 192.168.10.0/24 is directly connected, FastEthernet0/0
O 192.168.20.0/24 [110/2] via 192.168.10.2, 00:28:57, FastEthernet0/0 有到192.168.20.0的路由
C 1.1.1.0 is directly connected, Loopback1
3.0.0.0/32 is subnetted, 1 subnets 直连网段
O 3.3.3.3 [110/3] via 192.168.10.2, 00:27:40, FastEthernet0/0 有到3.3.3.3的路由
C 192.168.10.0/24 is directly connected, FastEthernet0/0
O 192.168.20.0/24 [110/2] via 192.168.10.2, 00:28:57, FastEthernet0/0 有到192.168.20.0的路由
r1#ping 3.3.3.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 3.3.3.3, timeout is 2 seconds:
!!!!! 连通测试成功
Success rate is 100 percent (5/5), round-trip min/avg/max = 62/62/63 ms
Sending 5, 100-byte ICMP Echos to 3.3.3.3, timeout is 2 seconds:
!!!!! 连通测试成功
Success rate is 100 percent (5/5), round-trip min/avg/max = 62/62/63 ms
R2:
r2#sh ip route
Codes: C - connected, S - static, I - IGRP, 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, E - EGP
i - 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 - ODR
P - periodic downloaded static route
Codes: C - connected, S - static, I - IGRP, 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, E - EGP
i - 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 - 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/2] via 192.168.10.1, 00:34:20, FastEthernet0/0
3.0.0.0/32 is subnetted, 1 subnets
O 3.3.3.3 [110/2] via 192.168.20.2, 00:31:57, FastEthernet0/1
C 192.168.10.0/24 is directly connected, FastEthernet0/0
C 192.168.20.0/24 is directly connected, FastEthernet0/1
O 1.1.1.1 [110/2] via 192.168.10.1, 00:34:20, FastEthernet0/0
3.0.0.0/32 is subnetted, 1 subnets
O 3.3.3.3 [110/2] via 192.168.20.2, 00:31:57, FastEthernet0/1
C 192.168.10.0/24 is directly connected, FastEthernet0/0
C 192.168.20.0/24 is directly connected, FastEthernet0/1
r2#ping 1.1.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 1.1.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 31/31/32 ms
Sending 5, 100-byte ICMP Echos to 1.1.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 31/31/32 ms
r2#ping 3.3.3.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 3.3.3.3, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 31/31/32 ms
Sending 5, 100-byte ICMP Echos to 3.3.3.3, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 31/31/32 ms
R3:
r3#sh ip route
Codes: C - connected, S - static, I - IGRP, 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, E - EGP
i - 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 - ODR
P - periodic downloaded static route
Codes: C - connected, S - static, I - IGRP, 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, E - EGP
i - 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 - 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/3] via 192.168.20.1, 00:34:01, FastEthernet0/0
3.0.0.0/24 is subnetted, 1 subnets
C 3.3.3.0 is directly connected, Loopback3
O 192.168.10.0/24 [110/2] via 192.168.20.1, 00:34:01, FastEthernet0/0
C 192.168.20.0/24 is directly connected, FastEthernet0/0
O 1.1.1.1 [110/3] via 192.168.20.1, 00:34:01, FastEthernet0/0
3.0.0.0/24 is subnetted, 1 subnets
C 3.3.3.0 is directly connected, Loopback3
O 192.168.10.0/24 [110/2] via 192.168.20.1, 00:34:01, FastEthernet0/0
C 192.168.20.0/24 is directly connected, FastEthernet0/0
r3#ping 1.1.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 1.1.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 47/59/63 ms
Sending 5, 100-byte ICMP Echos to 1.1.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 47/59/63 ms
调试证明三台设备均学到了另外两台的路由,PING测试成功,全网互通,实验成功!
本文转自 149banzhang 51CTO博客,原文链接:http://blog.51cto.com/149banzhang/764512,如需转载请自行联系原作者