<b>九、OSPF</b><b>基本指令:</b>
R1(config)#router ospf 程序号 //指定使用OSPF協定
R1(config-router)#network 接口IP 0.0.0.0(反掩碼) area 區域号
R1(config-router)#router-id ip位址 //手工指定router-id
備注:如果router-id已經産生,要改變router-id則必須手工指定,且必須重新開機OSPF程序才生效。
重新開機OSPF程序:R1#clear ip ospf process
反掩碼是: 1 和 0 反轉的子網路遮罩,即用255.255.255.255減去原掩碼得出反掩碼,又稱為通配符,0位 表示必須比對,1位表示不必比對。例如:
Router(config)# network 2.3.6.0 0.0.0.255 area 0
表示可以是 2.3.6.0 這個網段的任意主機
Router(config)# network 2.2.2.2 0.0.0.0 area 0
表示唯一位址為 2.2.2.2 (常用于設定接口位址****經常使用)
Router(config)# network 0.0.0.0 0.0.0.0 area 0
表示可以是任意網段的任意主機
在存在雙鍊路的網絡環境中,可以實作等價負載均衡
通過修改鍊路成本實作:進入接口模式
r1(config)#interface 接口編号
r1(config-if)#ip ospf cost 成本(1-65535)
配置相關的接口參數:
hello時間:在接口模式下:
r1(config-if)#ip ospf hello-interval 時間
**兩台路由器相連的接口都要修改,保持時間預設會是hello的時間4倍
保持時間:
r1(config-if)#ip ospf dead-interval 時間
檢視OSPF配置指令:
檢視OPSF鄰居表:r1#show ip ospf neighbors
檢視rouer-id,管理距離:r1#show ip protocols
檢視接口的相關OSPF屬性:r1#show ip ospf interface 接口
可以看到hello時間,保持時間,接口類型等等
ospf學習到的路由條目用字母O表示,即同一個區域内所學到的,管理距離值110
設定接口的優先級:
R1(config)# interface s0
R1(config-if)# <b>ip ospf priority</b> 100
顯示接口的優先級資訊
R1# show ip ospf interface s0
配置OSPF的網絡類型:
R1 (config-if) # ip ospf network {broadcast | point-to-point | point-to-multicast}
OSPF的認證:
為了安全的原因,在相同OSPF區域的路由器上啟用身份驗證的功能,隻有經過身份驗證的同一區域的路由器才能互相通告路由資訊。
OSPF的純文字驗證:
簡單的純文字驗證允許一個區隻配置一個密碼(Password)同一個區中的路由器要想參與路由,他們必須配置相同的密碼。這種方法的缺點是易受攻擊。
使用下面的指令啟動密碼驗證:
R1(config-if)<b>#</b>ip ospf authentication-key mypassword
R1(config-router)#area 0 authentication //”0”是area的ID
OSPF的MD5認證:
MD5(Message Digest Authentication)是采用加密驗證,每個路由器上都必須配置密碼和密碼ID。路由器使用一種算法,基于OSPF封包、密碼和密碼ID産生一個 “Message Digest”,然後加到OSPF封包中。不像簡單密碼驗證,MD5驗證密碼不在網絡上傳輸。每個OSPF封包中還包含有一個序列号以保護網絡不受攻擊。
使用下面的指令來配置MD5驗證:
R1(config-if)<b>#</b>ip ospf message-digest-key <key-id> md5 <key>
R1(config-router)#area 0 authentication message-digest
十、執行個體:
下面網絡拓樸圖中配置OSPF協定,并且在R2與R3實作等負載均衡,并且手動修改R2的router-id為10.10.10.10,檢視DR和BDR路由是哪個?檢視Router ID?通過改變RID來改變DR和BDR。
<a href="http://img1.51cto.com/attachment/201002/3/545402_1265159817ZlRz.png"></a>
三個路由器基配置
R1
enable
configure terminal
no ip domain-lookup
line console 0
no exec-timeout
logging syn
password cisco
login
hostname r1
interface l0
ip add 1.1.1.1 255.255.255.0
no sh
interface s0/0
ip address 192.1.1.1 255.255.255.0
no shutdown
router ospf 1
network 192.1.1.1 0.0.0.0 area 0
network 1.1.1.1 0.0.0.0 area 0
R2
hostname r2
ip add 2.2.2.2 255.255.255.0
ip address 192.1.1.2 255.255.255.0
interface s0/1
ip address 193.1.1.2 255.255.255.0
interface f1/0
ip address 194.1.1.2 255.255.255.0
network 192.1.1.2 0.0.0.0 area 0
network 193.1.1.2 0.0.0.0 area 0
network 194.1.1.2 0.0.0.0 area 0
network 2.2.2.2 0.0.0.0 area 0
R3
hostname r3
ip add 3.3.3.3 255.255.255.0
ip address 193.1.1.1 255.255.255.0
ip address 194.1.1.1 255.255.255.0
network 193.1.1.1 0.0.0.0 area 0
network 194.1.1.1 0.0.0.0 area 0
network 3.3.3.3 0.0.0.0 area 0
1、檢視DR和BDR路由:
r2#sh ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
3.3.3.3 1 FULL/BDR 00:00:32 194.1.1.1 FastEthernet1/0
1.1.1.1 0 FULL/ - 00:00:39 192.1.1.1 Serial0/0
顯示R2是DR,R3是BDR
2、檢視R2的Router ID
r2#sho 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 2.2.2.2
Number of areas in this router is 1. 1 normal 0 stub 0 nssa
Maximum path: 4
Routing for Networks:
2.2.2.2 0.0.0.0 area 0
192.1.1.2 0.0.0.0 area 0
193.1.1.2 0.0.0.0 area 0
194.1.1.2 0.0.0.0 area 0
Reference bandwidth unit is 100 mbps
Routing Information Sources:
Gateway Distance Last Update
3.3.3.3 110 00:14:50
1.1.1.1 110 00:14:50
Distance: (default is 110)
顯示Router ID為:2.2.2.2
3、改變其Router ID:
r2(config)#router ospf 1
r2(config-router)#router-id 10.10.10.10
Reload or use "clear ip ospf process" command, for this to take effect
r2(config-router)#end
r2#clear ip ospf process
Reset ALL OSPF processes? [no]: yes
r2#sh ip protocols
Router ID 10.10.10.10
3.3.3.3 110 00:19:38
1.1.1.1 110 00:00:12
4、檢視R2路由器的DR和BDR路由資訊:
r2#sh ip ospf nei
3.3.3.3 1 FULL/DR 00:00:32 194.1.1.1 FastEthernet1/0
顯示R2變成BDR,R3變成DR
5、再到R3重新開機OSPF協定
r3#clear ip ospf pr
r3#clear ip ospf process
再檢視R2資訊,又變回來了。
3.3.3.3 1 FULL/BDR 00:00:34 194.1.1.1 FastEthernet1/0
1.1.1.1 0 FULL/ - 00:00:33 192.1.1.1 Serial0/0
1、 通過改變路由器接口的Cost來實作R2與R3負載均衡
R2和R3有兩條連接配接一個s0/1和f1/0,成本cost分别為64和1,是以在R2上到3.3.3.3路由表是194.1.1.1。
<b>r2#sh ip ospf interface s0/1</b>
Serial0/1 is up, line protocol is up
Internet Address 193.1.1.2/24, Area 0
Process ID 1, Router ID 2.2.2.2, Network Type POINT_TO_POINT, Cost: 64
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:06
Supports Link-local Signaling (LLS)
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 3.3.3.3
Suppress hello for 0 neighbor(s)
<b>r2#sh ip ospf interface f1/0</b>
FastEthernet1/0 is up, line protocol is up
Internet Address 194.1.1.2/24, Area 0
Process ID 1, Router ID 2.2.2.2, Network Type BROADCAST, Cost: 1
Transmit Delay is 1 sec, State DR, Priority 1
Designated Router (ID) 2.2.2.2, Interface address 194.1.1.2
Backup Designated router (ID) 3.3.3.3, Interface address 194.1.1.1
Hello due in 00:00:03
Index 3/3, flood queue length 0
Last flood scan length is 1, maximum is 2
Last flood scan time is 0 msec, maximum is 4 msec
Adjacent with neighbor 3.3.3.3 (Backup Designated Router)
<b>r2#sh ip route</b>
1.0.0.0/32 is subnetted, 1 subnets
O 1.1.1.1 [110/65] via 192.1.1.1, 00:03:18, Serial0/0
2.0.0.0/24 is subnetted, 1 subnets
C 2.2.2.0 is directly connected, Loopback0
3.0.0.0/32 is subnetted, 1 subnets
O 3.3.3.3 [110/2] via 194.1.1.1, 00:03:18, FastEthernet1/0
C 193.1.1.0/24 is directly connected, Serial0/1
C 192.1.1.0/24 is directly connected, Serial0/0
C 194.1.1.0/24 is directly connected, FastEthernet1/0
<b>改變R2</b><b>的s0/1</b><b>接口cost</b><b>為1</b>
r2(config)#interface s0/1
r2(config-if)#ip ospf cost 1
r2#sh ip ospf interface s0/1
Process ID 1, Router ID 2.2.2.2, Network Type POINT_TO_POINT, Cost: 1
Hello due in 00:00:01
修改成功,再檢視R2的路由表,到達3.3.3.3有兩條路由條目了。
r2#sh ip route
O 1.1.1.1 [110/65] via 192.1.1.1, 00:00:00, Serial0/0
O 3.3.3.3 [110/2] via 194.1.1.1, 00:00:00, FastEthernet1/0
[110/2] via 193.1.1.1, 00:00:00, Serial0/1
<b>十一、處理OSPF故障常用指令</b>
OSPF是鍊路狀态協定,維護3個資料庫:相鄰資料庫、拓撲結構資料庫、路由表。
OSPF相關的show指令:
Show running-config
Show ip route
Show ip route ospf ;僅顯示OSPF路由
Show ip ospf process-id ;顯示與特定程序ID相關的資訊
Show ip ospf ;顯示OSPF相關資訊
Show ip ospf border-routers ;顯示邊界路由器
Show ip ospf database ;顯示OSPF的歸納資料庫
Show ip ospf interface ;顯示指定接口上的OSPF資訊
Show ip ospf neighbor ;顯示OSPF相鄰資訊
Show ip ospf request-list ;顯示鍊路狀态請求清單
Show ip ospf summary-address ;顯示歸納路由的再釋出資訊
Show ip ospf virtual-links ;顯示虛拟鍊路資訊
Show ip interface ;顯示接口的IP設定
OSPF相關的debug指令:
Debug ip ospf adj ;
Debug ip ospf events
Debug ip ospf flood
Debug ip ospf lsa-generation
Debug ip ospf packet
Debug ip ospf retransmission
Debug ip ospf spf
Debug ip ospf tree
常見的OSPF故障:OSPF的每個area不超過100台路由器,整個網絡不超過700台路由器;通配符掩碼配置不當;
本文轉自成功不僅是個人榮譽,更是對家人責任部落格51CTO部落格,原文連結http://blog.51cto.com/hukunlin/272696如需轉載請自行聯系原作者
kunlin_hu