一、配置IP地址,启用OSPF以及RIP
如图进行配置
二、进行多点双向重发布、重发布直连
完成该环境应先将R7环回重发布进OSPF环境,再在R2、R3上进行双向重发布;
此时在OSPF环境中,到R7环回的路由到R4上会分别发给R2、R3,此时该路由的优先级为150;
进入RIP环境中,该路由优先级变成100,假设从R2进入从R3出来,再进入OSPF环境,此时R4会学到两条R7环回的路由(R5,R3),他们的优先级都为150;
因为,R3根据优先级会选择由R1学习到的7.7.7.0/24(100)环回路由,会刷新掉由R4学习到的7.7.7.0/24(150)环回路由,此时再重发布给R4;
但是由R5传给R4的路由度量为3,所以R4会选择R3给他的R7环回的路由(度量为1),此时到R4到R7会形成环路;
当该路由由R4传给R5时,该路由度量为2(种子度量+1),R5通过OSPF学习到R7环回的度量也是2,且优先级都为150,此时R5到R7环回会负载均衡;
此时需要合理利用路由策略解决选路不佳,以及环路问题。
先将R7的环回进行重发布
[r7-ospf-1]import-route direct
再将R3、R2双向重发布,此处列举R2的配置
[r2-ospf-1]import-route rip
[r2-rip-1]import-route ospf
三、路由回馈
由于由OSPF学习到的R3环回路由它的掩码是32优先级为10,经由重发布进入RIP环境,R2会学到两条关于R3环回的路由(一个掩码32,一个掩码24),但是由RIP学习的路由的优先级为100,所以它会选择相信由OSPF学习到的那条路由,再传给R1,结果是R1到R3环回就会走12.1.1.0 网段,选路不佳。
[r1]dis ip ro
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 25 Routes : 33
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.0/24 RIP 100 1 D 12.1.1.2 GigabitEthernet0/0/0
3.3.3.0/24 RIP 100 1 D 13.1.1.2 GigabitEthernet0/0/1
3.3.3.3/32 RIP 100 1 D 12.1.1.2 GigabitEthernet0/0/0
<r2>dis ip ro
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 25 Routes : 25
Destination/Mask Proto Pre Cost Flags NextHop Interface
1.1.1.0/24 RIP 100 1 D 12.1.1.1 GigabitEthernet0/0/0
2.2.2.0/24 Direct 0 0 D 2.2.2.2 LoopBack0
2.2.2.2/32 Direct 0 0 D 127.0.0.1 LoopBack0
2.2.2.255/32 Direct 0 0 D 127.0.0.1 LoopBack0
3.3.3.0/24 RIP 100 2 D 12.1.1.1 GigabitEthernet0/0/0
3.3.3.3/32 OSPF 10 2 D 24.1.1.2 GigabitEthernet0/0/1
4.4.4.4/32 OSPF 10 1 D 24.1.1.2 GigabitEthernet0/0/1
解决办法:
1、将R3环回的接口网络类型改为broadcast
2、将该环回接口的掩码改为32
此处选择方法1,执行后R2路由表里就只会有R3环回OSPF的路由
[r3]int loop 0
[r3-LoopBack0]ospf network-type broadcast
<r2>dis ip ro
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 24 Routes : 24
Destination/Mask Proto Pre Cost Flags NextHop Interface
1.1.1.0/24 RIP 100 1 D 12.1.1.1 GigabitEthernet0/0/0
2.2.2.0/24 Direct 0 0 D 2.2.2.2 LoopBack0
2.2.2.2/32 Direct 0 0 D 127.0.0.1 LoopBack0
2.2.2.255/32 Direct 0 0 D 127.0.0.1 LoopBack0
3.3.3.0/24 OSPF 10 2 D 24.1.1.2 GigabitEthernet0/0/1
4.4.4.4/32 OSPF 10 1 D 24.1.1.2 GigabitEthernet0/0/1
四、解决环路
思路在于如何处理RIP环境中通过重发布OSPF进来的7.7.7.0/24路由;
解决办法:
1、令R3不学习由R1传给它的7.7.7.0/24路由:
使用前缀列表在R3上拒绝7.7.7.0/24网段,但是若R3-R4的物理链路出现故障无法连接,R3就无法到达7.7.7.0/24,没有了备用路线。
2、令R3从R1学习到的7.7.7.0/24路由的优先级大于由R4学习到的7.7.7.0/24路由(150)
这样R3就会选择相信由R4传给它的7.7.7.0/24路由,解决掉环路,且有备份线路
使用方法2:
[r3]ip ip-prefix hh permit 7.7.7.0 24
****创建前缀列表用于抓取7.7.7.0/24网段
[r3]route-policy hh permit node 10
Info: New Sequence of this List.
****创建路由策略
[r3-route-policy]if-match ip-prefix hh
****选中前缀列表
[r3-route-policy]apply preference 151
****执行将该前缀列表抓取到的路由的优先级改为151
[r3-rip-1]preference route-policy hh
****在RIP中调用该路由策略
再来查看R3、R4关于7.7.7.0/24的路由表
[r3-rip-1]dis ip ro
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 24 Routes : 24
Destination/Mask Proto Pre Cost Flags NextHop Interface
1.1.1.0/24 RIP 2 1 D 13.1.1.1 GigabitEthernet0/0/1
2.2.2.0/24 RIP 2 2 D 13.1.1.1 GigabitEthernet0/0/1
3.3.3.0/24 Direct 0 0 D 3.3.3.3 LoopBack0
3.3.3.3/32 Direct 0 0 D 127.0.0.1 LoopBack0
3.3.3.255/32 Direct 0 0 D 127.0.0.1 LoopBack0
4.4.4.4/32 OSPF 10 1 D 34.1.1.2 GigabitEthernet0/0/2
5.5.5.5/32 OSPF 10 2 D 34.1.1.2 GigabitEthernet0/0/2
6.6.6.6/32 OSPF 10 3 D 34.1.1.2 GigabitEthernet0/0/2
7.7.7.0/24 O_ASE 150 1 D 34.1.1.2 GigabitEthernet0/0/2
[r4-GigabitEthernet0/0/2]dis ip ro
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 26 Routes : 30
Destination/Mask Proto Pre Cost Flags NextHop Interface
1.1.1.0/24 O_ASE 150 1 D 24.1.1.1 GigabitEthernet0/0/1
O_ASE 150 1 D 34.1.1.1 GigabitEthernet0/0/2
2.2.2.0/24 O_ASE 150 1 D 24.1.1.1 GigabitEthernet0/0/1
O_ASE 150 1 D 34.1.1.1 GigabitEthernet0/0/2
3.3.3.0/24 OSPF 10 1 D 34.1.1.1 GigabitEthernet0/0/2
4.4.4.0/24 Direct 0 0 D 4.4.4.4 LoopBack0
4.4.4.4/32 Direct 0 0 D 127.0.0.1 LoopBack0
4.4.4.255/32 Direct 0 0 D 127.0.0.1 LoopBack0
5.5.5.5/32 OSPF 10 1 D 45.1.1.2 GigabitEthernet0/0/0
6.6.6.6/32 OSPF 10 2 D 45.1.1.2 GigabitEthernet0/0/0
7.7.7.0/24 O_ASE 150 1 D 45.1.1.2 GigabitEthernet0/0/0
环路问题解决
五、解决选路
此时查看R1的路由表,发现R1到OSPF都是负载均衡,显然不合理;
查看R4的路由表,同理此时R4到RIP也都是负载均衡,不合理;
理想状态下:
在RIP中:
R1到R3环回和34.1.1.0/24应该是走13.1.1.0/24
R1到24.1.1.0/24应该是走12.1.1.0/24
R1到其他网段都是负载均衡
在OSPF中:
R4到R3环回和13.1.1.0/24应该走34.1.1.0/24
R4到12.1.1.0/24应该走24.1.1.0/24
R4到R1环回负载均衡
此处列举R1的路由表
[r1]dis ip ro
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 24 Routes : 34
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.0/24 RIP 100 1 D 12.1.1.2 GigabitEthernet0/0/0
3.3.3.0/24 RIP 100 1 D 13.1.1.2 GigabitEthernet0/0/1
RIP 100 1 D 12.1.1.2 GigabitEthernet0/0/0
4.4.4.4/32 RIP 100 1 D 12.1.1.2 GigabitEthernet0/0/0
RIP 100 1 D 13.1.1.2 GigabitEthernet0/0/1
5.5.5.5/32 RIP 100 1 D 12.1.1.2 GigabitEthernet0/0/0
RIP 100 1 D 13.1.1.2 GigabitEthernet0/0/1
6.6.6.6/32 RIP 100 1 D 12.1.1.2 GigabitEthernet0/0/0
RIP 100 1 D 13.1.1.2 GigabitEthernet0/0/1
7.7.7.0/24 RIP 100 1 D 12.1.1.2 GigabitEthernet0/0/0
RIP 100 1 D 13.1.1.2 GigabitEthernet0/0/1
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
13.1.1.0/24 Direct 0 0 D 13.1.1.1 GigabitEthernet0/0/1
13.1.1.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1
13.1.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1
24.1.1.0/24 RIP 100 1 D 12.1.1.2 GigabitEthernet0/0/0
RIP 100 1 D 13.1.1.2 GigabitEthernet0/0/1
34.1.1.0/24 RIP 100 1 D 13.1.1.2 GigabitEthernet0/0/1
RIP 100 1 D 12.1.1.2 GigabitEthernet0/0/0
45.1.1.0/24 RIP 100 1 D 12.1.1.2 GigabitEthernet0/0/0
RIP 100 1 D 13.1.1.2 GigabitEthernet0/0/1
56.1.1.0/24 RIP 100 1 D 12.1.1.2 GigabitEthernet0/0/0
RIP 100 1 D 13.1.1.2 GigabitEthernet0/0/1
67.1.1.0/24 RIP 100 1 D 12.1.1.2 GigabitEthernet0/0/0
RIP 100 1 D 13.1.1.2 GigabitEthernet0/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
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
解决办法:
1、RIP中:
使用偏移列表改变它的度量
[r2]ip ip-prefix xx permit 3.3.3.0 24
[r2]ip ip-prefix xx permit 34.1.1.0 24
****抓取
[r2]int g0/0/0
[r2-GigabitEthernet0/0/0]rip metricout ip-prefix xx 2
****进入接口调用该前缀列表,并将它的度量+2,这样该选路就会成为备用选路
[r3]ip ip-prefix xx permit 24.1.1.0 24
[r3]int g0/0/1
[r3-GigabitEthernet0/0/1]rip metricout ip-prefix xx 2
2、OSPF中:
改变cost-type
[r2]ip ip-prefix haha permit 12.1.1.0 24
[r2]ip ip-prefix haha permit 2.2.2.0 24
****使用前缀列表抓取网段
[r2]route-policy haha permit node 10
Info: New Sequence of this List.
****创建路由策略
[r2-route-policy]if-match ip-prefix haha
[r2-route-policy]apply cost-type type-1
****将选中网段的路由的cost-type改为type-1
****因为默认重发布的路由的cost-type为type-2
****type-1的优先级大于type-2
****所以OSPF会将type-2的路线作为备用选路
[r2-route-policy]q
[r2]route-policy haha permit node 20
Info: New Sequence of this List.
****创建一个空表,允许所有
[r2-ospf-1]import-route rip route-policy haha
****在ospf中调用该路由策略
[r3]ip ip-prefix haha permit 13.1.1.0 24
[r3]route-policy haha permit node 10
Info: New Sequence of this List.
[r3-route-policy]if-match ip-prefix haha
[r3-route-policy]apply cost-type type-1
[r3-route-policy]q
[r3]route-policy haha permit node 20
Info: New Sequence of this List.
[r3-ospf-1]import-route rip route-policy haha
六、测试
注:此时可能会出现与预估不同的路由表,重启相关接口刷新路由表
R1路由表中已成最佳选路且无环
[r1-GigabitEthernet0/0/1]dis ip ro
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 24 Routes : 30
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.0/24 RIP 100 1 D 12.1.1.2 GigabitEthernet0/0/0
3.3.3.0/24 RIP 100 1 D 13.1.1.2 GigabitEthernet0/0/1
4.4.4.4/32 RIP 100 1 D 13.1.1.2 GigabitEthernet0/0/1
RIP 100 1 D 12.1.1.2 GigabitEthernet0/0/0
5.5.5.5/32 RIP 100 1 D 13.1.1.2 GigabitEthernet0/0/1
RIP 100 1 D 12.1.1.2 GigabitEthernet0/0/0
6.6.6.6/32 RIP 100 1 D 13.1.1.2 GigabitEthernet0/0/1
RIP 100 1 D 12.1.1.2 GigabitEthernet0/0/0
7.7.7.0/24 RIP 100 1 D 13.1.1.2 GigabitEthernet0/0/1
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
13.1.1.0/24 Direct 0 0 D 13.1.1.1 GigabitEthernet0/0/1
13.1.1.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1
13.1.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1
24.1.1.0/24 RIP 100 1 D 12.1.1.2 GigabitEthernet0/0/0
34.1.1.0/24 RIP 100 1 D 13.1.1.2 GigabitEthernet0/0/1
45.1.1.0/24 RIP 100 1 D 13.1.1.2 GigabitEthernet0/0/1
RIP 100 1 D 12.1.1.2 GigabitEthernet0/0/0
56.1.1.0/24 RIP 100 1 D 13.1.1.2 GigabitEthernet0/0/1
RIP 100 1 D 12.1.1.2 GigabitEthernet0/0/0
67.1.1.0/24 RIP 100 1 D 13.1.1.2 GigabitEthernet0/0/1
RIP 100 1 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
R4路由表中已成最佳选路且无环
[r4-GigabitEthernet0/0/1]dis ip ro
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 26 Routes : 27
Destination/Mask Proto Pre Cost Flags NextHop Interface
1.1.1.0/24 O_ASE 150 1 D 34.1.1.1 GigabitEthernet0/0/2
O_ASE 150 1 D 24.1.1.1 GigabitEthernet0/0/1
2.2.2.0/24 O_ASE 150 2 D 24.1.1.1 GigabitEthernet0/0/1
3.3.3.0/24 OSPF 10 1 D 34.1.1.1 GigabitEthernet0/0/2
4.4.4.0/24 Direct 0 0 D 4.4.4.4 LoopBack0
4.4.4.4/32 Direct 0 0 D 127.0.0.1 LoopBack0
4.4.4.255/32 Direct 0 0 D 127.0.0.1 LoopBack0
5.5.5.5/32 OSPF 10 1 D 45.1.1.2 GigabitEthernet0/0/0
6.6.6.6/32 OSPF 10 2 D 45.1.1.2 GigabitEthernet0/0/0
7.7.7.0/24 O_ASE 150 1 D 24.1.1.1 GigabitEthernet0/0/1
12.1.1.0/24 O_ASE 150 2 D 24.1.1.1 GigabitEthernet0/0/1
13.1.1.0/24 O_ASE 150 2 D 34.1.1.1 GigabitEthernet0/0/2
24.1.1.0/24 Direct 0 0 D 24.1.1.2 GigabitEthernet0/0/1
24.1.1.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1
24.1.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1
34.1.1.0/24 Direct 0 0 D 34.1.1.2 GigabitEthernet0/0/2
34.1.1.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/2
34.1.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/2
45.1.1.0/24 Direct 0 0 D 45.1.1.1 GigabitEthernet0/0/0
45.1.1.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0
45.1.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0
56.1.1.0/24 OSPF 10 2 D 45.1.1.2 GigabitEthernet0/0/0
67.1.1.0/24 OSPF 10 3 D 45.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