【ネットワーク】OSPF②

ネイバーを確立するときの条件

・OSPFネットワーク全体で、RIDがユニーク

・MTU値の一致(OSPFはフラグメンテーションをサポートしていないため)

・エリアIDの一致

・Hello Dead インターバルの一致

・認証タイプと認証情報(ID passwordなど)

・エリアタイプ(Stub,NSSAなど)

 

OSPFコンフィグ

OSPFを起動するコンフィグは下記の通り何パターンかあり。

・インタフェースで指定するパターン

R4(config)#interface gigabitEthernet 0/1
R4(config-if)#ip ospf 1 area 0

 

・networkコマンドで且つ全てのネットワークを指定するパターン

R1(config)#router ospf 1
R1(config-router)#network 0.0.0.0 255.255.255.225 area 0

 

・OSPFを有効にしたいインタフェースのIPアドレスを指定するパターン

 (セグメント指定でも可能 例10.3.3.3/24)

R3(config)#router ospf 1
R3(config-router)#network 10.3.3.3 0.0.0.0 area 0

例:R3(config-router)#network 10.3.3.3 0.0.0.255 area 0

 

確認コマンド

show ip ospf interface

OSPFが有効なインターフェースの情報が出力されます。

passive interfaceを有効にしていると青字部分の出力が異なってます。

 

R1#show ip ospf interface
Loopback0 is up, line protocol is up 
  Internet Address 192.168.1.1/32, Area 0, Attached via Network Statement
  Process ID 1, Router ID 192.168.1.1, Network Type LOOPBACK, Cost: 1
  Topology-MTID    Cost    Disabled    Shutdown      Topology Name
        0           1         no          no            Base
  Loopback interface is treated as a stub Host


GigabitEthernet0/2 is up, line protocol is up 
  Internet Address 10.1.1.1/24, Area 0, Attached via Network Statement
  Process ID 1, Router ID 192.168.1.1, Network Type BROADCAST, Cost: 1
  Topology-MTID    Cost    Disabled    Shutdown      Topology Name
        0           1         no          no            Base
  Transmit Delay is 1 sec, State DR, Priority 1
  Designated Router (ID) 192.168.1.1, Interface address 10.1.1.1
  No backup designated router on this network
  Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
    oob-resync timeout 40
    No Hellos (Passive interface) 
  Supports Link-local Signaling (LLS)
  Cisco NSF helper support enabled
  IETF NSF helper support enabled
  Index 1/2/2, flood queue length 0
  Next 0x0(0)/0x0(0)/0x0(0)
  Last flood scan length is 0, maximum is 0
  Last flood scan time is 0 msec, maximum is 0 msec
  Neighbor Count is 0, Adjacent neighbor count is 0 
  Suppress hello for 0 neighbor(s)


GigabitEthernet0/1 is up, line protocol is up 
  Internet Address 10.123.4.1/24, Area 0, Attached via Network Statement
  Process ID 1, Router ID 192.168.1.1, Network Type BROADCAST, Cost: 1
  Topology-MTID    Cost    Disabled    Shutdown      Topology Name
        0           1         no          no            Base
  Transmit Delay is 1 sec, State DR, Priority 1
  Designated Router (ID) 192.168.1.1, Interface address 10.123.4.1
  Backup Designated router (ID) 192.168.2.2, Interface address 10.123.4.2
  Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
    oob-resync timeout 40
    Hello due in 00:00:05
  Supports Link-local Signaling (LLS)
  Cisco NSF helper support enabled
  IETF NSF helper support enabled
  Index 1/1/1, flood queue length 0
  Next 0x0(0)/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 192.168.2.2  (Backup Designated Router)
  Suppress hello for 0 neighbor(s)

 

show ip ospf interface brief

show ip ospf interfaceコマンドの要約版です。

Nbrs F/Cは、2つに分かれてるように見えますが、実際は「NbrsF」「NbrsC」の2つです。

NbrsFは、Fullyadjancent、つまりFull状態の時に1と表示されます。

NbrsCは、2-way状態。つまりDROTHER同士だと1と表示されます。

DROTHER以外の状態でも、NbrsCが1と表示されているのは、恐らく、Full状態になるまでの間に2wayを通過するからだと思います。(あくまで推測です)

 

R1#show ip ospf interface brief
Interface    PID   Area     IP Address/Mask    Cost  State Nbrs F/C
Lo0             1     0           192.168.1.1/32     1      LOOP    0/0
Gi0/2          1     0           10.1.1.1/24          1       DR        0/0
Gi0/1          1     0           10.123.4.1/24      1       DR        1/1

 

R1(config)#do sh ip ospf interface brief
Interface    PID   Area            IP Address/Mask    Cost  State Nbrs F/C
Lo0          1     0               192.168.1.1/32     1     LOOP  0/0
Gi0/2        1     0               10.1.1.1/24        1     DROTH 0/1
Gi0/1        1     0               10.123.4.1/24      1     DR    1/1

 

R5(config)#do sh ip ospf interface brief
Interface    PID   Area            IP Address/Mask    Cost  State Nbrs F/C
Gi0/2        1     0               10.1.1.2/24        1     DROTH 0/1

 

show ip ospf neighbor

ネイバー状態の確認。

Dead Timeは、Helloパケットを受信してからの経過時間を表しています。

構成がbroadcastで、設定も変更していないので、Hello interval Dead intervalは、

10/40 (sec)

上記の状態であれば、Dead Timeは30秒以下にはならないですが

passive interfaceや障害などで、Helloパケットが届かなくなると、30未満になります。

 

R1#show ip ospf neighbor

Neighbor ID     Pri      State                 Dead Time   Address         Interface
10.1.1.2             0   2WAY/DROTHER    00:00:33    10.1.1.2         GigabitEthernet0/2
192.168.2.2       1   FULL/BDR              00:00:31    10.123.4.2      GigabitEthernet0/1

 

Neighbor ID     Pri   State           Dead Time   Address         Interface
10.1.1.2          0   2WAY/DROTHER    00:00:25    10.1.1.2        GigabitEthernet0/2
192.168.2.2       1   FULL/BDR        00:00:35    10.123.4.2      GigabitEthernet0/1

 

show io ospf neighbor detail

R1#show ip ospf neighbor detail 
 Neighbor 10.1.1.2, interface address 10.1.1.2
    In the area 0 via interface GigabitEthernet0/2
    Neighbor priority is 0, State is 2WAY, 7 state changes
    DR is 0.0.0.0 BDR is 0.0.0.0
    Options is 0x12 in Hello (E-bit, L-bit)
    LLS Options is 0x1 (LR)
    Dead timer due in 00:00:33
    Neighbor is up for 00:11:56
    Index 0/0/0, retransmission queue length 0, number of retransmission 0
    First 0x0(0)/0x0(0)/0x0(0) Next 0x0(0)/0x0(0)/0x0(0)
    Last retransmission scan length is 0, maximum is 0
    Last retransmission scan time is 0 msec, maximum is 0 msec
 Neighbor 192.168.2.2, interface address 10.123.4.2
    In the area 0 via interface GigabitEthernet0/1
    Neighbor priority is 1, State is FULL, 6 state changes
    DR is 10.123.4.1 BDR is 10.123.4.2
    Options is 0x12 in Hello (E-bit, L-bit)
    Options is 0x52 in DBD (E-bit, L-bit, O-bit)
    LLS Options is 0x1 (LR)
    Dead timer due in 00:00:31
    Neighbor is up for 03:00:51
    Index 1/1/1, retransmission queue length 0, number of retransmission 1
    First 0x0(0)/0x0(0)/0x0(0) Next 0x0(0)/0x0(0)/0x0(0)
    Last retransmission scan length is 1, maximum is 1
    Last retransmission scan time is 0 msec, maximum is 0 msec

 

show ip route ospf

OSPFで学習した経路だけを表示します。Oは、同じエリア内

別エリアだとOIAになったりと、エリアIDによって表記が変わります。

 

R5#show ip route ospf 

Gateway of last resort is not set

      10.0.0.0/8 is variably subnetted, 4 subnets, 2 masks
O        10.2.2.0/24 [110/3] via 10.1.1.1, 00:00:38, GigabitEthernet0/2
O        10.123.4.0/24 [110/2] via 10.1.1.1, 00:00:38, GigabitEthernet0/2
      192.168.1.0/32 is subnetted, 1 subnets
O        192.168.1.1 [110/2] via 10.1.1.1, 00:00:38, GigabitEthernet0/2
      192.168.2.0/32 is subnetted, 1 subnets
O        192.168.2.2 [110/3] via 10.1.1.1, 00:00:38, GigabitEthernet0/2

パッシブインターフェース

OSPFを有効にしたくないインターフェースで利用する。

パッシブインターフェースで指定すると、HelloPacketなどの送信を止めることができる。

OSPFのに参加させたいセグメントが10あり、1つだけ無効にしたい場合

10全てを1つずつnetworkコマンドを書いてたらコンフィグ量が多くなり大変なので

0.0.0.0 255.255.255.255で全てのセグメントを有効にした後、パッシブインターフェースで1つだけ無効にするほうが早い。

 

設定前

GI0/2からHelloパケットが送信されてます。

*Feb 12 02:32:28.079: OSPF-1 HELLO Gi0/2: Send hello to 224.0.0.5 area 0 from 10.1.1.1
*Feb 12 02:32:28.933: OSPF-1 HELLO Gi0/1: Rcv hello from 192.168.2.2 area 0 10.123.4.2
*Feb 12 02:32:31.387: OSPF-1 HELLO Gi0/1: Send hello to 224.0.0.5 area 0 from 10.123.4.1

 

コンフィグ

R1(config)#router ospf 1
R1(config-router)#passive-interface gigabitEthernet 0/2

 

設定後

Gi0/2からHelloパケットの送信が止まってます。

R1(config)#do debug ip ospf hello
OSPF hello debugging is on
R1(config)#
*Feb 12 02:33:36.878: OSPF-1 HELLO Gi0/1: Send hello to 224.0.0.5 area 0 from 10.123.4.1
*Feb 12 02:33:45.152: OSPF-1 HELLO Gi0/1: Rcv hello from 192.168.2.2 area 0 10.123.4.2
*Feb 12 02:33:46.684: OSPF-1 HELLO Gi0/1: Send hello to 224.0.0.5 area 0 from 10.123.4.1
*Feb 12 02:33:54.545: OSPF-1 HELLO Gi0/1: Rcv hello from 192.168.2.2 area 0 10.123.4.2
*Feb 12 02:33:55.806: OSPF-1 HELLO Gi0/1: Send hello to 224.0.0.5 area 0 from 10.123.4.1

 

デフォルトルートの広報

f:id:slavex:20220212153727p:plain

R1に、R5向けのデフォルトルートを設定し、R1からR2にデフォルトルートを広報します。

設定前

R2#show ip route
Gateway of last resort is not set

      10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks
O        10.1.1.0/24 [110/2] via 10.123.4.1, 01:12:55, GigabitEthernet0/1
C        10.2.2.0/24 is directly connected, GigabitEthernet0/2
L        10.2.2.2/32 is directly connected, GigabitEthernet0/2
C        10.123.4.0/24 is directly connected, GigabitEthernet0/1
L        10.123.4.2/32 is directly connected, GigabitEthernet0/1
      192.168.1.0/32 is subnetted, 1 subnets
O        192.168.1.1 [110/2] via 10.123.4.1, 04:23:08, GigabitEthernet0/1
      192.168.2.0/32 is subnetted, 1 subnets
C        192.168.2.2 is directly connected, Loopback0

R1のコンフィグ

R1(config)#$0.0.0 0.0.0.0 gigabitEthernet 0/2 10.1.1.2 name Default-Route   

R1(config-router)#default-information originate 

 

設定後

R2#show ip route

Gateway of last resort is 10.123.4.1 to network 0.0.0.0

O*E2  0.0.0.0/0 [110/1] via 10.123.4.1, 00:00:00, GigabitEthernet0/1
      10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks
O        10.1.1.0/24 [110/2] via 10.123.4.1, 01:12:58, GigabitEthernet0/1
C        10.2.2.0/24 is directly connected, GigabitEthernet0/2
L        10.2.2.2/32 is directly connected, GigabitEthernet0/2
C        10.123.4.0/24 is directly connected, GigabitEthernet0/1
L        10.123.4.2/32 is directly connected, GigabitEthernet0/1
      192.168.1.0/32 is subnetted, 1 subnets
O        192.168.1.1 [110/2] via 10.123.4.1, 04:23:11, GigabitEthernet0/1
      192.168.2.0/32 is subnetted, 1 subnets

 

「always」オプションをつけると、デフォルトルートが登録されていないルーターでも

デフォルトルートを広報できます。

設定前

R1(config-router)#do sh ip route

Gateway of last resort is not set

      10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks
C        10.1.1.0/24 is directly connected, GigabitEthernet0/2
L        10.1.1.1/32 is directly connected, GigabitEthernet0/2
O        10.2.2.0/24 [110/2] via 10.123.4.2, 04:30:44, GigabitEthernet0/1
C        10.123.4.0/24 is directly connected, GigabitEthernet0/1
L        10.123.4.1/32 is directly connected, GigabitEthernet0/1
      192.168.1.0/32 is subnetted, 1 subnets
C        192.168.1.1 is directly connected, Loopback0
      192.168.2.0/32 is subnetted, 1 subnets
O        192.168.2.2 [110/2] via 10.123.4.2, 04:30:44, GigabitEthernet0/1

 

R1のコンフィグ

R1(config-router)#default-information originate always

 

設定後

R1(config-router)#do sh ip route
Codes: L - local, C - connected, S - static, 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
       i - IS-IS, su - IS-IS summary, 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, H - NHRP, l - LISP
       a - application route
       + - replicated route, % - next hop override, p - overrides from PfR

Gateway of last resort is not set

      10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks
C        10.1.1.0/24 is directly connected, GigabitEthernet0/2
L        10.1.1.1/32 is directly connected, GigabitEthernet0/2
O        10.2.2.0/24 [110/2] via 10.123.4.2, 04:33:19, GigabitEthernet0/1
C        10.123.4.0/24 is directly connected, GigabitEthernet0/1
L        10.123.4.1/32 is directly connected, GigabitEthernet0/1
      192.168.1.0/32 is subnetted, 1 subnets
C        192.168.1.1 is directly connected, Loopback0
      192.168.2.0/32 is subnetted, 1 subnets
O        192.168.2.2 [110/2] via 10.123.4.2, 04:33:19, GigabitEthernet0/1

 

R2#show ip route

Gateway of last resort is 10.123.4.1 to network 0.0.0.0

O*E2  0.0.0.0/0 [110/1] via 10.123.4.1, 00:00:04, GigabitEthernet0/1
      10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks
O        10.1.1.0/24 [110/2] via 10.123.4.1, 01:20:41, GigabitEthernet0/1
C        10.2.2.0/24 is directly connected, GigabitEthernet0/2
L        10.2.2.2/32 is directly connected, GigabitEthernet0/2
C        10.123.4.0/24 is directly connected, GigabitEthernet0/1
L        10.123.4.2/32 is directly connected, GigabitEthernet0/1
      192.168.1.0/32 is subnetted, 1 subnets
O        192.168.1.1 [110/2] via 10.123.4.1, 04:30:54, GigabitEthernet0/1
      192.168.2.0/32 is subnetted, 1 subnets
C        192.168.2.2 is directly connected, Loopback0

 

 

 

シーケンス番号

送られてきたLSAが最新か判断するための番号です。

32ビット16進数で表記され、番号が大きいLSAの方が最新と判断します。

LSAは30分間隔でフラッディングします。

フラッディング毎に経過時間はリセットされ、シーケンス番号が+1されます。

更新されないLSAは、LSDBから削除されます。

 

メトリック

OSPFのメトリックは、「コスト」です。

コストの値は、帯域幅によって変わります。

ただし、100Mbps以上は、全て「1」になり、最適な経路選択ができないです。

理由は、下記計算式で計算し、小数点は考慮しないからです。

 

コスト=参照帯域幅(100Mbps) / インターフェース帯域幅(Mbps)

 

インターフェースが100Mbpsの場合、100Mbps/100Mbps = 1

インターフェースが1Gbpsの場合、100Mbps / 1000Mbps = 0.1→1

 

上記の解決式として2つあります。

・参照帯域幅の変更

 (config-router)#auto-cost reference-bandwidth <参照帯域幅>

上記設定は、全てのOSPFルーターで共通(一致)させる

 (SPFアルゴリズムの計算による、ループを防止に影響が出るため)

 

・手動でコスト値を設定

(config-if)#ip ospf cost <コスト値>

 

OSPFのタイマー

Hello Timer

Helloパケットの送信間隔。変更コマンドは下記の通り。

ネットワークタイプによって、デフォルトの値が変わる。

※変更する場合は、必ず対向と合わせること。

R2(config-if)#ip ospf hello-interval ?
  <1-65535>  Seconds

 

Dead Interval Timer

Helloパケットを受信できなくなってから、ダウンと判断するまでの時間

変更コマンドは下記の通り。ネットワークタイプによって、デフォルトの値が変わる。

R2(config-if)#ip ospf dead-interval ?
  <1-65535>  Seconds
  minimal    Set to 1 second