溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

實(shí)驗(yàn)設(shè)計(jì)與排錯(cuò)之四OSPF配置、分析與排錯(cuò)

發(fā)布時(shí)間:2020-06-20 01:40:16 來(lái)源:網(wǎng)絡(luò) 閱讀:2362 作者:deshen_feng 欄目:網(wǎng)絡(luò)安全

    1OSPF協(xié)議簡(jiǎn)述

OSPF(開放最短路徑優(yōu)先)是一種內(nèi)部網(wǎng)關(guān)協(xié)議。不同于IGRP,OSPF是一種無(wú)類鏈路狀態(tài)路由選擇協(xié)議,而不是一種分類距離矢量協(xié)議。OSPF被標(biāo)準(zhǔn)化,廣泛用于公共和私有網(wǎng)絡(luò)中。下面簡(jiǎn)單介紹一下鏈路狀態(tài)路由協(xié)議工作過(guò)程,如下:

  • 每臺(tái)路由器學(xué)習(xí)激活的直接相連的網(wǎng)絡(luò)。

  • 每臺(tái)路由器和直接相連的路由器互交,發(fā)送Hello報(bào)文,建立鄰居關(guān)系。

  • 每臺(tái)路由器構(gòu)建包含直接相連的鏈路狀態(tài)的LSA(Link-State Advertisement,鏈路狀態(tài)通告)。鏈路狀態(tài)通告(LSA)中記錄了所有相關(guān)的路由器,包括鄰路由器的標(biāo)識(shí)、鏈路類型、帶寬等。

  • 每臺(tái)路由器泛洪鏈路狀態(tài)通告(LSA)給所有的鄰路由器,并且自己也在本地儲(chǔ)存鄰路由發(fā)過(guò)來(lái)的LSA,然后再將收到的LSA泛洪給自己的所有鄰居,直到在同一區(qū)域中的所有路由器收到了所有的LSA。每臺(tái)路由器在本地?cái)?shù)據(jù)庫(kù)中保存所有收到的LSA副本,這個(gè)數(shù)據(jù)庫(kù)被稱作“鏈路狀態(tài)數(shù)據(jù)庫(kù)(LSDB,Link-State Database)”

  • 每臺(tái)路由器基于本地的“鏈路狀態(tài)數(shù)據(jù)庫(kù)(LSDB)”然后執(zhí)行“最短路徑優(yōu)先(SPF)”算法,并以本路由器為根,生成一個(gè)SPF樹,基于這個(gè)SPF樹計(jì)算去往每個(gè)網(wǎng)絡(luò)的最短路徑,也就得到了最終的路由表。

    2、實(shí)驗(yàn)?zāi)康?/span>

簡(jiǎn)單理解OSPF以下二個(gè)基礎(chǔ)知識(shí)點(diǎn)。

  • 理解鄰居表、拓?fù)浔硪约奥酚杀恚?/span>

  • OSPF如何選舉RID?

  • OSPF度量值的計(jì)算方法;

    3、實(shí)驗(yàn)拓?fù)?/span>

說(shuō)明:默認(rèn)沒(méi)有R1到R3的快速以太網(wǎng)鏈路,此鏈路將在后面實(shí)驗(yàn)OPSF度量值的計(jì)算方法上使用)

實(shí)驗(yàn)設(shè)計(jì)與排錯(cuò)之四OSPF配置、分析與排錯(cuò)

1)、路由表

R2#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

 

10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks

O              10.2.0.2/32 [110/65] via 192.168.10.2, 00:04:11, Serial1/1

O              10.5.0.2/32 [110/65] via 192.168.20.2, 00:02:21, Serial1/0

C               10.6.0.0/16 is directly connected, Loopback0

O              10.11.0.2/32 [110/65] via 192.168.50.2, 00:00:31, Serial1/3

O              10.12.0.2/32 [110/65] via 192.168.40.2, 00:01:26, Serial1/2

192.168.10.0/30 is subnetted, 1 subnets

C               192.168.10.0 is directly connected, Serial1/1

192.168.20.0/30 is subnetted, 1 subnets

C               192.168.20.0 is directly connected, Serial1/0

192.168.30.0/30 is subnetted, 1 subnets

O              192.168.30.0 [110/128] via 192.168.40.2, 00:00:31, Serial1/2

[110/128] via 192.168.50.2, 00:00:31, Serial1/3

192.168.40.0/30 is subnetted, 1 subnets

C               192.168.40.0 is directly connected, Serial1/2

192.168.50.0/30 is subnetted, 1 subnets

C               192.168.50.0 is directly connected, Serial1/3

如上面紅色部分,在OSPF中所有的回環(huán)接口都被自動(dòng)宣告成32位的主機(jī)路由“/32”,如果想顯示回環(huán)接口的實(shí)際子網(wǎng)掩碼,可以在回環(huán)端口上使用下面的命令:

Ip ospf network point-to-point

我們來(lái)看看實(shí)際的結(jié)果,當(dāng)在R1、R2上的loopback0端口輸入此命令后如下顯示:

R2#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

 

10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks

O              10.2.0.0/16 [110/65] via 192.168.10.2, 00:00:11, Serial1/1

O              10.5.0.2/32 [110/65] via 192.168.20.2, 00:36:53, Serial1/0

C               10.6.0.0/16 is directly connected, Loopback0

O              10.11.0.2/32 [110/65] via 192.168.50.2, 00:35:03, Serial1/3

O              10.12.0.2/32 [110/65] via 192.168.40.2, 00:35:57, Serial1/2

-----------

R1#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

 

10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks

C               10.2.0.0/16 is directly connected, Loopback0

O              10.5.0.2/32 [110/129] via 192.168.10.1, 00:36:39, Serial0/0

O              10.6.0.0/16 [110/65] via 192.168.10.1, 00:00:38, Serial0/0

O              10.11.0.2/32 [110/129] via 192.168.10.1, 00:34:49, Serial0/0

O              10.12.0.2/32 [110/129] via 192.168.10.1, 00:35:48, Serial0/0

-----------

2)、鄰居表

R2#show ip ospf neighbor

 

Neighbor ID             Pri            State                 Dead Time      Address                     Interface

10.5.0.2                    0               FULL/ -              00:00:34          192.168.20.2           Serial1/0

10.2.0.2                    0               FULL/ -              00:00:31          192.168.10.2           Serial1/1

10.12.0.2                  0               FULL/ -              00:00:34          192.168.40.2           Serial1/2

10.11.0.2                  0               FULL/ -              00:00:33          192.168.50.2           Serial1/3

Neighbor ID:鄰居的RID,通過(guò)上面的輸出可以看到R3的RID是10.5.0.2,R1的RID是10.2.0.2,R5的RID是10.12.0.2和R4的RID是10.11.0.2,分別從不同的接口建立了鄰居關(guān)系。

Pir: OSPF鄰居接口的優(yōu)先級(jí),接口優(yōu)先級(jí)用于DR和BDR的選舉,以太網(wǎng)接口的默認(rèn)優(yōu)先級(jí)是1,串行線路不需要選舉DR和BDR,所以串行線路的優(yōu)先級(jí)是0,即0代表不參與選舉。

State:鄰居路由器的狀態(tài),F(xiàn)ULL代表已經(jīng)建立鄰接關(guān)系,“/”后面是選舉的DR或BDR標(biāo)識(shí),因?yàn)榇芯€路不需要選舉,所以是“-”。

Dead time: 默認(rèn)的死亡時(shí)間是hello時(shí)間的4倍,即40秒。死亡時(shí)間是一個(gè)倒計(jì)時(shí),計(jì)時(shí)器為0時(shí),該鄰居被刪除。

Address: 鄰居直連接口的IP地址。

Interface: 本路由的輸出接口。

3)、拓?fù)浔?/span>

R2#show ip ospf database

OSPF Router with ID (10.6.0.2) (Process ID 1)

 

Router Link States (Area 0)

 

Link ID              ADV Router              Age         Seq#                           Checksum       Link count

10.6.0.2           10.6.0.2                    54             0x8000000c             0x00997e        9

10.5.0.2           10.5.0.2                    393          0x80000005             0x00650d        3

10.12.0.2         10.12.0.2                  299          0x80000007             0x0099d6        5

10.11.0.2         10.11.0.2                  285          0x80000007             0x004419        5

10.2.0.2           10.2.0.2                    19             0x80000006             0x00a5ea        3

4)、OSPF如何選舉Router ID?

Router ID簡(jiǎn)稱RID,用來(lái)唯一標(biāo)示OSPF網(wǎng)絡(luò)中的每一臺(tái)路由器。如果兩條OSPF路由器的RID一樣,彼此間無(wú)法建立鄰接關(guān)系。RID是以IP地址的形式出現(xiàn)的,那么RID的選舉順序是什么?我們先來(lái)看看R1的RID:

R1#show ip protocols

 

Routing Protocol is "ospf 1"

Outgoing update filter list for all interfaces is not set

Incoming update filter list for all interfaces is not set

Router ID 10.2.0.2      

Number of areas in this router is 1. 1 normal 0 stub 0 nssa

Maximum path: 4

Routing for Networks:

192.168.10.0 0.0.0.255 area 0

0.0.0.0 255.255.255.255 area 0

Routing Information Sources:

Gateway Distance Last Update

10.2.0.2 110 00:07:07

10.5.0.2 110 00:13:21

10.6.0.2 110 00:07:43

10.11.0.2 110 00:11:34

10.12.0.2 110 00:11:48

Distance: (default is 110)

下面我們來(lái)手工配置一下R1Router ID:

R1#conf t

Enter configuration commands, one per line. End with CNTL/Z.

R1(config)#route ospf 1

A.B.C.D OSPF router-id in IP address format

R1(config-router)#route 20.20.20.20     

R1(config-router)#Reload or use "clear ip ospf process" command, for this to take effect

 

R1(config-router)#end

R1#

%SYS-5-CONFIG_I: Configured from console by console

 

R1#clear ip ospf process         

Reset ALL OSPF processes? [no]: y

 

R1#

01:24:01: %OSPF-5-ADJCHG: Process 1, Nbr 10.6.0.2 on Serial0/0 from FULL to DOWN, Neighbor Down: Adjacency forced to reset

 

01:24:01: %OSPF-5-ADJCHG: Process 1, Nbr 10.6.0.2 on Serial0/0 from FULL to DOWN, Neighbor Down: Interface down or detached

 

01:24:05: %OSPF-5-ADJCHG: Process 1, Nbr 10.6.0.2 on Serial0/0 from LOADING to FULL, Loading Done

我們?cè)賮?lái)查看一下Route ID是什么情況:

R1#show ip protocols

 

Routing Protocol is "ospf 1"

Outgoing update filter list for all interfaces is not set

Incoming update filter list for all interfaces is not set

Router ID 20.20.20.20

Number of areas in this router is 1. 1 normal 0 stub 0 nssa

----------

從上面的例子中,我們看到RID可以是一個(gè)并不存在的IP地址,RID僅僅作為路由的標(biāo)識(shí),不會(huì)用于尋址。

另我們需要想一個(gè)問(wèn)題,那就是如果取消R1的手動(dòng)配置RID,并且關(guān)閉loopback0接口,這個(gè)時(shí)候最大的已激活回環(huán)接口IP應(yīng)該是什么?同樣我們來(lái)看看實(shí)驗(yàn):

R1#conf t

Enter configuration commands, one per line. End with CNTL/Z.

R1(config)#route ospf 1

R1(config-router)#no route 20.20.20.20         

R1(config-router)#int loopback0

R1(config-if)#shutdown           

R1(config-if)#

%LINK-5-CHANGED: Interface Loopback0, changed state to administratively down

 

%LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback0, changed state to down

 

R1(config-if)#end

R1#

%SYS-5-CONFIG_I: Configured from console by console

 

R1#clear ip ospf process

Reset ALL OSPF processes? [no]: y

 

R1#

01:36:48: %OSPF-5-ADJCHG: Process 1, Nbr 10.6.0.2 on Serial0/0 from FULL to DOWN, Neighbor Down: Adjacency forced to reset

 

01:36:48: %OSPF-5-ADJCHG: Process 1, Nbr 10.6.0.2 on Serial0/0 from FULL to DOWN, Neighbor Down: Interface down or detached

 

R1#show ip protocols

 

Routing Protocol is "ospf 1"

Outgoing update filter list for all interfaces is not set

Incoming update filter list for all interfaces is not set

Router ID 192.168.10.2 

Number of areas in this router is 1. 1 normal 0 stub 0 nssa

Maximum path: 4

Routing for Networks:

192.168.10.0 0.0.0.255 area 0

0.0.0.0 255.255.255.255 area 0

Routing Information Sources:

Gateway Distance Last Update

Distance: (default is 110)

         R1#

01:36:56: %OSPF-5-ADJCHG: Process 1, Nbr 10.6.0.2 on Serial0/0 from LOADING to FULL, Loading Done

如上實(shí)例說(shuō)明一個(gè)問(wèn)題,若沒(méi)有手動(dòng)指定RID,路由器默認(rèn)使用最大已激活的回環(huán)接口IP作為RID,但這里要注意的是最大并不是接口號(hào)最大,而是IP地址最大。還有一個(gè)問(wèn)題就是如果路由器沒(méi)有激活的回環(huán)接口,路由器默認(rèn)會(huì)選擇最大激活的物理接口的IP地址作為RID,如上則選擇的是物理接口192.168.10.2。

5)、OSPF度量值如何計(jì)算?

OSPF中使用的度量值是“花費(fèi)(Cost)”,默認(rèn)OSPF使用100Mb/s作為參考帶寬,使用100Mb/s除以實(shí)際鏈路帶寬,得出的值取整(對(duì)于小于0的結(jié)果,取1),就是花費(fèi)。

比如串行線路的帶寬是1.544M,快速以太網(wǎng)的帶寬是100M,即如下:

串行線路的花費(fèi)=100M/1.544≈64(取整,且不四舍五入)

快速以太網(wǎng)線路花費(fèi)=100M/100M=1

繼續(xù)上面的實(shí)驗(yàn),同時(shí)我們?cè)赗1和R3中新增一條快速以太網(wǎng)鏈路,然后做相應(yīng)的配置,再看看其R3的驗(yàn)證:

R3#show ip route ospf

10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks

O              10.2.0.0 [110/2] via 172.16.50.1, 00:00:15, FastEthernet0/0

O              10.6.0.0 [110/65] via 192.168.20.1, 00:10:00, Serial0/3

O              10.11.0.2 [110/129] via 192.168.20.1, 00:10:00, Serial0/3

O              10.12.0.2 [110/129] via 192.168.20.1, 00:10:00, Serial0/3

192.168.10.0/30 is subnetted, 1 subnets

O              192.168.10.0 [110/65] via 172.16.50.1, 00:00:15, FastEthernet0/0

192.168.30.0/30 is subnetted, 1 subnets

O              192.168.30.0 [110/192] via 192.168.20.1, 00:10:00, Serial0/3

192.168.40.0/30 is subnetted, 1 subnets

O              192.168.40.0 [110/128] via 192.168.20.1, 00:10:00, Serial0/3

192.168.50.0/30 is subnetted, 1 subnets

O              192.168.50.0 [110/128] via 192.168.20.1, 00:10:00, Serial0/3

我們可以看到[110/2],110是OSPF的默認(rèn)管理距離,2是花費(fèi),去往10.2.0.0/16的花費(fèi)是2,就是快速以太網(wǎng)的花費(fèi)加上回環(huán)接口的花費(fèi),因?yàn)榛丨h(huán)接口的帶寬非常高,用100M去除會(huì)小于0,所以取1。另外192.168.10.0 [110/65]的65是通過(guò)串行線路花費(fèi)64,加上以太網(wǎng)花費(fèi)1得到的。

現(xiàn)在我們關(guān)閉R3的快速以及網(wǎng)接口,再看看R3的路由表:

R3(config)#int fa0/0

R3(config-if)#shutdown

 

R3(config-if)#

%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to administratively down

 

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to down

 

00:17:25: %OSPF-5-ADJCHG: Process 1, Nbr 10.2.0.2 on FastEthernet0/0 from FULL to DOWN, Neighbor Down: Interface down or detached

end

R3#

%SYS-5-CONFIG_I: Configured from console by console

 

R3#show ip route ospf

10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks

O              10.2.0.0 [110/129] via 192.168.20.1, 00:00:01, Serial0/3

O              10.6.0.0 [110/65] via 192.168.20.1, 00:17:06, Serial0/3

O              10.11.0.2 [110/129] via 192.168.20.1, 00:17:06, Serial0/3

O              10.12.0.2 [110/129] via 192.168.20.1, 00:17:06, Serial0/3

192.168.10.0/30 is subnetted, 1 subnets

O              192.168.10.0 [110/128] via 192.168.20.1, 00:00:01, Serial0/3

192.168.30.0/30 is subnetted, 1 subnets

O              192.168.30.0 [110/192] via 192.168.20.1, 00:17:06, Serial0/3

192.168.40.0/30 is subnetted, 1 subnets

O              192.168.40.0 [110/128] via 192.168.20.1, 00:17:06, Serial0/3

192.168.50.0/30 is subnetted, 1 subnets

O              192.168.50.0 [110/128] via 192.168.20.1, 00:17:06, Serial0/3

此時(shí)會(huì)發(fā)現(xiàn)數(shù)據(jù)都要經(jīng)過(guò)串行線路,并且花費(fèi)變成了129。而192.168.10.0 [110/128]也變成了128。其實(shí)可以通過(guò)下面的方法修改計(jì)算花費(fèi)的參考帶寬:

R3(config)#route ospf 1

R3(config-router)#auto-cost

R3(config-router)#auto-cost reference-bandwidth 10000     

% OSPF: Reference bandwidth is changed.

Please ensure reference bandwidth is consistent across all routers.   

R3(config-router)#end

R3#

%SYS-5-CONFIG_I: Configured from console by console

當(dāng)修改了所有路由器的參考帶寬后,再看看R3的路由表:

R3#show ip route ospf

10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks

O              10.2.0.0 [110/12953] via 192.168.20.1, 00:00:28, Serial0/3

O              10.6.0.0 [110/6477] via 192.168.20.1, 00:02:42, Serial0/3

O              10.11.0.2 [110/12953] via 192.168.20.1, 00:00:28, Serial0/3

O              10.12.0.2 [110/12953] via 192.168.20.1, 00:00:28, Serial0/3

O              172.16.0.0 [110/13052] via 192.168.20.1, 00:00:28, Serial0/3

192.168.10.0/30 is subnetted, 1 subnets

O              192.168.10.0 [110/12952] via 192.168.20.1, 00:00:28, Serial0/3

192.168.30.0/30 is subnetted, 1 subnets

O              192.168.30.0 [110/19428] via 192.168.20.1, 00:00:18, Serial0/3

192.168.40.0/30 is subnetted, 1 subnets

O              192.168.40.0 [110/12952] via 192.168.20.1, 00:00:28, Serial0/3

192.168.50.0/30 is subnetted, 1 subnets

O              192.168.50.0 [110/12952] via 192.168.20.1, 00:00:28, Serial0/3

同樣用去往10.2.0.0/16網(wǎng)絡(luò)的12953舉例計(jì)算花費(fèi)如下:

         R3和R2相連的串行鏈路花費(fèi)=10000M/1.544M≈6476

    R2和R1相連的串行鏈路花費(fèi)=10000M/1.544M≈6476

    R1上的loopback0接口的花費(fèi)=10000M/8000M≈1

    三條線路花費(fèi)綜合即為12953,另其它端口花費(fèi)同樣計(jì)算。

最后可以通過(guò)下面方法查看某接口的OSPF信息:

R3#show ip ospf int se0/3

 

Serial0/3 is up, line protocol is up

Internet address is 192.168.20.2/30, Area 0

Process ID 1, Router ID 10.5.0.2, Network Type POINT-TO-POINT, Cost: 6476

Transmit Delay is 1 sec, State POINT-TO-POINT, Priority 0

No designated router on this network

No backup designated router on this network

Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5

Hello due in 00:00:01

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 0 msec

Neighbor Count is 1 , Adjacent neighbor count is 1

Adjacent with neighbor 10.6.0.2

Suppress hello for 0 neighbor(s)

 

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI