OSPF的原理及配置
(1)OSPF单区域配置
Process ID即OSPF 100中的100。如不特别指定,Process ID默认为1。Process ID是本地的概念,同一个区域的Process ID可以不同。但是生产环境中,同一区域的Process ID建议保持一致,以免混淆。
router-id建议手工配置环回地址。
本地设备只需将直连网段宣告出来即可。
1 OSPF配置
AR1:
interface GigabitEthernet0/0/0
ip address 12.1.1.1 255.255.255.0
interface LoopBack0
ip address 1.1.1.1 255.255.255.0
ospf 100 router-id 1.1.1.1
area 0.0.0.0
network 1.1.1.0 0.0.0.255
network 12.1.1.0 0.0.0.255
AR2:
interface GigabitEthernet0/0/0
ip address 23.1.1.2 255.255.255.0
interface GigabitEthernet0/0/1
ip address 12.1.1.2 255.255.255.0
interface LoopBack0
ip address 2.2.2.2 255.255.255.0
ospf 100 router-id 2.2.2.2
area 0.0.0.0
network 2.2.2.0 0.0.0.255
network 12.1.1.0 0.0.0.255
network 23.1.1.0 0.0.0.255
AR3:
interface GigabitEthernet0/0/1
ip address 23.1.1.3 255.255.255.0
interface LoopBack0
ip address 3.3.3.3 255.255.255.0
ospf 100 router-id 3.3.3.3
area 0.0.0.0
network 3.3.3.0 0.0.0.255
network 23.1.1.0 0.0.0.255
2 OSPF信息查询
[AR2]dis ospf peer
OSPF Process 100 with Router ID 2.2.2.2
Neighbors
Area 0.0.0.0 interface 12.1.1.2(GigabitEthernet0/0/1)'s neighbors
Router ID: 1.1.1.1 Address: 12.1.1.1
State: Full Mode:Nbr is Slave Priority: 1
DR: 12.1.1.1 BDR: 12.1.1.2 MTU: 0
Dead timer due in 39 sec
Retrans timer interval: 5
Neighbor is up for 00:01:44
Authentication Sequence: [ 0 ]
Neighbors
Area 0.0.0.0 interface 23.1.1.2(GigabitEthernet0/0/0)'s neighbors
Router ID: 3.3.3.3 Address: 23.1.1.3
State: Full Mode:Nbr is Master Priority: 1
DR: 23.1.1.2 BDR: 23.1.1.3 MTU: 0
Dead timer due in 36 sec
Retrans timer interval: 5
Neighbor is up for 00:00:26
Authentication Sequence: [ 0 ]
[AR2]dis ospf peer brief
OSPF Process 100 with Router ID 2.2.2.2
Peer Statistic Information
-----------------------------------------------------------------
Area Id Interface Neighbor id State
0.0.0.0 GigabitEthernet0/0/1 1.1.1.1 Full
0.0.0.0 GigabitEthernet0/0/0 3.3.3.3 Full
----------------------------------------------------------------
[AR1]dis ospf peer brief
OSPF Process 100 with Router ID 1.1.1.1
Peer Statistic Information
-----------------------------------------------------------------
Area Id Interface Neighbor id State
0.0.0.0 GigabitEthernet0/0/0 2.2.2.2 Full
-----------------------------------------------------------------
[AR3]dis ospf peer brief
OSPF Process 100 with Router ID 3.3.3.3
Peer Statistic Information
-----------------------------------------------------------------
Area Id Interface Neighbor id State
0.0.0.0 GigabitEthernet0/0/1 2.2.2.2 Full
-----------------------------------------------------------------
3路由查询
[AR1]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.0/24 Direct 0 0 D 1.1.1.1 LoopBack0
1.1.1.1/32 Direct 0 0 D 127.0.0.1 LoopBack0
1.1.1.255/32 Direct 0 0 D 127.0.0.1 LoopBack0
2.2.2.2/32 OSPF 10 1 D 12.1.1.2 GigabitEthernet0/0/0
3.3.3.3/32 OSPF 10 2 D 12.1.1.2 GigabitEthernet0/0/0
12.1.1.0/24 Direct 0 0 D 12.1.1.1 GigabitEthernet0/0/0
12.1.1.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0
12.1.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0
23.1.1.0/24 OSPF 10 2 D 12.1.1.2 GigabitEthernet0/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
127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
[AR1]dis ospf routing
OSPF Process 100 with Router ID 1.1.1.1
Routing Tables
Routing for Network
Destination Cost Type NextHop AdvRouter Area
1.1.1.1/32 0 Stub 1.1.1.1 1.1.1.1 0.0.0.0
12.1.1.0/24 1 Transit 12.1.1.1 1.1.1.1 0.0.0.0
2.2.2.2/32 1 Stub 12.1.1.2 2.2.2.2 0.0.0.0
3.3.3.3/32 2 Stub 12.1.1.2 3.3.3.3 0.0.0.0
23.1.1.0/24 2 Transit 12.1.1.2 2.2.2.2 0.0.0.0
Total Nets: 5
Intra Area: 5 Inter Area: 0 ASE: 0 NSSA: 0
(2)OSPF多区域配置
AR1:
ospf 100 router-id 1.1.1.1
bandwidth-reference 10000
area 0.0.0.0
network 1.1.1.0 0.0.0.255
network 12.1.1.0 0.0.0.255
AR2:
ospf 100 router-id 2.2.2.2
bandwidth-reference 10000
area 0.0.0.0
network 2.2.2.0 0.0.0.255
network 12.1.1.0 0.0.0.255
area 0.0.0.1
network 23.1.1.0 0.0.0.255
AR3:
ospf 100 router-id 3.3.3.3
bandwidth-reference 10000
area 0.0.0.1
network 3.3.3.0 0.0.0.255
network 23.1.1.0 0.0.0.255
[AR2]dis ospf peer
OSPF Process 100 with Router ID 2.2.2.2
Neighbors
Area 0.0.0.0 interface 12.1.1.2(GigabitEthernet0/0/1)'s neighbors
Router ID: 1.1.1.1 Address: 12.1.1.1
State: Full Mode:Nbr is Slave Priority: 1
DR: 12.1.1.2 BDR: 12.1.1.1 MTU: 0
Dead timer due in 34 sec
Retrans timer interval: 5
Neighbor is up for 21:39:05
Authentication Sequence: [ 0 ]
Neighbors
Area 0.0.0.1 interface 23.1.1.2(GigabitEthernet0/0/0)'s neighbors
Router ID: 3.3.3.3 Address: 23.1.1.3
State: Full Mode:Nbr is Master Priority: 1
DR: 23.1.1.2 BDR: 23.1.1.3 MTU: 0
Dead timer due in 36 sec
Retrans timer interval: 5
Neighbor is up for 00:00:07
Authentication Sequence: [ 0 ]
[AR2]dis ospf routing
OSPF Process 100 with Router ID 2.2.2.2
Routing Tables
Routing for Network
Destination Cost Type NextHop AdvRouter Area
2.2.2.2/32 0 Stub 2.2.2.2 2.2.2.2 0.0.0.0
12.1.1.0/24 10 Transit 12.1.1.2 2.2.2.2 0.0.0.0
23.1.1.0/24 10 Transit 23.1.1.2 2.2.2.2 0.0.0.1
1.1.1.1/32 10 Stub 12.1.1.1 1.1.1.1 0.0.0.0
3.3.3.3/32 10 Stub 23.1.1.3 3.3.3.3 0.0.0.1
Total Nets: 5
Intra Area: 5 Inter Area: 0 ASE: 0 NSSA: 0
[AR3]dis ospf routing
OSPF Process 100 with Router ID 3.3.3.3
Routing Tables
Routing for Network
Destination Cost Type NextHop AdvRouter Area
3.3.3.3/32 0 Stub 3.3.3.3 3.3.3.3 0.0.0.1
23.1.1.0/24 10 Transit 23.1.1.3 3.3.3.3 0.0.0.1
1.1.1.1/32 20 Inter-area 23.1.1.2 2.2.2.2 0.0.0.1
2.2.2.2/32 10 Inter-area 23.1.1.2 2.2.2.2 0.0.0.1
12.1.1.0/24 20 Inter-area 23.1.1.2 2.2.2.2 0.0.0.1
Total Nets: 5
Intra Area: 2 Inter Area: 3 ASE: 0 NSSA: 0