单区域OSPF
OSPF( Open Shortest Path First)开放最短链路优先路由协议是典型的链路状态路由协议。它作为一种内部网关协议(IGP)用于在同一个自治系统(AS)中的路由器之间交换路由信息。
OSPF将网络划分为4种不同 的类型:广播多路访问型(BMA),非广播多路访问型(NBMA),点到点型(Point-Point)和点到多点型(Point-to MultiPoint)
示例1 点到点链路上的OSPF
拓扑图
配置代码:
》》》Router1
Router(config)#
Router(config)#int s2/0
Router(config-if)#ip address 192.168.2.1 255.255.255.0
Router(config-if)#clock rate 128000
Router(config-if)#no shutdown
Router(config-if)#exit
Router(config)#int f0/0
Router(config-if)#ip address 192.168.1.1 255.255.255.0
Router(config-if)#no shutdown
Router(config)#router ospf 1
Router(config-router)#network 192.168.1.0 255.255.255.0 area 0
Router(config-router)#network 192.168.2.0 255.255.255.0 area 0
Router(config-router)#exit
》》》Router2
Router(config)#int s3/0
Router(config-if)#ip address 192.168.3.1 255.255.255.0
Router(config-if)#clock rate 128000
Router(config-if)#no shutdown
Router(config-if)#exit
Router(config)#int s2/0
Router(config-if)#ip address 192.168.2.2 255.255.255.0
Router(config-if)#no shutdown
Router(config)#router ospf 1
Router(config-router)#network 192.168.2.0 255.255.255.0 area 0
Router(config-router)#network 192.168.3.0 255.255.255.0 area 0
》》》Router3
Router(config)#int f0/0
Router(config-if)#ip address 192.168.4.1 255.255.255.0
Router(config-if)#no shutdown
Router(config-if)#exit
Router(config)#int s3/0
Router(config-if)#ip address 192.168.4.2 255.255.255.0
Router(config-if)#ip address 192.168.3.2 255.255.255.0
Router(config-if)#no shutdown
Router(config)#router ospf 1
Router(config-router)#network 192.168.3.0 255.255.255.0 area 0
Router(config-router)#network 192.168.4.0 255.255.255.0 area 0
测试:可以在Router1上查看
Router#show 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
Gateway of last resort is not set
C 192.168.1.0/24 is directly connected, FastEthernet0/0
C 192.168.2.0/24 is directly connected, Serial2/0
O 192.168.3.0/24 [110/1562] via 192.168.2.2, 00:08:01, Serial2/0
O 192.168.4.0/24 [110/1563] via 192.168.2.2, 00:07:17, Serial2/0
在PC0上测试
PC>ping 192.168.4.2
Pinging 192.168.4.2 with 32 bytes of data:
Reply from 192.168.4.2: bytes=32 time=109ms TTL=125
Reply from 192.168.4.2: bytes=32 time=125ms TTL=125
Reply from 192.168.4.2: bytes=32 time=125ms TTL=125
Reply from 192.168.4.2: bytes=32 time=125ms TTL=125
Ping statistics for 192.168.4.2:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 109ms, Maximum = 125ms, Average = 121ms
PC>
测试成功