1.配置ip
r1:
GigabitEthernet0/0/0 12.1.1.1/24 up up
GigabitEthernet0/0/1 unassigned down down
GigabitEthernet0/0/2 unassigned down down
LoopBack0 192.168.1.1/24 up up(s)
NULL0 unassigned up up(s)
r2:
GigabitEthernet0/0/0 12.1.1.2/24 up up
GigabitEthernet0/0/1 23.1.1.1/24 up up
GigabitEthernet0/0/2 unassigned down down
NULL0 unassigned up up(s)
r3:
GigabitEthernet0/0/0 23.1.1.2/24 up up
GigabitEthernet0/0/1 34.1.1.1/24 up up
GigabitEthernet0/0/2 unassigned down down
NULL0 unassigned up up(s)
r4:
GigabitEthernet0/0/0 34.1.1.2/24 up up
GigabitEthernet0/0/1 45.1.1.1/24 up up
GigabitEthernet0/0/2 unassigned down down
NULL0 unassigned up up(s)
r5:
GigabitEthernet0/0/0 45.1.1.2/24 up up
GigabitEthernet0/0/1 unassigned down down
GigabitEthernet0/0/2 unassigned down down
LoopBack0 192.168.5.1/24 up up(s)
NULL0 unassigned up up(s)
2.ospf宣告
r1:
[r1]ospf 1 router-id 1.1.1.1
[r1-ospf-1]area 0
[r1-ospf-1-area-0.0.0.0]net 192.168.1.0 0.0.0.255
[r1-ospf-1-area-0.0.0.0]net 12.1.1.0 0.0.0.255
r2:
[r2]ospf 1 router-id 2.2.2.2
[r2-ospf-1]area 0
[r2-ospf-1-area-0.0.0.0]net 12.1.1.0 0.0.0.255
[r2-ospf-1-area-0.0.0.0]area 1
[r2-ospf-1-area-0.0.0.1]net 23.1.1.0 0.0.0.255
r3:
[r3]ospf 1 router-id 3.3.3.3
[r3-ospf-1]area 1
[r3-ospf-1-area-0.0.0.1]net 23.1.1.0 0.0.0.255
[r3-ospf-1-area-0.0.0.1]net 34.1.1.0 0.0.0.255
r4:
[r4]ospf 1 router-id 4.4.4.4
[r4-ospf-1-area-0.0.0.0]area 1
[r4-ospf-1-area-0.0.0.1]net 34.1.1.0 0.0.0.255
[r4-ospf-1-area-0.0.0.1]area 2
[r4-ospf-1-area-0.0.0.2]net 45.1.1.0 0.0.0.255
r5:
[r5]ospf 1 router-id 5.5.5.5
[r5-ospf-1]area 2
[r5-ospf-1-area-0.0.0.2]net 45.1.1.0 0.0.0.255
[r5-ospf-1-area-0.0.0.2]net 192.168.5.0 0.0.0.2
3.查看路由信息
r1]dis ip routing-table pro ospf
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 2 Routes : 2
OSPF routing table status : <Active>
Destinations : 2 Routes : 2
Destination/Mask Proto Pre Cost Flags NextHop Interface
23.1.1.0/24 OSPF 10 2 D 12.1.1.2 GigabitEthernet0/0/0
34.1.1.0/24 OSPF 10 3 D 12.1.1.2 GigabitEthernet0/0/0
r1未获取到区域2 45网络路由和5的环回
[r5]dis ip routing-table pro ospf
r5什么也学不到
因此需要接下来两种方法
法一:隧道
法二:虚链路
4.隧道(在r2和r4上做注:r2和r4必须同时在一个区域做(0或者2))
r2:
[r2]inter tu0/0/0
[r2-Tunnel0/0/0]ip add 10.1.1.1 24
[r2-Tunnel0/0/0]tu
[r2-Tunnel0/0/0]tunnel-protocol gre
[r2-Tunnel0/0/0]sou
[r2-Tunnel0/0/0]source 23.1.1.2
[r2-Tunnel0/0/0]des
[r2-Tunnel0/0/0]dest
[r2-Tunnel0/0/0]source 23.1.1.1
[r2-Tunnel0/0/0]dest 34.1.1.2
[r2]ospf 1
[r2-ospf-1]area 0
[r2-ospf-1-area-0.0.0.0]net 10.1.1.0 0.0.0.255
r4:
[r4]inter tu0/0/0
[r4-Tunnel0/0/0]ip add 10.1.1.2 24
[r4-Tunnel0/0/0]tu
[r4-Tunnel0/0/0]tunnel-protocol gre
[r4-Tunnel0/0/0]sou
[r4-Tunnel0/0/0]source 34.1.1.2
[r4-Tunnel0/0/0]destination 23.1.1.1
[r4-Tunnel0/0/0]ospf 1
[r4-ospf-1]area 0
[r4-ospf-1-area-0.0.0.0]net 10.1.1.0 0.0.0.255
测试
<r1>dis ip routing-table pro ospf
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 5 Routes : 5
OSPF routing table status : <Active>
Destinations : 5 Routes : 5
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.1.1.0/24 OSPF 10 1563 D 12.1.1.2 GigabitEthernet0/0/0
23.1.1.0/24 OSPF 10 2 D 12.1.1.2 GigabitEthernet0/0/0
34.1.1.0/24 OSPF 10 3 D 12.1.1.2 GigabitEthernet0/0/0
45.1.1.0/24 OSPF 10 1564 D 12.1.1.2 GigabitEthernet0/0/0
192.168.5.1/32 OSPF 10 1564 D 12.1.1.2 GigabitEthernet0/0/0
<r1>ping 192.168.5.1
PING 192.168.5.1: 56 data bytes, press CTRL_C to break
Reply from 192.168.5.1: bytes=56 Sequence=1 ttl=253 time=30 ms
Reply from 192.168.5.1: bytes=56 Sequence=2 ttl=253 time=50 ms
Reply from 192.168.5.1: bytes=56 Sequence=3 ttl=253 time=40 ms
Reply from 192.168.5.1: bytes=56 Sequence=4 ttl=253 time=40 ms
Reply from 192.168.5.1: bytes=56 Sequence=5 ttl=253 time=40 ms
5.虚链路(须先删除隧道 注:两必须连接同一非骨干,所以也是进入此非骨干做虚链路邻居 为对方router id)
[r2]ospf 1
[r2-ospf-1]area 1
[r2-ospf-1-area-0.0.0.1]lin
[r2-ospf-1-area-0.0.0.1]vl
[r2-ospf-1-area-0.0.0.1]vlink-peer 4.4.4.4
[r4]ospf 1
[r4-ospf-1]area 1
[r4-ospf-1-area-0.0.0.1]vl
[r4-ospf-1-area-0.0.0.1]vlink-peer 2.2.2.2
测试:
<r1>dis ip routing-table pro ospf
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 4 Routes : 4
OSPF routing table status : <Active>
Destinations : 4 Routes : 4
Destination/Mask Proto Pre Cost Flags NextHop Interface
23.1.1.0/24 OSPF 10 2 D 12.1.1.2 GigabitEthernet0/0/0
34.1.1.0/24 OSPF 10 3 D 12.1.1.2 GigabitEthernet0/0/0
45.1.1.0/24 OSPF 10 4 D 12.1.1.2 GigabitEthernet0/0/0
192.168.5.1/32 OSPF 10 4 D 12.1.1.2 GigabitEthernet0/0/0
<r1>ping 192.168.5.1
PING 192.168.5.1: 56 data bytes, press CTRL_C to break
Reply from 192.168.5.1: bytes=56 Sequence=1 ttl=252 time=40 ms
Reply from 192.168.5.1: bytes=56 Sequence=2 ttl=252 time=40 ms
Reply from 192.168.5.1: bytes=56 Sequence=3 ttl=252 time=40 ms
Reply from 192.168.5.1: bytes=56 Sequence=4 ttl=252 time=40 ms
Reply from 192.168.5.1: bytes=56 Sequence=5 ttl=252 time=50 ms