[r1]interface GigabitEthernet0/0/0 [r1-GigabitEthernet0/0/0]ip address 12.0.0.1 255.255.255.252 [r1-GigabitEthernet0/0/0]quit [r1]interface GigabitEthernet0/0/1 [r1-GigabitEthernet0/0/1]ip address 16.0.0.1 255.255.255.252 [r1-GigabitEthernet0/0/0]quit [r1]interface LoopBack0 [r1-LoopBack0]ip address 1.1.1.1 255.255.255.255 [r1-LoopBack0]quit <r1>display ip interface brief //查看接口IP信息 *down: administratively down !down: FIB overload down ^down: standby (l): loopback (s): spoofing (d): Dampening Suppressed The number of interface that is UP in Physical is 4 The number of interface that is DOWN in Physical is 8 The number of interface that is UP in Protocol is 4 The number of interface that is DOWN in Protocol is 8 Interface IP Address/Mask Physical Protocol Ethernet0/0/0 unassigned down down Ethernet0/0/1 unassigned down down GigabitEthernet0/0/0 12.0.0.1/30 up up GigabitEthernet0/0/1 16.0.0.1/30 up up GigabitEthernet0/0/2 unassigned down down GigabitEthernet0/0/3 unassigned down down LoopBack0 1.1.1.1/32 up up(s)
[r1]ospf 1 [r1-ospf-1]area 1 [r1-ospf-1-area-0.0.0.1] [r1-ospf-1-area-0.0.0.1]network 12.0.0.0 0.0.0.3 //將area 1區域中的接口網段發佈出去,後面爲反掩碼 [r1-ospf-1-area-0.0.0.1]network 1.1.1.1 0.0.0.0 //將環回口也發佈出去,另外一個接口是和R6相鏈接的,不須要進行發佈,並且運行的是RIP協議 [r1-ospf-1-area-0.0.0.1]
[r1]router id 1.1.1.1 //指定router id,全局,全部協議都會使用這個router id
[r1]ospf 1 router-id 1.1.1.1 //只針對ospf指定router id
<r1>reset ospf 1 process <r1>dis ospf brief //查看OSPF的一些信息
[r1]rip [r1-rip-1]version 2 [r1-rip-1]undo summary [r1-rip-1]network 16.0.0.0
[r1-rip-1]dis ip routing-table protocol rip Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Public routing table : RIP Destinations : 1 Routes : 1 RIP routing table status : <Active> Destinations : 1 Routes : 1 Destination/Mask Proto Pre Cost Flags NextHop Interface 6.6.6.6/32 RIP 100 1 D 16.0.0.2 GigabitEthernet 0/0/1 RIP routing table status : <Inactive> Destinations : 0 Routes : 0 [r1-rip-1]
[r1]ospf 1 [r1-ospf-1]import-route rip 1 //把RIP引入到了OSPF,默認用的類型是type 2,即cost不累加 //在R3上經過<r3>dis ip routing-table 能夠看到一條路由 6.6.6.6/32 O_ASE 150 1(這個1就是cost) D 23.0.0.1 GigabitEthernet 0/0/0 cost值是1,並無累加,若是累加了應該是2 //再在R3上經過<r3>dis ospf routing 能夠看到 Routing for ASEs Destination Cost Type Tag NextHop AdvRouter 6.6.6.6/32 1 Type2 1 23.0.0.1 1.1.1.1 16.0.0.0/30 1 Type2 1 23.0.0.1 1.1.1.1 這裏的Type是2,說明剛纔的import-route rip 1命令默認是使用的類型2,即cost值不會累加 從新在R1配置該命令以下 [r1-ospf-1]import-route rip 1 type 1 cost 5 //手動設置爲類型1,且設置cost值爲5,那麼通過R2到達R3 cost值應該變爲了7 再在R3上經過<r3>dis ospf routing 來查看 Routing for ASEs Destination Cost Type Tag NextHop AdvRouter 6.6.6.6/32 7 Type1 1 23.0.0.1 1.1.1.1 16.0.0.0/30 7 Type1 1 23.0.0.1 1.1.1.1 //驗證確實cost變爲了7
[r1]rip [r1-rip-1]import-route ospf 1 [r1-rip-1]dis th # rip 1 undo summary version 2 network 16.0.0.0 import-route ospf 1 # 導入路由完成後在R1查看路由表 [r1-rip-1]dis ip routing-table Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Routing Tables: Public Destinations : 15 Routes : 15 Destination/Mask Proto Pre Cost Flags NextHop Interface 1.1.1.1/32 Direct 0 0 D 127.0.0.1 LoopBack0 2.2.2.2/32 OSPF 10 1 D 12.0.0.2 GigabitEthernet 0/0/0 3.3.3.3/32 OSPF 10 2 D 12.0.0.2 GigabitEthernet 0/0/0 4.4.4.4/32 OSPF 10 3 D 12.0.0.2 GigabitEthernet 0/0/0 5.5.5.5/32 OSPF 10 4 D 12.0.0.2 GigabitEthernet 0/0/0 6.6.6.6/32 RIP 100 1 D 16.0.0.2 GigabitEthernet 0/0/1 12.0.0.0/30 Direct 0 0 D 12.0.0.1 GigabitEthernet 0/0/0 12.0.0.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/0 16.0.0.0/30 Direct 0 0 D 16.0.0.1 GigabitEthernet 0/0/1 16.0.0.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/1 23.0.0.0/30 OSPF 10 2 D 12.0.0.2 GigabitEthernet 0/0/0 34.0.0.0/30 OSPF 10 3 D 12.0.0.2 GigabitEthernet 0/0/0 45.0.0.0/30 OSPF 10 4 D 12.0.0.2 GigabitEthernet 0/0/0 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
在R6查看路由表 <r6>dis ip routing-table Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Routing Tables: Public Destinations : 14 Routes : 14 Destination/Mask Proto Pre Cost Flags NextHop Interface 1.1.1.1/32 RIP 100 1 D 16.0.0.1 GigabitEthernet 0/0/0 2.2.2.2/32 RIP 100 1 D 16.0.0.1 GigabitEthernet 0/0/0 3.3.3.3/32 RIP 100 1 D 16.0.0.1 GigabitEthernet 0/0/0 4.4.4.4/32 RIP 100 1 D 16.0.0.1 GigabitEthernet 0/0/0 5.5.5.5/32 RIP 100 1 D 16.0.0.1 GigabitEthernet 0/0/0 6.6.6.6/32 Direct 0 0 D 127.0.0.1 LoopBack0 12.0.0.0/30 RIP 100 1 D 16.0.0.1 GigabitEthernet 0/0/0 16.0.0.0/30 Direct 0 0 D 16.0.0.2 GigabitEthernet 0/0/0 16.0.0.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/0 23.0.0.0/30 RIP 100 1 D 16.0.0.1 GigabitEthernet 0/0/0 34.0.0.0/30 RIP 100 1 D 16.0.0.1 GigabitEthernet 0/0/0 45.0.0.0/30 RIP 100 1 D 16.0.0.1 GigabitEthernet 0/0/0 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
<r6>ping 5.5.5.5 //測試從R6ping R5的環回口IP地址 PING 5.5.5.5: 56 data bytes, press CTRL_C to break Reply from 5.5.5.5: bytes=56 Sequence=1 ttl=251 time=160 ms Reply from 5.5.5.5: bytes=56 Sequence=2 ttl=251 time=170 ms Reply from 5.5.5.5: bytes=56 Sequence=3 ttl=251 time=110 ms Reply from 5.5.5.5: bytes=56 Sequence=4 ttl=251 time=120 ms Reply from 5.5.5.5: bytes=56 Sequence=5 ttl=251 time=170 ms --- 5.5.5.5 ping statistics --- 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 110/146/170 ms
<r5>ping 6.6.6.6 //再從R5ping R6的環回口IP地址 PING 6.6.6.6: 56 data bytes, press CTRL_C to break Reply from 6.6.6.6: bytes=56 Sequence=1 ttl=251 time=160 ms Reply from 6.6.6.6: bytes=56 Sequence=2 ttl=251 time=160 ms Reply from 6.6.6.6: bytes=56 Sequence=3 ttl=251 time=120 ms Reply from 6.6.6.6: bytes=56 Sequence=4 ttl=251 time=110 ms Reply from 6.6.6.6: bytes=56 Sequence=5 ttl=251 time=160 ms --- 6.6.6.6 ping statistics --- 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 110/142/160 ms
一、RID的選舉,即router id的選舉
通常默認從環回口選擇一個最大的,若是環回口沒有地址,就會從物理口選個最大的;
建議手動指定router id,這樣內心有數,便於排錯;ide
interface g 0/0/0 ospf dr-priority 0 //默認爲1,修改成0使其不能參與DR的選舉 //若是一個修改成5,一個修改成10,那麼優先級爲10的就是DR,優先級爲5的就是BDR
在現網中也不會去關心,讓他本身去選舉就能夠了;oop
interface GigabitEthernet0/0/0 ip address 12.0.0.2 255.255.255.252 # interface GigabitEthernet0/0/1 ip address 23.0.0.1 255.255.255.252 # interface LoopBack0 ip address 2.2.2.2 255.255.255.255 #
[r2]ospf 10 router-id 2.2.2.2 //進程號多少無所謂,只有本地意義,這裏使用的是10,同時指定router id [r2-ospf-10]area 1 [r2-ospf-10-area-0.0.0.1]network 12.0.0.0 0.0.0.3 [r2-ospf-10-area-0.0.0.1]network 2.2.2.2 0.0.0.0 [r2-ospf-10-area-0.0.0.1]network 23.0.0.0 0.0.0.3
interface GigabitEthernet0/0/0 ip address 23.0.0.2 255.255.255.252 # interface GigabitEthernet0/0/1 ip address 34.0.0.1 255.255.255.252 # interface LoopBack0 ip address 3.3.3.3 255.255.255.255 #
[r3]ospf 10 router-id 3.3.3.3 [r3-ospf-10]area 1 [r3-ospf-10-area-0.0.0.1]network 23.0.0.0 0.0.0.3 [r3-ospf-10-area-0.0.0.1]q [r3-ospf-10]area 0 [r3-ospf-10-area-0.0.0.0]network 34.0.0.0 0.0.0.3 [r3-ospf-10-area-0.0.0.0]network 3.3.3.3 0.0.0.0 //環回口也能夠放到區域1中
interface GigabitEthernet0/0/0 ip address 34.0.0.2 255.255.255.252 # interface GigabitEthernet0/0/1 ip address 45.0.0.1 255.255.255.252 # interface LoopBack0 ip address 4.4.4.4 255.255.255.255 #
[r4]ospf 10 router-id 4.4.4.4 [r4-ospf-10]area 0 [r4-ospf-10-area-0.0.0.0]network 4.4.4.4 0.0.0.0 [r4-ospf-10-area-0.0.0.0]network 34.0.0.0 0.0.0.3 [r4-ospf-10-area-0.0.0.0]q [r4-ospf-10]area 2 [r4-ospf-10-area-0.0.0.2]network 45.0.0.0 0.0.0.3 [r4-ospf-10-area-0.0.0.2]
[r4-ospf-10-area-0.0.0.2]return //直接回到用戶視圖 <r4>display ospf peer brief OSPF Process 10 with Router ID 4.4.4.4 Peer Statistic Information ---------------------------------------------------------------------------- Area Id Interface Neighbor id State 0.0.0.0 GigabitEthernet0/0/0 3.3.3.3 Full 0.0.0.2 GigabitEthernet0/0/1 5.5.5.5 Full ---------------------------------------------------------------------------- //能夠看到R4的鄰接關係有3和5
<r4>dis ospf interface GigabitEthernet 0/0/0 OSPF Process 10 with Router ID 4.4.4.4 Interfaces Interface: 34.0.0.2 (GigabitEthernet0/0/0) Cost: 1 State: BDR Type: Broadcast MTU: 1500 Priority: 1 Designated Router: 34.0.0.1 Backup Designated Router: 34.0.0.2 Timers: Hello 10 , Dead 40 , Poll 120 , Retransmit 5 , Transmit Delay 1
OSPF協議是使用的帶寬來做爲度量值的,100M除以接口獲得的帶寬,
這裏試驗中應該是100M/1G獲得的應該是一個小數,可是度量值不多是一個小數,最小就是1;
這樣致使接口是10G、1G、100M,得出的度量值都是1,不能真正區分出鏈路的優劣!
解決辦法:
一、更改參考帶寬的值,即將100M改成10G,或者100G,而後用更改後的值來除以接口,
可是須要在自治系統裏的全部設備上進行更改,工做量巨大;
二、現網中通常採起直接給接口配置cost值;
如:學習
interface GigabitEthernet 0/0/0 ospf cost 10 //流量從cost小的走
interface GigabitEthernet0/0/0 ip address 45.0.0.2 255.255.255.252 # interface LoopBack0 ip address 5.5.5.5 255.255.255.255 #
[r5]ospf 10 router-id 5.5.5.5 [r5-ospf-10]area 2 [r5-ospf-10-area-0.0.0.2]network 45.0.0.0 0.0.0.3 [r5-ospf-10-area-0.0.0.2]network 5.5.5.5 0.0.0.0
[r5]display ospf peer brief //查看OSPF的鄰接關係 OSPF Process 10 with Router ID 5.5.5.5 Peer Statistic Information ---------------------------------------------------------------------------- Area Id Interface Neighbor id State 0.0.0.2 GigabitEthernet0/0/0 4.4.4.4 Full ---------------------------------------------------------------------------- //能夠看到R5的鄰接關係只有一個4
<r4>dis ip routing-table Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Routing Tables: Public Destinations : 13 Routes : 13 Destination/Mask Proto Pre Cost Flags NextHop Interface 1.1.1.1/32 OSPF 10 3 D 34.0.0.1 GigabitEthernet 0/0/0 2.2.2.2/32 OSPF 10 2 D 34.0.0.1 GigabitEthernet 0/0/0 3.3.3.3/32 OSPF 10 1 D 34.0.0.1 GigabitEthernet 0/0/0 4.4.4.4/32 Direct 0 0 D 127.0.0.1 LoopBack0 5.5.5.5/32 OSPF 10 1 D 45.0.0.2 GigabitEthernet 0/0/1 12.0.0.0/30 OSPF 10 3 D 34.0.0.1 GigabitEthernet 0/0/0 23.0.0.0/30 OSPF 10 2 D 34.0.0.1 GigabitEthernet 0/0/0 34.0.0.0/30 Direct 0 0 D 34.0.0.2 GigabitEthernet 0/0/0 34.0.0.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/0 45.0.0.0/30 Direct 0 0 D 45.0.0.1 GigabitEthernet 0/0/1 45.0.0.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/1 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
[r6]rip [r6-rip-1]version 2 //啓用版本2 [r6-rip-1]undo summary //關閉自動彙總 [r6-rip-1]network 6.0.0.0 //宣告本身的網段,只能宣告有類網段 [r6-rip-1]network 16.0.0.0