OSPF(Open Shortest Path First,开放式最短路径优先)是基于链路状态的内部网关协议。OSPF具备收敛快、路由无环、扩展性好等优势。链路状态算法路由协议互相通告的是链路状态信息,每台路由器都将本身的链路状态信息(包含接口的IP地址和子网掩码、网络类型、该链路的开销等)发送给其余路由器,并在网络中泛洪,当每台路由器收集到网络内全部链路状态信息后,就能拥有整个网络的拓扑状况,而后根据整网拓扑状况运行SPF算法,得出全部网段的最短路径。算法
R1网络
interface Ethernet0/0/0 ip address 10.0.10.254 255.255.255.0 interface GigabitEthernet0/0/0 ip address 10.1.1.1 255.255.255.252 interface GigabitEthernet0/0/2 ip address 10.1.1.5 255.255.255.252
R2ide
interface Ethernet0/0/0 ip address 10.0.20.254 255.255.255.0 interface GigabitEthernet0/0/0 ip address 10.1.1.2 255.255.255.252 interface GigabitEthernet0/0/1 ip address 10.1.1.9 255.255.255.252
R3oop
interface Ethernet0/0/0 ip address 10.0.30.254 255.255.255.0 interface GigabitEthernet0/0/1 ip address 10.1.1.10 255.255.255.252 interface GigabitEthernet0/0/2 ip address 10.1.1.6 255.255.255.252
在三个路由器的区域0上宣告本身的直连网段,宣告需写反转掩码加密
[r1]ospf 1 [r1-ospf-1]area 0 [r1-ospf-1-area-0.0.0.0]network 10.0.10.0 0.0.0.255 [r1-ospf-1-area-0.0.0.0]network 10.1.1.0 0.0.0.3 [r1-ospf-1-area-0.0.0.0]network 10.1.1.4 0.0.0.3 [r2]ospf [r2-ospf-1]ar 0 [r2-ospf-1-area-0.0.0.0]network 10.0.20.0 0.0.0.255 [r2-ospf-1-area-0.0.0.0]network 10.1.1.0 0.0.0.3 [r2-ospf-1-area-0.0.0.0]network 10.1.1.8 0.0.0.3 [r3]ospf [r3-ospf-1]ar 0 [r3-ospf-1-area-0.0.0.0]network 10.0.30.0 0.0.0.255 [r3-ospf-1-area-0.0.0.0]network 10.1.1.4 0.0.0.3 [r3-ospf-1-area-0.0.0.0]network 10.1.1.8 0.0.0.3
[r1]display ospf interface OSPF Process 1 with Router ID 10.0.10.254 Interfaces Area: 0.0.0.0 (MPLS TE not enabled) IP Address Type State Cost Pri DR BDR 10.0.10.254 Broadcast DR 1 1 10.0.10.254 0.0.0.0 10.1.1.1 Broadcast DR 1 1 10.1.1.1 10.1.1.2 10.1.1.5 Broadcast DR 1 1 10.1.1.5 10.1.1.6
[r1]display ospf peer OSPF Process 1 with Router ID 10.0.10.254 Neighbors Area 0.0.0.0 interface 10.1.1.1(GigabitEthernet0/0/0)'s neighbors Router ID: 10.0.20.254 Address: 10.1.1.2 State: Full Mode:Nbr is Master Priority: 1 DR: 10.1.1.1 BDR: 10.1.1.2 MTU: 0 Dead timer due in 35 sec Retrans timer interval: 5 Neighbor is up for 00:05:08 Authentication Sequence: [ 0 ] Neighbors Area 0.0.0.0 interface 10.1.1.5(GigabitEthernet0/0/2)'s neighbors Router ID: 10.0.30.254 Address: 10.1.1.6 State: Full Mode:Nbr is Master Priority: 1 DR: 10.1.1.5 BDR: 10.1.1.6 MTU: 0 Dead timer due in 38 sec Retrans timer interval: 5 Neighbor is up for 00:02:45 Authentication Sequence: [ 0 ]
[r1]dis ip routing-table protocol ospf Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Public routing table : OSPF Destinations : 3 Routes : 4 OSPF routing table status : <Active> Destinations : 3 Routes : 4 Destination/Mask Proto Pre Cost Flags NextHop Interface 10.0.20.0/24 OSPF 10 2 D 10.1.1.2 GigabitEthernet 0/0/0 10.0.30.0/24 OSPF 10 2 D 10.1.1.6 GigabitEthernet 0/0/2 10.1.1.8/30 OSPF 10 2 D 10.1.1.2 GigabitEthernet 0/0/0 OSPF 10 2 D 10.1.1.6 GigabitEthernet 0/0/2 OSPF routing table status : <Inactive> Destinations : 0 Routes : 0
OSPF协议能够将整个自治系统化为不一样的区域(Area)。链路状态信息只在区域内部泛洪,区域之间传递的只是路由条目而非链路状态信息;区域0是骨干区域,骨干区域负责在非骨干区域之间发布区域间的路由信息。在一个OSPF区域中有且只有一个骨干区域,非骨干区域必须和骨干区域相连,且非骨干区域之间不能直接进行路由信息交互。code
Al-backbone与As-backbone为区域边界路由器router
Al-backboneblog
vlan batch 901 to 902 interface Vlanif901 description to_al-core1 ip address 10.1.1.2 255.255.255.252 interface Vlanif902 description to_as-backbone ip address 10.0.1.2 255.255.255.252 interface GigabitEthernet0/0/1 description to_al-core1 port link-type trunk port trunk allow-pass vlan 2 to 4094 interface GigabitEthernet0/0/2 description to_as-backbone port link-type trunk port trunk allow-pass vlan 2 to 4094 ospf 1 area 0.0.0.0 network 10.0.1.0 0.0.0.3 description to_as-backbone area 0.0.0.1 network 10.1.1.0 0.0.0.3 description to_al-core1
As-backbone接口
vlan batch 902 to 903 interface Vlanif902 description to_al-backbone ip address 10.0.1.1 255.255.255.252 interface Vlanif903 description to_as-core1 ip address 10.2.1.1 255.255.255.252 interface GigabitEthernet0/0/1 description to_as-core1 port link-type trunk port trunk allow-pass vlan 2 to 4094 interface GigabitEthernet0/0/2 description to_al-backbone port link-type trunk port trunk allow-pass vlan 2 to 4094 ospf 1 area 0.0.0.0 network 10.0.1.0 0.0.0.3 description to_al-backbone area 0.0.0.2 network 10.2.1.0 0.0.0.3 description to_as-core1
Al-core1ip
vlan batch 4 901 interface Vlanif4 description to_pc1 ip address 10.1.4.254 255.255.255.0 interface Vlanif901 description to_al-backbone ip address 10.1.1.1 255.255.255.252 interface GigabitEthernet0/0/1 description to_al-backbone port link-type trunk port trunk allow-pass vlan 2 to 4094 interface GigabitEthernet0/0/2 description to_pc1 port link-type access port default vlan 4 ospf 1 area 0.0.0.1 network 10.1.1.0 0.0.0.3 description to_al-backbone network 10.1.4.0 0.0.0.255 description to_pc1
As-core1
vlan batch 4 903 interface Vlanif4 description to_pc2 ip address 10.2.4.254 255.255.255.0 interface Vlanif903 description to_as-backbone ip address 10.2.1.2 255.255.255.252 interface GigabitEthernet0/0/1 description to_as-backbone port link-type trunk port trunk allow-pass vlan 2 to 4094 interface GigabitEthernet0/0/2 description to_pc2 port link-type access port default vlan 4 ospf 1 area 0.0.0.2 network 10.2.1.0 0.0.0.3 description to_as-backbone network 10.2.4.0 0.0.0.255 description to_pc1
<al-backbone>dis ip routing-table Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Routing Tables: Public Destinations : 9 Routes : 9 Destination/Mask Proto Pre Cost Flags NextHop Interface 10.0.1.0/30 Direct 0 0 D 10.0.1.2 Vlanif902 10.0.1.2/32 Direct 0 0 D 127.0.0.1 Vlanif902 10.1.1.0/30 Direct 0 0 D 10.1.1.2 Vlanif901 10.1.1.2/32 Direct 0 0 D 127.0.0.1 Vlanif901 10.1.4.0/24 OSPF 10 2 D 10.1.1.1 Vlanif901 10.2.1.0/30 OSPF 10 2 D 10.0.1.1 Vlanif902 10.2.4.0/24 OSPF 10 3 D 10.0.1.1 Vlanif902 127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0 127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
OSPF报文验证功能,经过验证的报文才能接受
1. 区域认证:区域内全部路由器(三层交换机)的认证模式和口令必须一致 2. 链路认证:针对某个邻居设置单独的认证模式和密码。同时配置了两种,则链路认证优先
1. 简单验证模式:明文传输 2. MD5验证模式:md5加密传输 3. Key chain验证模式:同时配置多个密钥,不一样密钥单独设置生效周期
Al-backbone区域1配置 [al-backbone-ospf-1-area-0.0.0.1]authentication-mode simple plain 111111 Al-core1区域1配置 [al-core1-ospf-1-area-0.0.0.1]authentication-mode simple plain 111111
As-backbone区域2配置 [as-backbone-ospf-1-area-0.0.0.2]authentication-mode simple cipher 111111 As-core1区域2配置 [as-backbone-ospf-1-area-0.0.0.2]authentication-mode simple cipher 111111
Al-backbone区域1配置 [al-backbone-ospf-1-area-0.0.0.1]undo authentication-mode [al-backbone-ospf-1-area-0.0.0.1]authentication-mode md5 1 huawei
标识符为1,配置口令为huawei
Al-core1区域1配置 [al-core1-ospf-1-area-0.0.0.1]undo authentication-mode [al-core1-ospf-1-area-0.0.0.1]authentication-mode md5 1 huawei
[Huawei]interface GigabitEthernet0/0/1 三层交换机需先清除以太网接口二层配置并开启三层功能 [Huawei-GigabitEthernet0/0/1]undo portswitch [Huawei-GigabitEthernet0/0/1]ospf authentication-mode md5 1 huawei
被动接口也称抑制接口,成为被动接口后,将不会接收和发送OSPF报文。通常配置链接pc的接口为被动接口
[al-core1-ospf-1]silent-interface GigabitEthernet 0/0/2
OSPF使用Router-ID做为路由器的身份标识,若是在启动ospf时没有指定Router-ID,则OSPF没法正常启动。例如,路由器(三层交换机)上未配置任何ip地址。
Router-ID命令配置 --> 最大的loopback接口ip地址 --> 最大的其余接口ip地址(不考虑up/down状况)
只有配选为Router-ID的接口ip地址被删除/修改,才触发从新选择过程。Router-ID改变以后,需手动reset ospf协议。
[al-backbone]router id 1.1.1.1 <al-backbone>reset ospf process
<al-backbone>dis router id RouterID:1.1.1.1
DR(指定路由器):全部的路由器都只将各自的链路状态信息发送给DR,再由DR以组播方式发送至全部路由器。
BDR(备份指定路由器):当DR因为故障失效时,BDR成为DR,并在选择新的BDR路由器。
DR Other(其余路由器):非DR与BDR的路由器
比较优先级,优先级高的为DR,次高的为BDR
比较Router-ID,数值高的为DR,次高的为BDR
Notes:DR选举针对接口,DR选举是非抢占的。
三层交换机需先清除以太网接口二层配置并开启三层功能
[Huawei-GigabitEthernet0/0/1]undo portswitch [Huawei-GigabitEthernet0/0/1]ospf dr-priority 10
改变优先级后,能够利用下面两种方法从新进行DR/BDR的选择,可是这会致使路由器(三层交换机)之间的OSPF邻接关系中断,通常状况下不推荐使用
当路由器或交换机上同时存在多种路由协议的时候,系统为每一种路由协议设置了不一样的默认优先级,当在不一样协议中发现同一条路由时,协议优先级高的将被优选。
[al-backbone]ospf [al-backbone-ospf-1]preference 200
ospf接口的开销值若是没配置,ospf会根据该接口的带宽自动计算其开销值。计算公式为:接口开销=带宽参考值/接口带宽,取计算结果的整数部分做为接口开销值,经过改变带宽参考值能够间接改变接口的开销值。
三层交换机需先清除以太网接口二层配置并开启三层功能
[Huawei-GigabitEthernet0/0/1]undo portswitch [Huawei-GigabitEthernet0/0/1]ospf cost 1000
[al-backbone]ospf [al-backbone-ospf-1]bandwidth-reference 10000
在OSPF协议中的网络类型为广播网络类型,其默认hello计时器为10秒,dead计时器为40秒
三层交换机需先清除以太网接口二层配置并开启三层功能
[Huawei-GigabitEthernet0/0/1]undo portswitch [Huawei-GigabitEthernet0/0/1]ospf timer hello 20 [Huawei-GigabitEthernet0/0/1]ospf timer dead 80