实验拓扑
实验要求
1.使用双点双向重发布
2.所有路由器进行最佳选路
3.存在备份路径,不得出现环路,和路由回馈
4.R1除本身环回外,外加几条环回
172.16.1.0/24 deny
172.16.2.0/24 type 1
172.16.3.0/24 cost 6
172.16.4.0/24 type 1 cost 9
更改如上参数
实验内容
首先给每一台路由器上配置上相应的ip地址
R1
#
interface GigabitEthernet0/0/0
ip address 12.1.1.1 255.255.255.0
#
interface GigabitEthernet0/0/1
ip address 14.1.1.1 255.255.255.0
#
interface GigabitEthernet0/0/2
#
interface NULL0
#
interface LoopBack0
ip address 1.1.1.1 255.255.255.0
#
interface LoopBack1
ip address 172.16.1.1 255.255.255.0
#
interface LoopBack2
ip address 172.16.2.1 255.255.255.0
#
interface LoopBack3
ip address 172.16.3.1 255.255.255.0
#
interface LoopBack4
ip address 172.16.4.1 255.255.255.0
#
R2
[Huawei]sys r2
[r2]int g0/0/0
[r2-GigabitEthernet0/0/0]ip add 12.1.1.2 24
[r2-GigabitEthernet0/0/0]int lo2
[r2-LoopBack2]ip add 2.2.2.2 24
[r2-LoopBack2]int g0/0/1
[r2-GigabitEthernet0/0/1]ip add 23.1.1.1 24
R3
interface GigabitEthernet0/0/0
ip address 23.1.1.2 255.255.255.0
#
interface GigabitEthernet0/0/1
ip address 34.1.1.1 255.255.255.0
#
interface GigabitEthernet0/0/2
#
interface NULL0
#
interface LoopBack0
ip address 3.3.3.3 255.255.255.0
#
R4
[Huawei]sys r4
[r4]int lo0
[r4-LoopBack0]ip add 4.4.4.4 24
[r4-LoopBack0]int g0/0/0
[r4-GigabitEthernet0/0/0]ip add 14.1.1.2 24
[r4-GigabitEthernet0/0/0]int g0/0/1
[r4-GigabitEthernet0/0/1]ip add 34.1.1.2 24
接着就是根据题意,我们在对应的路由器上起相应的协议
R1
rip 1
version 2
network 12.0.0.0
network 14.0.0.0
network 1.0.0.0
network 172.16.0.0
#
R2
[r2]rip 1
[r2-rip-1]v 2
[r2-rip-1]net
[r2-rip-1]network 2.0.0.0
[r2-rip-1]net
[r2-rip-1]network 12.0.0.0
[r2-rip-1]q
[r2]ospf 1
[r2-ospf-1]a 0
[r2-ospf-1-area-0.0.0.0]net
[r2-ospf-1-area-0.0.0.0]network 23.1.1.1 0.0.0.0
R3
#
ospf 1
area 0.0.0.0
network 3.3.3.0 0.0.0.255
network 23.1.1.0 0.0.0.255
network 34.1.1.0 0.0.0.255
#
R4
[r4]rip 1
[r4-rip-1]v 2
[r4-rip-1]net
[r4-rip-1]network 14.0.0.0
[r4-rip-1]q
[r4]ospf 1
[r4-ospf-1]a 0
[r4-ospf-1-area-0.0.0.0]net
[r4-ospf-1-area-0.0.0.0]network 4.4.4.4 0.0.0.0
[r4-ospf-1-area-0.0.0.0]net
[r4-ospf-1-area-0.0.0.0]network 34.1.1.2 0.0.0.0
然后根据要求4的配置,进行改变
我们则需要去做路由策略
分别在R2和R4上
R2
[r2]ip ip-prefix 1 per
[r2]ip ip-prefix 1 permit 172.16.1.0 24
[r2]ip ip
[r2]ip ip-prefix 2 per
[r2]ip ip-prefix 2 permit 172.16.2.0 24
[r2]ip ip
[r2]ip ip-prefix 3 per
[r2]ip ip-prefix 3 permit 172.16.3.0 24
[r2]ip ip
[r2]ip ip-prefix 4 per
[r2]ip ip-prefix 4 permit 172.16.4.0 24
[r2]route-policy huawei deny node 10
Info: New Sequence of this List.
[r2-route-policy]if
[r2-route-policy]if-match ip
[r2-route-policy]if-match ip
[r2-route-policy]if-match ip-prefix 1
[r2-route-policy]q
[r2]rou
[r2]route-policy huawei per
[r2]route-policy huawei permit node 20
Info: New Sequence of this List.
[r2-route-policy]if
[r2-route-policy]if-match ip-
[r2-route-policy]if-match ip-prefix ty
[r2-route-policy]if-match ip-prefix ?
STRING<1-169> Specify prefix-list name
[r2-route-policy]if-match ip-prefix 2
[r2-route-policy]app
[r2-route-policy]apply cost-
[r2-route-policy]apply cost-type co
[r2-route-policy]apply cost-type type
[r2-route-policy]apply cost-type type-1
[r2-route-policy]q
[r2]rou
[r2]route-policy huawei per
[r2]route-policy huawei permit node 30
Info: New Sequence of this List.
[r2-route-policy]if
[r2-route-policy]if-match ip-
[r2-route-policy]if-match ip-prefix 3
[r2-route-policy]apply cost 6
[r2-route-policy]q
[r2]route-policy huawei per
[r2]route-policy huawei permit node 40
Info: New Sequence of this List.
[r2-route-policy]if
[r2-route-policy]if-match ip-
[r2-route-policy]if-match ip-prefix 4
[r2-route-policy]apply cost-type type-1
[r2-route-policy]apply cost 9
[r2-route-policy]q
[r2]route-policy huawei permit node 50
在R4上
[r4]ip ip-
[r4]ip ip-prefix 1 per
[r4]ip ip-prefix 1 permit 172.16.1.0 24
[r4]ip ip-
[r4]ip ip-prefix 2 per
[r4]ip ip-prefix 2 permit 172.16.2.0 24
[r4]ip ip-
[r4]ip ip-prefix 3 per
[r4]ip ip-prefix 3 permit 172.16.3.0 24
[r4]ip ip-
[r4]ip ip-prefix 4 per
[r4]ip ip-prefix 4 permit 172.16.4.0 24
[r4]route-
[r4]route-policy huawei deny node 10
Info: New Sequence of this List.
[r4-route-policy]if
[r4-route-policy]if-match ip-
[r4-route-policy]if-match ip-prefix 1
[r4-route-policy]q
[r4]route-
[r4]route-policy huawei per
[r4]route-policy huawei permit node 20
Info: New Sequence of this List.
[r4-route-policy]if
[r4-route-policy]if-match ip-
[r4-route-policy]if-match ip-prefix 2
[r4-route-policy]apply cost-
[r4-route-policy]apply cost-type type
[r4-route-policy]apply cost-type type-1
[r4-route-policy]q
[r4]route-policy huawei per
[r4]route-policy huawei permit node 30
Info: New Sequence of this List.
[r4-route-policy]if
[r4-route-policy]if-match ip-
[r4-route-policy]if-match ip-prefix 3
[r4-route-policy]apply cost 6
[r4-route-policy]q
[r4]route-
[r4]route-policy huawei per
[r4]route-policy huawei permit node 40
Info: New Sequence of this List.
[r4-route-policy]if
[r4-route-policy]if-match ip-
[r4-route-policy]if-match ip-prefix 4
[r4-route-policy]apply cost 9
[r4-route-policy]apply cost-
[r4-route-policy]apply cost-type ty
[r4-route-policy]apply cost-type type-1
[r4-route-policy]q
[r4]route-policy huawei per
[r4]route-policy huawei permit node 50
写完对于R4的路由策略,然后就可以在重发布的时候,将策略进行应用
R2
[r2]ospf 1
[r2-ospf-1]imp
[r2-ospf-1]import-route rip 1 hua
[r2-ospf-1]import-route rip 1 rou
[r2-ospf-1]import-route rip 1 route-policy huawei
[r2-ospf-1]q
[r2]rip 1
[r2-rip-1]imp
[r2-rip-1]import-route ospf 1 rou
[r2-rip-1]import-route ospf 1 route-policy huawei
R4
[r4]rip 1
[r4-rip-1]imp
[r4-rip-1]import-route ospf 1 rou
[r4-rip-1]import-route ospf 1 route-policy huawei
[r4-rip-1]q
[r4]ospf 1
[r4-ospf-1]imp
[r4-ospf-1]import-route rip 1 rou
[r4-ospf-1]import-route rip 1 route-policy huawei
接着可以在R1或者R3上查看你的策略是否做成功了
R3
<r3>display ospf routing
OSPF Process 1 with Router ID 23.1.1.2
Routing Tables
Routing for Network
Destination Cost Type NextHop AdvRouter Area
3.3.3.3/32 0 Stub 3.3.3.3 23.1.1.2 0.0.0.0
23.1.1.0/24 1 Transit 23.1.1.2 23.1.1.2 0.0.0.0
34.1.1.0/24 1 Transit 34.1.1.1 23.1.1.2 0.0.0.0
4.4.4.4/32 1 Stub 34.1.1.2 14.1.1.2 0.0.0.0
Routing for ASEs
Destination Cost Type Tag NextHop AdvRouter
1.1.1.0/24 1 Type2 1 23.1.1.1 12.1.1.2
1.1.1.0/24 1 Type2 1 34.1.1.2 14.1.1.2
2.2.2.0/24 1 Type2 1 23.1.1.1 12.1.1.2
2.2.2.0/24 1 Type2 1 34.1.1.2 14.1.1.2
4.4.4.0/24 1 Type2 1 23.1.1.1 12.1.1.2
12.1.1.0/24 1 Type2 1 23.1.1.1 12.1.1.2
12.1.1.0/24 1 Type2 1 34.1.1.2 14.1.1.2
14.1.1.0/24 1 Type2 1 23.1.1.1 12.1.1.2
14.1.1.0/24 1 Type2 1 34.1.1.2 14.1.1.2
172.16.2.0/24 2 Type1 1 23.1.1.1 12.1.1.2
172.16.2.0/24 2 Type1 1 34.1.1.2 14.1.1.2
172.16.3.0/24 6 Type2 1 23.1.1.1 12.1.1.2
172.16.3.0/24 6 Type2 1 34.1.1.2 14.1.1.2
172.16.4.0/24 10 Type1 1 23.1.1.1 12.1.1.2
172.16.4.0/24 10 Type1 1 34.1.1.2 14.1.1.2
Total Nets: 19
Intra Area: 4 Inter Area: 0 ASE: 15 NSSA: 0
然后就是解决路由回馈问题了
通常有两种做法
1.修改路径的cost值
2.使用路由策略
这里我选择路由策略(偏移列表)
查看R3的路由表
<r3>display ip routing-table protocol ospf
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 9 Routes : 16
OSPF routing table status : <Active>
Destinations : 9 Routes : 16
Destination/Mask Proto Pre Cost Flags NextHop Interface
1.1.1.0/24 O_ASE 150 1 D 23.1.1.1 GigabitEthernet
0/0/0
O_ASE 150 1 D 34.1.1.2 GigabitEthernet
0/0/1
2.2.2.0/24 O_ASE 150 1 D 23.1.1.1 GigabitEthernet
0/0/0
O_ASE 150 1 D 34.1.1.2 GigabitEthernet
0/0/1
4.4.4.0/24 O_ASE 150 1 D 23.1.1.1 GigabitEthernet
0/0/0
4.4.4.4/32 OSPF 10 1 D 34.1.1.2 GigabitEthernet
0/0/1
12.1.1.0/24 O_ASE 150 1 D 23.1.1.1 GigabitEthernet
0/0/0
O_ASE 150 1 D 34.1.1.2 GigabitEthernet
0/0/1
14.1.1.0/24 O_ASE 150 1 D 23.1.1.1 GigabitEthernet
0/0/0
O_ASE 150 1 D 34.1.1.2 GigabitEthernet
0/0/1
172.16.2.0/24 O_ASE 150 2 D 23.1.1.1 GigabitEthernet
0/0/0
O_ASE 150 2 D 34.1.1.2 GigabitEthernet
0/0/1
172.16.3.0/24 O_ASE 150 6 D 34.1.1.2 GigabitEthernet
0/0/1
O_ASE 150 6 D 23.1.1.1 GigabitEthernet
0/0/0
172.16.4.0/24 O_ASE 150 10 D 23.1.1.1 GigabitEthernet
0/0/0
O_ASE 150 10 D 34.1.1.2 GigabitEthernet
0/0/1
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0
这里我们发现路径不佳主要来自于12网段和14网段
学习14网段的23网段
学习12网段的34网段
所有在R2上
[r2]ip ip-
[r2]ip ip-prefix per
[r2]ip ip-prefix x per
[r2]ip ip-prefix x permit 14.1.1.0 24
[r2]route-policy hu deny node 10
Info: New Sequence of this List.
[r2-route-policy]if
[r2-route-policy]if-match ip-
[r2-route-policy]if-match ip-prefix x
[r2-route-policy]q
[r2]route-policy hu per
[r2]route-policy hu permit node 20
在R4上
[r4]ip ip-
[r4]ip ip-prefix x per
[r4]ip ip-prefix x permit 12.1.1.0 24
[r4]route-
[r4]route-policy hu deny ip-
[r4]route-policy hu deny node 10
Info: New Sequence of this List.
[r4-route-policy]if
[r4-route-policy]if-match ip-
[r4-route-policy]if-match ip-prefix x
[r4]route-policy hu permit node 20
[r4-route-policy]q
[r4]rip 1
[r4-rip-1]i
[r4-rip-1]import-route ospf 1 rou
[r4-rip-1]import-route ospf 1 route-policy hu
[r4-rip-1]q
[r4]ospf 1
[r4-ospf-1]imp
[r4-ospf-1]import-route rip 1 rou
[r4-ospf-1]import-route rip 1 route-policy hu
注:这里一定要写一个定义的空list,代表允许所有。
看R3的路由表
<r3>display ip routing-table protocol ospf
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 10 Routes : 16
OSPF routing table status : <Active>
Destinations : 10 Routes : 16
Destination/Mask Proto Pre Cost Flags NextHop Interface
1.1.1.0/24 O_ASE 150 1 D 23.1.1.1 GigabitEthernet
0/0/0
O_ASE 150 1 D 34.1.1.2 GigabitEthernet
0/0/1
2.2.2.0/24 O_ASE 150 1 D 23.1.1.1 GigabitEthernet
0/0/0
O_ASE 150 1 D 34.1.1.2 GigabitEthernet
0/0/1
4.4.4.0/24 O_ASE 150 1 D 23.1.1.1 GigabitEthernet
0/0/0
4.4.4.4/32 OSPF 10 1 D 34.1.1.2 GigabitEthernet
0/0/1
12.1.1.0/24 O_ASE 150 1 D 23.1.1.1 GigabitEthernet
0/0/0
14.1.1.0/24 O_ASE 150 1 D 34.1.1.2 GigabitEthernet
0/0/1
172.16.1.0/24 O_ASE 150 1 D 23.1.1.1 GigabitEthernet
0/0/0
O_ASE 150 1 D 34.1.1.2 GigabitEthernet
0/0/1
172.16.2.0/24 O_ASE 150 1 D 23.1.1.1 GigabitEthernet
0/0/0
O_ASE 150 1 D 34.1.1.2 GigabitEthernet
0/0/1
172.16.3.0/24 O_ASE 150 1 D 23.1.1.1 GigabitEthernet
0/0/0
O_ASE 150 1 D 34.1.1.2 GigabitEthernet
0/0/1
172.16.4.0/24 O_ASE 150 1 D 23.1.1.1 GigabitEthernet
0/0/0
O_ASE 150 1 D 34.1.1.2 GigabitEthernet
0/0/1
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0
这样12网段 14网段所选的路为最佳。
查看R1的路由表,会发现23网段和34网段也选路不佳,原理为一样的,解决方法也为一样的。
实验结束。