OSPF是开放式最短路径优先协议,与EIGRP不同之处就是ERGRP只能运行在Cisco设备上,另外OSPF有一个最短路径算法。
OSPF属于动态路由协议,支持VLSM(可变长子网掩码)和CIDR(无类域间路由)的无类路由协议,属于IGP(内部网关协议),可以根据算法划分为链路状态协议。
- 距离矢量路由协议:网段 + 距离(Metric) + 矢量(方向/下一跳)
- 链路状态路由协议:链路ID + 链路数据 + 链路属性
- 链路状态路由协议不传递路由条目只传递LSA(链路状态通道)
R1配置:
R1#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#interface f0/0
R1(config-if)#ip address 10.1.1.1 255.255.255.0
R1(config-if)#no shutdown
R1(config-if)#end
R1#
*Mar 1 00:02:38.783: %LINK-3-UPDOWN: Interface FastEthernet0/0, changed state to up
R1#
*Mar 1 00:02:39.523: %SYS-5-CONFIG_I: Configured from console by console
*Mar 1 00:02:39.783: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
R1#write memory
Building configuration...
[OK]
R2配置:
R2#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R2(config)#interface f0/0
R2(config-if)#ip address 10.1.1.2 255.255.255.0
R2(config-if)#no shutdown
R2#write mem
Building configuration...
[OK]
R2#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R2(config)#interface f0/1
R2(config-if)#ip address 10.1.2.1 255.255.255.0
R2(config-if)#no shutdown
R2#write mem
Building configuration...
[OK]
通过上面的配置确保直连要能ping通,下面来配置OSPF路由协议,OSPF和EIGRP配置方法类似,也需要宣告网段。
R1上配置OSPF协议:
R1(config)#router ospf ?
<1-65535> Process ID // 进程号,类似于
R1(config)#router ospf 5
R1(config-router)#network 10.1.1.0 ?
A.B.C.D OSPF wild card bits // 通配符掩码
R1(config-router)#network 10.1.1.0 0.0.0.255 ?
area Set the OSPF area ID // 设置区域ID(可选二进制或IP)
R1(config-router)#network 10.1.1.0 0.0.0.255 area ?
<0-4294967295> OSPF area ID as a decimal value
A.B.C.D OSPF area ID in IP address format
R1(config-router)#network 10.1.1.0 0.0.0.255 area 0
R2上配置OSPF协议:
R2#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R2(config)#router ospf 5 // 这里的进程ID可以不一样
R2(config-router)#network 10.1.2.0 0.0.0.255 area 0 // 这里的通配符掩码,区域ID要和R1一致才能建立邻居关系,回车后R1上出现邻居更新信息
R1#
*Mar 1 00:38:33.747: %OSPF-5-ADJCHG: Process 5, Nbr 10.1.2.1 on FastEthernet0/0 from LOADING to FULL, Loading Done
通说命令查看邻居表:
R1#show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
10.1.2.1 1 FULL/BDR 00:00:38 10.1.1.2 FastEthernet0/0
这时候直接ping 10.1.2.1:
R1#ping 10.1.2.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.1.2.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 8/10/12 ms
这样就成功建立邻居关系了。