码迷,mamicode.com
首页 > 其他好文 > 详细

NA西游第五难:OSPF基础配置

时间:2019-11-13 11:15:00      阅读:65      评论:0      收藏:0      [点我收藏+]

标签:address   master   The   bat   seq   广播   chain   数值   script   

OSPF

OSPF(Open Shortest Path First,开放式最短路径优先)是基于链路状态的内部网关协议。OSPF具有收敛快、路由无环、扩展性好等优点。链路状态算法路由协议互相通告的是链路状态信息,每台路由器都将自己的链路状态信息(包含接口的IP地址和子网掩码、网络类型、该链路的开销等)发送给其他路由器,并在网络中泛洪,当每台路由器收集到网络内所有链路状态信息后,就能拥有整个网络的拓扑情况,然后根据整网拓扑情况运行SPF算法,得出所有网段的最短路径。

OSPF单区域

技术图片

基础配置

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

R2

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

R3

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

配置OSPF单区域

在三个路由器的区域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

检查OSPF接口通告

[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

检查OSPF邻居状态

[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 ]?

查看ospf路由表

[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多区域

OSPF协议可以将整个自治系统化为不同的区域(Area)。链路状态信息只在区域内部泛洪,区域之间传递的只是路由条目而非链路状态信息;区域0是骨干区域,骨干区域负责在非骨干区域之间发布区域间的路由信息。在一个OSPF区域中有且只有一个骨干区域,非骨干区域必须和骨干区域相连,且非骨干区域之间不能直接进行路由信息交互。
技术图片

Al-backbone与As-backbone为区域边界路由器

多区域配置

Al-backbone

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-core1

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认证

OSPF报文验证功能,通过验证的报文才能接受

OSPF协议的两种认证方式

1. 区域认证:区域内所有路由器(三层交换机)的认证模式和口令必须一致
2. 链路认证:针对某个邻居设置单独的认证模式和密码。同时配置了两种,则链路认证优先

每种认证方式的三种验证模式

1. 简单验证模式:明文传输
2. MD5验证模式:md5加密传输
3. Key chain验证模式:同时配置多个密钥,不同密钥单独设置生效周期

配置OSPF区域1明文认证(实验环境同多区域配置)

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

配置OSPF区域2秘文认证(实验环境同多区域配置)

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

更改OSPF区域1为md5认证(实验环境同多区域配置)

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

配置OSPF链路认证

[Huawei]interface GigabitEthernet0/0/1
三层交换机需先清除以太网接口二层配置并开启三层功能
[Huawei-GigabitEthernet0/0/1]undo portswitch
[Huawei-GigabitEthernet0/0/1]ospf authentication-mode md5 1 huawei

OSPF被动接口

被动接口也称抑制接口,成为被动接口后,将不会接收和发送OSPF报文。一般配置连接pc的接口为被动接口

被动接口配置(实验环境同多区域配置)

[al-core1-ospf-1]silent-interface GigabitEthernet 0/0/2

OSPF Router-ID

OSPF使用Router-ID作为路由器的身份标识,如果在启动ospf时没有指定Router-ID,则OSPF无法正常启动。例如,路由器(三层交换机)上未配置任何ip地址。

Router-ID选举规则

Router-ID命令配置 --> 最大的loopback接口ip地址 --> 最大的其他接口ip地址(不考虑up/down情况)
只有配选为Router-ID的接口ip地址被删除/修改,才触发重新选择过程。Router-ID改变之后,需手动reset ospf协议。

手动配置Router-ID

[al-backbone]router id 1.1.1.1
<al-backbone>reset ospf process?

查看Router-ID

<al-backbone>dis router id
RouterID:1.1.1.1

OSPF的DR与BDR

DR(指定路由器):所有的路由器都只将各自的链路状态信息发送给DR,再由DR以组播方式发送至所有路由器。
BDR(备份指定路由器):当DR由于故障失效时,BDR成为DR,并在选择新的BDR路由器。
DR Other(其他路由器):非DR与BDR的路由器

DR选举规则

比较优先级,优先级高的为DR,次高的为BDR
比较Router-ID,数值高的为DR,次高的为BDR

Notes:DR选举针对接口,DR选举是非抢占的。

手动配置接口ospf优先级

三层交换机需先清除以太网接口二层配置并开启三层功能

[Huawei-GigabitEthernet0/0/1]undo portswitch
[Huawei-GigabitEthernet0/0/1]ospf dr-priority 10

后续处理

改变优先级后,可以利用下面两种方法重新进行DR/BDR的选择,但是这会导致路由器(三层交换机)之间的OSPF邻接关系中断,一般情况下不推荐使用

  1. 重启所有路由器(三层交换机)
  2. 在建立了OSPF邻居的接口上执行shutdown/undo shutdown命令

OSPF协议优先级修改

当路由器或交换机上同时存在多种路由协议的时候,系统为每一种路由协议设置了不同的默认优先级,当在不同协议中发现同一条路由时,协议优先级高的将被优选。

修改OSPF协议优先级

[al-backbone]ospf
[al-backbone-ospf-1]preference 200

OSPF开销值修改

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计时器修改

在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

NA西游第五难:OSPF基础配置

标签:address   master   The   bat   seq   广播   chain   数值   script   

原文地址:https://blog.51cto.com/jiayimeng/2449856

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!