OSPF_CISCO

概述

IGP路由协议,链路状态路由协议;无类协议;

OSI模型中:传输层协议:封装在ip协议内,协议号88

三张表

邻居表:

拓扑表:LSDB,同一区域内的路由器LSDB信息一致

路由表:

区域划分

  • 区域划分是基于接口的

  • 减少了路由表路由条目的数量(路由汇总:ABR和ASBR),域间传递路由信息

  • 拓扑发生变化时,影响限制在区域内部;

  • 特定的LSA只能在区域内传播,不同的LSA传播范围不一样;泛洪传播

DR、BDR

  • DR和BDR建立邻接(full)
  • DR和BDR与Dother建立邻接(full)
  • Dother建立邻居关系(2-way)

先比较优先级(越大越好,1-255,0表示不参与选举),再比较router-id,次优为BDR

ospf报文

  • hello报文:间隔10s,hold:40s;或者间隔30s,hold:120s

  • DBD报文:交换LSDB;隐式确认:用相同的报文来确认,是基于序列号的确认;

  • LSR报文:请求没有的LSA头部

  • LSU报文:回复LSR,包含完整的LSA

  • LSACK报文:确认LSU

 

 

 ospf状态机

1. DOWN:初始状态,接口被宣告进ospf,没有发送任何报文
2. init:通过接口发送一个hello报文
3. two-way:通过接口收到一份enighbor字段,包含自身RID的hello报文
4. Exstart:交互3个不带LSA报头的DBD选择master/slava;mtu不一致会处于exstart状态;
5. Exchange:由master发起的带有LSA报头的DBD信息交互
6. Loading:交互LSR、LSU以及LSAck实现LSDN的同步
7. Full:一旦LSDB同步,邻接关系到达Full

建立邻居条件

  • 相同的hello和dead时间

  • 直连接口属于相同的区域

  • 使用相同的认证类型和秘钥

  • 相同的特殊类型

  • 相同的mtu

  • 相同的网络类型

ospf配置

router ospf 1
 router-id 1.1.1.1
 network 1.1.1.1 0.0.0.0 area 1
 network 12.1.1.1 0.0.0.0 area 1

查看命令

R1#show ip ospf neighbor           #查看邻居信息

Neighbor ID     Pri   State           Dead Time   Address         Interface
2.2.2.2           1   FULL/DR         00:00:34    12.1.1.2        Ethernet0/0

  

show ip ospf neighbor  detail    #查看邻居详细信息
show ip protocols        #查看协议信息
show ip ospf             #查看协议信息
show ip ospf interface   #查看ospf协议的接口信息
show ip ospf border-routers    #查看邻居路由器的角色(ABR、ASBR)

  

show ip ospf interface brief           #查看ospf接口简洁信息
Interface    PID   Area            IP Address/Mask    Cost  State Nbrs F/C
Lo0          1     1               1.1.1.1/24         1     LOOP  0/0
Et0/0        1     1               12.1.1.1/24        10    BDR   1/1

修改mtu,使在exstart状态:

interface Ethernet0/0
 ip mtu 1492
show ip ospf neighbor 
Neighbor ID     Pri   State           Dead Time   Address         Interface
2.2.2.2           1   EXSTART/DR      00:00:36    12.1.1.2        Ethernet0/0
interface Ethernet0/0
 ip ospf mtu-ignore             #忽视mtu值的影响,两边随便在哪边执行都可以

修改ospf的hello间隔,默认为10s(广播和p2p),NABA和p2mp为30s

interface Ethernet0/0
 ip ospf hello-interval 12
show ip ospf interface e0/0          #查看ospf接口的信息
  • hello时间改了之后,dead时间自动改为hello的四倍;
  • dead时间修改之后,hello时间没法自动修改

把lo口当成一个网段

 interface Loopback0
  ip ospf network point-to-point				#修改ospf的网络类型

修改ospf的接口优先级以选举DR/BDR(MA网络)

interface Ethernet0/0
 ip ospf priority 10                #值越大越优

优先级为0,表示该接口不参与DR/BDR选举

 

区域划分建立

  • 每台路由器属于的区域不超过3个
  • 每个区域内路由器数量50个以内
  • 对于一台运行ospf路由器,邻接关系不超过60个

LSA概述

LSA更新周期30min,老化时间60min

  • LSA1:Router LSA
    • 传播范围:只能在一个area内传递,不能穿越ABR
    • 通告者:每台属于一个区域的路由器都会基于该区域通告一条1类LSA
    • 包含内容:拓扑信息,其中描述该路由器所有宣告进该区域的链路的前缀,掩码,网络类型以及度量值
    • Link-ID:通过该LAS的路由器的RID
    • ADV Router:通过该LSA的路由器的RID
show ip ospf database router           #一类LSA查看方法
  • LSA2:Network LSA
    • 传播范围:只能在一个area内传递,不能穿越ABR
    • 通告者:MA网络中的DR
    • 包含内容:纯拓扑信息,包含了该MA网段直连的所有路由器的RID信息,该MA网段的掩码长度(router-id)
    • Link-ID:该MA网段DR接口的IP地址
    • ADV Router:该DR的RID.
show ip ospf database  network 
  • LSA3:Summary Network LSA
    • 传播范围:除了该区域外的整个ospf路由选择域
    • 通告者:ABR
    • 包含内容:一条3类LSA包含一条OSPF域间路由,O IA
    • Link-ID:3类LSA路由的前缀
    • ADV Router:ABR的RID,3类LSA在OSPF路由选择域内传递的时候为了保证可达性每跨越一个ABR都会自动改写为该ABR的RID;
show ip ospf database summary 
  • LSA5:External LSA
  •  
    • 传递范围:整个ospf路由选择域

    • 通告者:ASBR

    • 包含内容:纯路由信息,一条ospf域外路由对应一条5类LSA

    • Link-ID:域外路由的路由前缀

    • ADV Router:ASBR的RID,该LSA在OSPF域内传递的时候,ADV Router不会发生任何改变;

show ip ospf database external
  • LSA4:Summary ASB LSA
    • 传递范围:除了ASBR所在区域之外的整个路由选择域
    • 通告者:和ASBR在同一个区域的ABR路由

    • 包含内容:纯拓扑信息,描述了ASBR所在位置

    • Link-ID:ASBR的RID

    • ADV Rrouter:通告者ABR的RID,并且该值每跨越一个ABR都会自动改变,同3类LSA

域外路由

(O E2情况下)Seed Metric:种子度量值,对于OSPF而言如果将BGP路由重发布进入,则Seed Metric默认为1,所有其他外部路由缺省Seed Metic是20;

ospf引入路由类型:

OE2度量值=种子度量值

OE1度量值=种子度量值+OSPF域内每一跳入接口带宽

router eigrp 100
 redistribute eigrp 100 metric-type 1 subnets            #修改引入外部路由的类型
 summary-address 192.168.8.0 255.255.252.0
#
router eigrp 100
 redistribute rip subnets metric 30								#引入外部路由的seed metric为30

ospf路由优先级

域内O > 域间O IA > 域外 O E1/E2 = 七类外部 O N1/N2

 

ospf特性

ospf路由汇总

  • 域间汇总:需要在ABR上部署,实现对3类LSA的汇总传递
  • 域外汇总:需要在ASBR上部署,实现对5类LSA的汇总传递

域间汇总:

 

 

R1(config-router)#area 0 range 172.16.8.0 255.255.252.0 ?
  advertise      Advertise this range (default)
  cost           User specified metric for this range
  not-advertise  DoNotAdvertise this range               #不通告汇总的路由(域间过滤)
  <cr>
#该路由在哪个区域发布的在哪个区域聚合。例如在R1的area0聚合后,area2的R4收到的是聚合后的路由,R2和R3还是明细路由,因为R2会将3类LSA发给R3,故域间汇总最好在该网段发布的区域的所有ABR上都操作。

 

域外汇总:

 

 

router eigrp 100
 redistribute eigrp 100 metric-type 1 subnets
 summary-address 192.168.8.0 255.255.252.0
#
R3(config-router)#summary-address 192.168.8.0 255.255.252.0 ?
  not-advertise  Do not advertise or translate    #汇总不发布,明细和汇总都过滤
  nssa-only      Limit summary to NSSA areas
  tag            Set tag
  <cr>

域间路由过滤:

ip prefix-list 10 seq 10 deny 172.16.8.0/23 ge 24 le 24
ip prefix-list 10 seq 20 permit 0.0.0.0/0 le 32
router ospf 100
 area 0 filter-list prefix 10 out
#在R1的area0的出反向过滤两条(8.0和9.0)路由,R4的area2上只能收到两条(10.0/11.0);也可在R1的area2的入方向引用(area 2 filter-list prefix 10 in );

 

OSPF向正常区域下发默认路由:

 

 默认下发的是第二类外部默认路由:可以通过metic-type=E2修改;

default-information originate [always] [metric metric-value] [metric-type type-value] [route-map map-name]
  • 如果ASBR在其路由表中已经有默认路由,使用default-information originate router configuration 命令,将现有的0.0.0.0/0通告到ospf域内。
  • 如果ASBR没有默认路由,使用default-information originate always;不管本地是否存在0.0.0.0/0都会通过默认路由到ospf域内;

 

LSDB过载保护(IOS12.4以上):限制的是邻居发给该路由器LSA的数量

  • warning-only:只报警

  • ignore-time:报警的时间,报警完该时间后down邻居,down完后多长时间重新建立邻居

  • ignore-count:down邻居的次数

  • reset-time:down完邻居后,如果LSDB数量恢复正常,并保持reset-time时间,会对ignore-count次数的重置时间

 

修改ospf接口cost

ospf的cost算入接口:(100Mbps/带宽(Mbps))

interface Ethernet0/1
 ip ospf cost 90

修改ospf的参考带宽:默认100Mbps(10^8)

router ospf 100 
 auto-cost reference-bandwidth 10000

 

特殊区域

stub区域(末节区域)——过滤4/5类

  • * 建议stub区域只有一个ABR,防止出现次优路径
  • * 同区域内所有路由去都得是stub区域
  • * 该区域不能存在ASBR
  • * 该区域不能是区域0
  • * 该区域不能存在虚链路穿越

 

如果将一个OSPF区域部署为stub,该区域的ABR会将入区域方向的4/5类LSA同时过滤,同时该ABR会主动向区域内部注入一条O IA的0.0.0.0/0的3类缺省路由,Seed Metric为1;

R2:
router ospf 100
  area 1 stub						 #area1的所有路由都要设置为stub
  area 1 default-cost 30       #修改下发的三类路由的seed metric值

Totally stubby(完全末节区域) ——过滤3/4/5类

Totally Stub区域:在Stub区域的基础之上ABR路由会同时将3/4/5类入向传递的LSA过滤掉,同时会主动向该区域注入一条O IA的0.0.0.0/0的3类缺省路由,Seed Metric缺省为1;

R2:
router ospf 100
 area 1 stub no-summary         #末节区域的ABR上执行,其他的路由器执行stub区域

 

NSSA区域——过滤4/5类

  • 只要可以产生5类LSA的路由器就是ASBR

  • NSSA区域部署在存在ASBR的区域

  • NSSA区域的ASBR会将4/5类LSA转化为7类LSA在NSSA区域内传播,当传播到ABR时,ABR会将七类LSA转换为4/5类LSA传给其他区域,如果该区域有多个ABR,那么 router-id大的ABR成为转换者;

  • 当某个区域为NSSA区域时,该区域的ABR(R3)会阻止从其他地方重发布进OSPF的4/5类LSA(例如图中EIGRP),会导致NSSA内部其他的路由器无法到达从其他地方重发布的路由,故需在NSSA区域的ABR配置时加上default-information-originate参数(area 2 nssa default-information-originate),ABR会向NSSA区域注入一个七类O N2 0.0.0.0/0的缺省路由;

 

  •  当某个NSSA区域的某个路由器即是ABR又是ASBR时(例如R3),从该路由器重发布的路由会在NSSA区域以七类LSA的形式传播,为了更好的优化NSSA区域,可在该路由的NSSA区域后面加上no-redistribution参数(area 2 nssa no-redistribution default-information-originate),让从即是ABR又是ASBR重发布的路由(R3),在NSSA区域中消失;

 

  •  NSSA区域的路由经过ABR转发给其他区域的路由器时,forward address会置为ASBR的地址;为了优化NSSA区域ABR的性能,可以在ABR将该forward address设为0.0.0.0;
R3:
router ospf 100
 area 2 nssa no-redistribution default-information-originate
 area 2 nssa translate type7 suppress-fa            #forward address不改为ASBR的地址

 

Totally NSSA区域(完全NSSA区域)——过滤3/4/5类

 

 

  • 基于NSSA区域的概念基础,ABR会主动阻止3/4/5类LSA进入该区域,并且ABR会主动向区域内注入O IA 0.0.0.0/0 Seed Metric=1的缺省路由
R3:
router ospf 100
 area 2 nssa no-redistribution default-information-originate no-summary
#no-summary  NSSA区域的ABR过滤3类LSA,生成3类缺省注入
#default-information-originate   NSSA区域的ABR生成七类缺省注入

ospf不规则区域(虚连接)

  • 非骨干区域与骨干区域分隔

  • 骨干区域被分割

解决方案:

方法一:在出现问题的ABR上(没有和Area0直连的ABR),使用双OSPF进程,并且执行单点双向重分发

 

  •  在R4上起两个ospf进程,互相重发布
R4:
router ospf 100
 router-id 4.4.4.4
 redistribute ospf 99 subnets
 network 4.4.4.4 0.0.0.0 area 2
 network 34.1.1.4 0.0.0.0 area 2
router ospf 99
 router-id 94.4.4.4
 redistribute ospf 100 subnets
 network 45.1.1.4 0.0.0.0 area 3

方法二:在出现问题的ABR上建立一个Tunnel链路连接到离其最近的area 0 中的ABR路由器上,在这两台ABR上对Tunnel配置IP地址为同一个IP子网段,并且将其宣告进OSPF的区域0;

R3:
interface Tunnel3
 ip address 43.1.1.3 255.255.255.0
 tunnel source 3.3.3.3
 tunnel destination 4.4.4.4
#
router ospf 100
 router-id 3.3.3.3
 network 23.1.1.3 0.0.0.0 area 0
 network 34.1.1.3 0.0.0.0 area 2
 network 43.1.1.3 0.0.0.0 area 0           #将tunnel口ip发布到ospf的area0中
#
ip route 4.4.4.4 255.255.255.255 34.1.1.4         #防止tunnel频繁up/down,tunnel口的源目ip不能发布到IGP中,故增加静态路由

R4:
interface Tunnel4
 ip address 43.1.1.4 255.255.255.0
 tunnel source 4.4.4.4
 tunnel destination 3.3.3.3
#
router ospf 100
 router-id 4.4.4.4
 network 34.1.1.4 0.0.0.0 area 2
 network 43.1.1.4 0.0.0.0 area 0
 network 45.1.1.4 0.0.0.0 area 3
#
ip route 3.3.3.3 255.255.255.255 34.1.1.3

方法三:使用Virtual-Link在出问题的ABR以及离他最近的Area0的ABR上部署

  • 不能跨越骨干区域,不能跨越特殊区域
R3:
router ospf 100
 area 2 virtual-link 4.4.4.4          #需要穿越哪个区域就写哪个area
R4:
router ospf 100
 area 2 virtual-link 3.3.3.3
R4#show ip ospf virtual-links 
Virtual Link OSPF_VL1 to router 3.3.3.3 is up
  Run as demand circuit
  DoNotAge LSA allowed.
  Transit area 2, via interface Serial1/0
 Topology-MTID    Cost    Disabled     Shutdown      Topology Name
        0           64        no          no            Base
  Transmit Delay is 1 sec, State POINT_TO_POINT,
  Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
    Hello due in 00:00:07
    Adjacency State FULL (Hello suppressed)
    Index 1/3, retransmission queue length 0, number of retransmission 0
    First 0x0(0)/0x0(0) Next 0x0(0)/0x0(0)
    Last retransmission scan length is 0, maximum is 0
    Last retransmission scan time is 0 msec, maximum is 0 msec

ospf认证

链路级明文认证:

interface Serial1/0
 ip ospf authentication
 ip ospf authentication-key cisco

链路级密文认证:两边keyid必须一致

interface Serial1/1
 ip ospf authentication message-digest
 ip ospf message-digest-key 23 md5 cisco

区域级明文认证:若区域有vlink穿越,也会影响vlink的邻居

interface Serial1/1
 ip ospf authentication-key cisco
router ospf 100
 area 2 authentication

区域级密文认证:

interface Serial1/1
 ip ospf message-digest-key 45 md5 h3c
router ospf 100
 area 3 authentication message-digest

虚链路明文认证:(只有在VL初始化建立邻居的时候生效,因为VL抑制了Hello报文)

router ospf 100
 area 2 virtual-link 4.4.4.4 authentication
 area 2 virtual-link 4.4.4.4 authentication-key cisco

虚链路密文认证(只有在VL初始化建立邻居的时候生效,因为VL抑制了Hello报文)

router ospf 100
 area 2 virtual-link 3.3.3.3 authentication message-digest
 area 2 virtual-link 3.3.3.3 message-digest-key 43 md5 cisco

注意:当area0启用了区域级认证时,部署的虚链路也需要启用:例如上图area0启用区域认证,R3和R4的area2启用虚链路:

 

R1:
router ospf 100
 area 0 authentication message-digest
 area 2 virtual-link 4.4.4.4 message-digest-key 100 md5 cisco
R4:
router ospf 100
 area 0 authentication message-digest
 area 2 virtual-link 3.3.3.3 message-digest-key 100 md5 cisco

 

 

注意:当两台路由器即启用了接口级认证又启用了区域级认证,是可以同时配置的,但是接口级认证优先级高于区域级,故同时存在时,只需接口级认证配对正确,即可认证完成;

 

Ospf网络类型

  1. Loopback:无论接口掩码多少,都以/32主机路由通告

  2. Point-To-Point:Serial/ISDN BRI/帧中继点到点 支持组播,没有DR

  3. Broadcast:以太网接口 支持组播,有DR

  4. NBMA:(非广播)FR主接口/FR多点子接口,不支持组播,有DR,单播发送报文

  5. Point-To-Multipoint:支持组播,无DR         

  6. Point-To-Multipoint Non-Broadcast:不支持组播,没有DR; 

查看ospf的接口网络类型:

show ip ospf interface

 修改Loopback的ospf网络类型,以正常的掩码:

interface Loopback0
 ip ospf network point-to-point


R1#show ip ospf interface       
Loopback0 is up, line protocol is up 
  Internet Address 1.1.1.1/24, Area 0, Attached via Network Statement
  Process ID 100, Router ID 1.1.1.1, Network Type POINT_TO_POINT, Cost: 1
  Topology-MTID    Cost    Disabled    Shutdown      Topology Name
        0           1         no          no            Base
  Transmit Delay is 1 sec, State POINT_TO_POINT
  Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
    oob-resync timeout 40
  Supports Link-local Signaling (LLS)
  Cisco NSF helper support enabled
  IETF NSF helper support enabled
  Index 1/1, flood queue length 0
  Next 0x0(0)/0x0(0)
  Last flood scan length is 0, maximum is 0
  Last flood scan time is 0 msec, maximum is 0 msec
  Neighbor Count is 0, Adjacent neighbor count is 0 
  Suppress hello for 0 neighbor(s)
Serial1/0 is up, line protocol is up 
  Internet Address 12.1.1.1/24, Area 0, Attached via Network Statement
  Process ID 100, Router ID 1.1.1.1, Network Type POINT_TO_POINT, Cost: 64
  Topology-MTID    Cost    Disabled    Shutdown      Topology Name
        0           64        no          no            Base
  Transmit Delay is 1 sec, State POINT_TO_POINT
  Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
    oob-resync timeout 40
    Hello due in 00:00:02
  Supports Link-local Signaling (LLS)
  Cisco NSF helper support enabled
  IETF NSF helper support enabled
  Index 2/2, flood queue length 0
  Next 0x0(0)/0x0(0)
  Last flood scan length is 1, maximum is 1
  Last flood scan time is 0 msec, maximum is 1 msec
  Neighbor Count is 1, Adjacent neighbor count is 1 
    Adjacent with neighbor 2.2.2.2
  Suppress hello for 0 neighbor(s)

 

NBMA网络:

需要选DR/BDR;时间:Hello 30, Dead 120, Wait 120

R2:
interface Serial1/1
 ip address 12.1.1.2 255.255.255.0
 ip ospf network non-broadcast          #改为NAMA网络
 serial restart-delay 0
#
router ospf 100
 router-id 2.2.2.2
 network 2.2.2.2 0.0.0.0 area 0
 network 12.1.1.2 0.0.0.0 area 0

R1:
interface Serial1/0
ip address 12.1.1.1 255.255.255.0
ip ospf network non-broadcast
serial restart-delay 0
end
#
router ospf 100
 router-id 1.1.1.1
 network 1.1.1.1 0.0.0.0 area 0
 network 12.1.1.1 0.0.0.0 area 0
 neighbor 12.1.1.2                  #只需要在一端指定neighbor

 

Point-To-Multipoint网络:

支持组播,无DR,自动生成关于直连邻居接口/32的主机路由;Hello 30, Dead 120, Wait 120

R1:
interface Serial1/0
 ip address 12.1.1.1 255.255.255.0
 ip ospf network point-to-multipoint
 serial restart-delay 0

R2:
interface Serial1/1
 ip address 12.1.1.2 255.255.255.0
 ip ospf network point-to-multipoint
 serial restart-delay 0
R2#show ip route ospf
Codes: L - local, C - connected, S - static, 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
       i - IS-IS, su - IS-IS summary, 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, H - NHRP, l - LISP
       + - replicated route, % - next hop override

Gateway of last resort is not set

      1.0.0.0/24 is subnetted, 1 subnets
O        1.1.1.0 [110/65] via 12.1.1.1, 00:02:07, Serial1/1
      12.0.0.0/8 is variably subnetted, 3 subnets, 2 masks
O        12.1.1.1/32 [110/64] via 12.1.1.1, 00:02:07, Serial1/1

 

Point-To-Multipoint Non-Broadcast 网络:

不支持组播,没有DR,自动生成关于直连邻居接口/32的主机路由;Hello 30, Dead 120, Wait 120

R1:
interface Serial1/0
 ip address 12.1.1.1 255.255.255.0
 ip ospf network point-to-multipoint
 serial restart-delay 0
end
#
router ospf 100
 router-id 1.1.1.1
 network 1.1.1.1 0.0.0.0 area 0
 network 12.1.1.1 0.0.0.0 area 0
 neighbor 12.1.1.2          #只需在一边指定neighbor即可
#
R2:
interface Serial1/1
 ip address 12.1.1.2 255.255.255.0
 ip ospf network point-to-multipoint non-broadcast
 serial restart-delay 0
#
router ospf 100
 router-id 2.2.2.2
 network 2.2.2.2 0.0.0.0 area 0
 network 12.1.1.2 0.0.0.0 area 0

 

注意:例如网络类型中一边是P2P,一边是P2MP,邻居会建立失败,因为两边的hello时间不一致,修改P2P侧或者P2MP侧的ospf hello报文时间即可解决;

 

posted @ 2021-12-28 16:22  Day__Day_Up  阅读(35)  评论(0编辑  收藏  举报