新聞中心
OSPF開放式最短路徑優(yōu)先協(xié)議,是目前網(wǎng)絡(luò)中應(yīng)用最廣泛的路由協(xié)議之一。屬于內(nèi)部網(wǎng)關(guān)路由協(xié)議,能夠適應(yīng)各種規(guī)模的網(wǎng)絡(luò)環(huán)境,是典型的鏈路狀態(tài)協(xié)議,本篇文章重點為大家講解一下配置OSPF 動態(tài)路由具體方法。

為天心等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務(wù),及天心網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為成都做網(wǎng)站、成都網(wǎng)站設(shè)計、天心網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠(yuǎn)!
實驗?zāi)康?/h3>
掌握 OSPF 協(xié)議的配置方法 掌握查看通過動態(tài)路由協(xié)議 OSPF 學(xué)習(xí)產(chǎn)生的路由 熟悉廣域網(wǎng)線纜的鏈接方式
實驗背景
假設(shè)校園網(wǎng)通過一臺三層交換機連到校園網(wǎng)出口路由器上,路由器再和校園外的另一臺路由器連接。現(xiàn)要做適當(dāng)配置,實現(xiàn)校園網(wǎng)內(nèi)部主機與校園網(wǎng)外部主機之間的相互通信。為了簡化網(wǎng)管的管理維護(hù)工作,學(xué)校決定采用 OSPF 協(xié)議實現(xiàn)互通。
技術(shù)原理
OSPF(Open Shortest Path First) 開放式最短路徑優(yōu)先協(xié)議,是目前網(wǎng)路中應(yīng)用最廣泛的路由協(xié)議之一。屬于內(nèi)部網(wǎng)關(guān)路由協(xié)議,能夠適應(yīng)各種規(guī)模的網(wǎng)絡(luò)環(huán)境,是典型的鏈路狀態(tài)協(xié)議。OSPF路由協(xié)議通過向全網(wǎng)擴散本設(shè)備的鏈路狀態(tài)信息,使網(wǎng)絡(luò)中每臺設(shè)備最終同步一個具有全網(wǎng)鏈路狀態(tài)的數(shù)據(jù)庫,然后路由器采用 SPF 算法,以自己為根,計算到達(dá)其他網(wǎng)絡(luò)的最短路徑,最終形成全網(wǎng)路由信息。
OSPF(Open Shortest Path First)是一個內(nèi)部網(wǎng)關(guān)協(xié)議(Interior Gateway Protocol,簡稱IGP)。與RIP相對,OSPF是鏈路狀態(tài)路由協(xié)議,而RIP是距離向量路由協(xié)議。 鏈路是路由器接口的另一種說法,因此OSPF也稱為接口狀態(tài)路由協(xié)議。OSPF通過路由器之間通告網(wǎng)絡(luò)接口的狀態(tài)來建立鏈路狀態(tài)數(shù)據(jù)庫,生成最短路徑樹,每個OSPF路由器使用這些最短路徑構(gòu)造路由表。
基本概念和術(shù)語
鏈路狀態(tài)
OSPF路由器收集其所在網(wǎng)絡(luò)區(qū)域上各路由器的連接狀態(tài)信息,即鏈路狀態(tài)信息(Link-State),生成鏈路狀態(tài)數(shù)據(jù)庫(Link-State Database)。路由器掌握了該區(qū)域上所有路由器的鏈路狀態(tài)信息,也就等于了解了整個網(wǎng)絡(luò)的拓?fù)錉顩r。OSPF路由器利用“最短路徑優(yōu)先算法(Shortest Path First, SPF)”,獨立地計算出到達(dá)任意目的地的路由。
區(qū)域
OSPF協(xié)議引入“分層路由”的概念,將網(wǎng)絡(luò)分割成一個“主干”連接的一組相互獨立的部分,這些相互獨立的部分被稱為“區(qū)域”(Area),“主干”的部分稱為“主干區(qū)域”。每個區(qū)域就如同一個獨立的網(wǎng)絡(luò),該區(qū)域的OSPF路由器只保存該區(qū)域的鏈路狀態(tài)。每個路由器的鏈路狀態(tài)數(shù)據(jù)庫都可以保持合理的大小,路由計算的時間、報文數(shù)量都不會過大。
共有五種區(qū)域的主要區(qū)別在于它們和外部路由器間的關(guān)系:
標(biāo)準(zhǔn)區(qū)域: 一個標(biāo)準(zhǔn)區(qū)域可以接收鏈路更新信息和路由總結(jié)。
主干區(qū)域(傳遞區(qū)域):主干區(qū)域是連接各個區(qū)域的中心實體。主干區(qū)域始終是“區(qū)域0”,所有其他的區(qū)域都要連接到這個區(qū)域上交換路由信息。主干區(qū)域擁有標(biāo)準(zhǔn)區(qū)域的所有性質(zhì)。
存根區(qū)域(stub Area):存根區(qū)域是不接受自治系統(tǒng)以外的路由信息的區(qū)域。如果需要自治系統(tǒng)以外的路由,它使用默認(rèn)路由0.0.0.0。
完全存根區(qū)域:它不接受外部自治系統(tǒng)的路由以及自治系統(tǒng)內(nèi)其他區(qū)域的路由總結(jié)。需要發(fā)送到區(qū)域外的報文則使用默認(rèn)路由:0.0.0.0。完全存根區(qū)域是Cisco自己定義的。
不完全存根區(qū)域(NSAA): 它類似于存根區(qū)域,但是允許接收以LSA Type 7發(fā)送的外部路由信息,并且要把LSA Type 7轉(zhuǎn)換成LSA Type 5。
度量值cost(鏈路開銷)
OSPF的度量值cost(鏈路開銷)它是根據(jù)鏈路帶寬算出來的。基本上是和鏈路帶寬成反比。也就是說帶寬越大,開銷值越小,鏈路越優(yōu)。計算公式為: 接口開銷=參考帶寬/邏輯帶寬 (邏輯帶寬通常配置和物理接口帶寬相同) OSPF先將鏈路每段的開銷分別計算,然后計算從當(dāng)前節(jié)點到達(dá)任意目標(biāo)地址的網(wǎng)絡(luò)開銷,即多段鏈路累加。選出到達(dá)目標(biāo)網(wǎng)絡(luò)開銷最小的路徑,為最佳路徑。 ospf接口開銷有默認(rèn)的參考值,即接口帶寬默認(rèn)為100Mbps,如果實際帶寬值為10M,那么該接口的cost=100/10=10,如果該接口實際帶寬為100Mpbs那么接口開銷為cost=100/100=1 。但現(xiàn)在的網(wǎng)絡(luò)已經(jīng)進(jìn)入1000M時代,就會出現(xiàn)100M和1000M的帶寬在ospf中得到的開銷相同都是1。所以如果實際應(yīng)用中如果接口帶寬值較高時應(yīng)該重新配置端口的參考帶寬值。
O 192.168.4.0/24 [110/65] via 192.168.3.2, 00:01:00, Vlan20 O 路由協(xié)議代碼:O表示OSPF,R代表RIP,S代表靜態(tài),使用show命令的時候,在最上方有說明。 192.168.4.0/24 分別是目標(biāo)網(wǎng)絡(luò)和目標(biāo)網(wǎng)絡(luò)的掩碼 [110/65] 分別表示管理距離和度量值。
管理距離
管理距離是用來比較不同路由協(xié)議的優(yōu)劣的,如這臺路由器同時啟用了RIP和OSPF兩種動態(tài)路由協(xié)議,都會得出到達(dá)192.168.4.0/24的網(wǎng)絡(luò)路徑,但是那種路由協(xié)議的結(jié)果會被記錄到路由表中呢?就是通過管理距離比較算法的優(yōu)劣。管理距離的值越小,路由器認(rèn)為該協(xié)議的算法越好,計算結(jié)果越準(zhǔn)確,優(yōu)先采用該協(xié)議的結(jié)果。
常見路由協(xié)議的管理距離有: 直連路由 0 靜態(tài)路由 1 EIGRP匯總路由 5 EBGP 20 EIGRP 90 IGRP 100 OSPF 110 IS-IS 115 RIP(v1&v2) 120 EGP 140 ODR 160 ExEIGRP (外部EIGRP) 170 IBGP 200 未知 255
度量值是用來衡量同一種路由協(xié)議計算到達(dá)相同目標(biāo)地址的多條路徑的優(yōu)劣的參數(shù)。度量值最小的會被記錄到路由表。比如:OSPF計算到達(dá)192.168.4.0/24網(wǎng)絡(luò)有三條路徑開銷值分別是:145 ,230 和99,比較后發(fā)現(xiàn)99的這條路徑度量值最小,會被認(rèn)為是最佳路徑,加入到路由表。常用來作為度量值的參考因素有: 跳數(shù)、帶寬、延遲、可靠性、負(fù)載、MTU等。 不同的路由協(xié)議用來作為度量值的參數(shù)是不同的,有的是一種,有的是多種。如RIP使用跳數(shù)做度量值,EIGRP默認(rèn)使用帶寬和延遲兩種,最多可以使用五種。OSPF使用cost(開銷)作為度量值,cost和端口的帶寬相關(guān),基本上是和端口帶寬成反比,即端口帶寬越大,開銷越小,鏈路越優(yōu)。 via 192.168.3.2 表示下一跳地址。即到達(dá)192.168.4.0網(wǎng)絡(luò)首先要到達(dá)192.168.3.2才可以。另外via也可以理解為:更新源,即該路由消息是來自于誰。 00:01:00 該消息的更新時間。 Vlan20 出接口,表示到達(dá)目標(biāo)網(wǎng)絡(luò)應(yīng)該從自己的那個接口將數(shù)據(jù)發(fā)出。
路由表的五要
目標(biāo)地址 目標(biāo)網(wǎng)絡(luò)掩碼 優(yōu)先級(度量值和管理距離) 下一跳地址 出接口**
實驗步驟
新建 packet tracer 拓?fù)鋱D
路由器 OSPF 動態(tài)路由配置路由器 OSPF 動態(tài)路由配置
(1)在本實驗中的三層交換機上劃分 VLAN10 和 VLAN20,其中 VLAN10 用于 連接校園網(wǎng)主機,VLAN20 用于連接 R1 (2)路由器之間通過 V35 電纜通過串口連接,DCE 端連接在 R1 上,配置其時鐘 頻率 64000 (3)主機和交換機通過直連線,主機與路由器通過交叉線連接 (4)在 S3560 上配置 OSPF 路由協(xié)議 (5)在路由器 R1、R2 上配置 OSPF 路由協(xié)議 (6)將 PC1、PC2 主機默認(rèn)網(wǎng)關(guān)設(shè)置為與直連網(wǎng)路設(shè)備接口 IP 地址 (7)驗證 PC1、PC2 主機之間可以互相同信
實驗設(shè)備
PC 2 臺;Switch_3560 1 臺;Router-PT 2 臺;直連線;交叉線;DCE 串口線
PC1
IP: 192.168.1.2
Submask: 255.255.255.0
Gateway: 192.168.1.1
PC2
IP: 192.168.2.2
Submask: 255.255.255.0
Gateway: 192.168.2.1
S3560
en
conf t
hostname S3560
vlan 10
exit
vlan 20
exit
interface fa 0/10
switchport access vlan 10
exit
int fa 0/20
switchport access valn 20
exit
interface vlan 10
ip address 192.168.1.1 255.255.255.0
no shutdown
exit
interface vlan 20
ip address 192.168.3.1 255.255.255.0
no shutdown
end
show ip route
conf t
router ospf 1 #指定ospf的進(jìn)程號為1
network 192.168.1.0 0.0.0.255 area 0 #宣告192.168.1.0網(wǎng)段反掩碼為0.0.0.255 區(qū)域為骨干區(qū)域area 0
network 192.168.3.0 0.0.0.255 area 0
end
show ip route
R1
en
conf t
hostname R1
interface fa 0/0
no shutdown
ip address 192.168.3.2 255.255.255.0
exit
interface serial 2/0
no shutdown
clock rate 64000
ip address 192.168.4.1 255.255.255.0
end
show ip route
conf t
router ospf 1
network 192.168.3.0 0.0.0.255 area 0
network 192.168.4.0 0.0.0.255 area 0
end
show ip route
R2
en
conf t
hostname R2
interface fa 0/0
no shutdown
ip address 192.168.2.1 255.255.255.0
exit
interface serial 2/0
no shutdown
ip address 192.168.4.2 255.255.255.0
end
show ip route
conf t
router ospf 1
network 192.168.2.0 0.0.0.255 area 0
network 192.168.4.0 0.0.0.255 area 0
end
show ip route
實戰(zhàn)演練
S3560
Switch>en
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#hostname
% Incomplete command.
Switch(config)#hostname S3560
S3560(config)#vlan 10
S3560(config-vlan)#exit
S3560(config)#vlan 20
S3560(config-vlan)#int fa 0/10
S3560(config-if)#sw acc vlan 10
S3560(config-if)#exit
S3560(config)#int fa 0/20
S3560(config-if)#sw acc vlan 20
S3560(config-if)#exit
S3560(config)#int vlan 10
%LINK-5-CHANGED: Interface Vlan10, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan10, changed state to up
S3560(config-if)#ip address 192.168.1.1 255.255.255.0
S3560(config-if)#no shut
S3560(config-if)#exit
S3560(config)#int vlan 20
S3560(config-if)#
%LINK-5-CHANGED: Interface Vlan20, changed state to up
S3560(config-if)#ip address 192.168.3.1 255.255.255.0
S3560(config-if)#no shut
S3560(config-if)#end
S3560#
%SYS-5-CONFIG_I: Configured from console by console
S3560#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
C 192.168.1.0/24 is directly connected, Vlan10
S3560#conf t
Enter configuration commands, one per line. End with CNTL/Z.
S3560(config)#router ospf 1
S3560(config-router)#network 192.168.1.0 0.0.0.255 area 0
S3560(config-router)#network 192.168.3.0 0.0.0.255 area 0
S3560(config-router)#
S3560(config-router)#end
S3560#
%SYS-5-CONFIG_I: Configured from console by console
S3560#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
C 192.168.1.0/24 is directly connected, Vlan10
S3560#
%LINK-5-CHANGED: Interface FastEthernet0/20, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/20, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan20, changed state to up
00:12:29: %OSPF-5-ADJCHG: Process 1, Nbr 192.168.4.1 on Vlan20 from LOADING to FULL, Loading Done
R1
Continue with configuration dialog? [yes/no]: n
Press RETURN to get started!
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#hostname R1
R1(config)#int fa 0/0
R1(config-if)#no shut
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
R1(config-if)#ip address 192.168.3.2 255.255.255.0
R1(config-if)#exit
R1(config)#
R1(config)#int serial 2/0
R1(config-if)#no shut
%LINK-5-CHANGED: Interface Serial2/0, changed state to down
R1(config-if)#clock rate 64000
R1(config-if)#ip address 192.168.4.1 255.255.255.0
R1(config-if)#end
R1#
%SYS-5-CONFIG_I: Configured from console by console
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
C 192.168.3.0/24 is directly connected, FastEthernet0/0
R1#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#router ospf 1
R1(config-router)#network 192.168.3.0 0.0.0.255 area 0
R1(config-router)#network 192.168.4.0 0.0.0.255 area 0
R1(config-router)#end
R1#
%SYS-5-CONFIG_I: Configured from console by console
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
O 192.168.1.0/24 [110/2] via 192.168.3.1, 00:00:23, FastEthernet0/0
C 192.168.3.0/24 is directly connected, FastEthernet0/0
R1#
R2
Router>en
Router#
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#hostname R2
R2(config)#int fa 0/0
R2(config-if)#no shut
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
R2(config-if)#ip address 192.168.2.1 255.255.255.0
R2(config-if)#exit
R2(config)#
R2(config)#int serial 2/0
R2(config-if)#no shut
%LINK-5-CHANGED: Interface Serial2/0, changed state to up
R2(config-if)#ip add
%LINEPROTO-5-UPDOWN: Line protocol on Interface Serial2/0, changed state to up
% Incomplete command.
R2(config-if)#ip add 192.168.4.2 255.255.255.0
R2(config-if)#end
R2#
%SYS-5-CONFIG_I: Configured from console by console
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
C 192.168.2.0/24 is directly connected, FastEthernet0/0
C 192.168.4.0/24 is directly connected, Serial2/0
R2#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R2(config)#router ospf 1
R2(config-router)#
R2(config-router)#network 192.168.2.0 0.0.0.255 area 0
R2(config-router)#network 192.168.4.0 0.0.0.255 area 0
R2(config-router)#end
R2#
%SYS-5-CONFIG_I: Configured from console by console
R2#
00:14:52: %OSPF-5-ADJCHG: Process 1, Nbr 192.168.4.1 on Serial2/0 from LOADING to FULL, Loading Done
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
O 192.168.1.0/24 [110/66] via 192.168.4.1, 00:00:03, Serial2/0
C 192.168.2.0/24 is directly connected, FastEthernet0/0
O 192.168.3.0/24 [110/65] via 192.168.4.1, 00:00:03, Serial2/0
C 192.168.4.0/24 is directly connected, Serial2/0
R2#
測試
PC>ipconfig
IP Address......................: 192.168.1.2
Subnet Mask.....................: 255.255.255.0
Default Gateway.................: 192.168.1.1
PC>ping 192.168.2.2
Pinging 192.168.2.2 with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Ping statistics for 192.168.2.2:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
PC>
ping 不通,查看三層交換機的路由表信息并開啟路由轉(zhuǎn)發(fā)功能
S3560#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
C 192.168.1.0/24 is directly connected, Vlan10
O 192.168.2.0/24 [110/66] via 192.168.3.2, 00:04:27, Vlan20
C 192.168.3.0/24 is directly connected, Vlan20
O 192.168.4.0/24 [110/65] via 192.168.3.2, 00:05:43, Vlan20
S3560#conf t
Enter configuration commands, one per line. End with CNTL/Z.
S3560(config)#
S3560(config)#ip routing
S3560(config)#
再次觀察測試情況
PC>ping -t 192.168.2.2
Pinging 192.168.2.2 with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Reply from 192.168.2.2: bytes=32 time=18ms TTL=125
Reply from 192.168.2.2: bytes=32 time=23ms TTL=125
Reply from 192.168.2.2: bytes=32 time=19ms TTL=125
Reply from 192.168.2.2: bytes=32 time=22ms TTL=125
Reply from 192.168.2.2: bytes=32 time=20ms TTL=125
Reply from 192.168.2.2: bytes=32 time=21ms TTL=125
Reply from 192.168.2.2: bytes=32 time=18ms TTL=125
分享名稱:詳解配置OSPF動態(tài)路由
路徑分享:http://www.dlmjj.cn/article/dhhjscg.html


咨詢
建站咨詢
