1. 程式人生 > >OSPF實驗記錄

OSPF實驗記錄

p地址 運行 ppr int for received fib pro stand

技術分享圖片
技術分享圖片

R1配置

一、配置接口IP

[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)     

二、配置OSPF協議,將區域網段發布出去

[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]

三、指定router id

  • 第一種方法
[r1]router id 1.1.1.1   //指定router id,全局,所有協議都會使用這個router id
  • 第二種方法
[r1]ospf 1 router-id 1.1.1.1    //只針對ospf指定router id

四、重啟OSPF進程,使router id生效

<r1>reset ospf 1 process 

<r1>dis ospf brief  //查看OSPF的一些信息

五、配置與R6間的RIP協議

[r1]rip
[r1-rip-1]version 2
[r1-rip-1]undo summary 
[r1-rip-1]network 16.0.0.0

六、查看RIP協議

[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進行一個路由引入的動作

  • 1)把RIP路由引入到OSPF域
[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
  • 2)同時也把OSPF的域引入到RIP
[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

※備註

  • 1、RID的選舉,即router id的選舉
    一般默認從環回口選擇一個最大的,如果環回口沒有地址,就會從物理口選個最大的;
    建議手動指定router id,這樣心裏有數,便於排錯;

  • 2、DR的選舉
    在一個以太網裏面router id大的是DR,第二大的是BDR;
    在現網中也不會去關心,讓他自己去選舉就可以了;

R2配置

一、接口IP

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
#

二、OSPF配置,指定router id,發布網段

[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

R3配置

一、接口IP

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
#

二、OSPF配置,指定router id,發布網段

[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中

R4配置

一、接口IP

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
#

二、OSPF配置,指定router id,發布網段

[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]

三、查看OSPF的鄰接關系

[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

四、查看OSPF接口的信息

 <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 

關於上面的Cost:1的理解

OSPF協議是使用的帶寬來作為度量值的,100M除以接口得到的帶寬,
這裏試驗中應該是100M/1G得到的應該是一個小數,但是度量值不可能是一個小數,最小就是1;
這樣導致接口是10G、1G、100M,得出的度量值都是1,不能真正區分出鏈路的優劣!
解決辦法:
1、更改參考帶寬的值,即將100M改為10G,或者100G,然後用更改後的值來除以接口,
但是需要在自治系統裏的所有設備上進行更改,工作量巨大;
2、現網中一般采取直接給接口配置cost值;
如:

interface GigabitEthernet 0/0/0
ospf cost 10
//流量從cost小的走

R5配置

一、接口IP

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
#

二、OSPF配置,指定router id,發布網段

[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

三、查看OSPF的鄰接關系

[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 
[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

OSPF實驗記錄