步骤一:配置各个路由器接口ip和环回接口ip
[r1]interface g 0/0/0
[r1-GigabitEthernet0/0/0]ip address 12.0.0.1 24
[r1-GigabitEthernet0/0/0]interface g 0/0/1
[r1-GigabitEthernet0/0/1]ip address 13.0.0.1 24
[r1]interface LoopBack 0
[r1-LoopBack0]ip address 1.1.1.1 24
[r2]interface g 0/0/0
[r2-GigabitEthernet0/0/0]ip address 12.0.0.2 24
[r2-GigabitEthernet0/0/0]interface g 0/0/1
[r2-GigabitEthernet0/0/1]ip address 24.0.0.1 24
[r2]interface LoopBack 0
[r2-LoopBack0]ip address 2.2.2.2 24
[r3]interface g 0/0/0
[r3-GigabitEthernet0/0/0]ip address 13.0.0.2 24
[r3-GigabitEthernet0/0/0]interface g 0/0/1
[r3-GigabitEthernet0/0/1]ip address 34.0.0.1 24
[r3]interface LoopBack 0
[r3-LoopBack0]ip address 3.3.3.3 24
[r4]interface g 0/0/0
[r4-GigabitEthernet0/0/0]ip address 24.0.0.2 24
[r4-GigabitEthernet0/0/0]interface g 0/0/1
[r4-GigabitEthernet0/0/1]ip address 34.0.0.2 24
[r4]interface LoopBack 0
[r4-LoopBack0]ip address 4.4.4.4 24
步骤二:配置RIP和OSPF
R1:配置RIP
[r1]rip 1
[r1-rip-1]version 2
[r1-rip-1]network 12.0.0.0
[r1-rip-1]network 13.0.0.0
[r1-rip-1]network 1.0.0.0
R4:配置OSPF
[r4]ospf
[r4-ospf-1]area 0
[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]network 24.0.0.2 0.0.0.0
[r4-ospf-1-area-0.0.0.0]network 34.0.0.2 0.0.0.0
R2:配置RIP和OSPF、双向重发布
[r2]rip 1
[r2-rip-1]version 2
[r2-rip-1]network 12.0.0.0
[r2-rip-1]q
[r2]ospf 1
[r2-ospf-1]area 0
[r2-ospf-1-area-0.0.0.0]network 24.0.0.1 0.0.0.0
[r2-ospf-1-area-0.0.0.0]q
[r2-ospf-1]import
[r2-ospf-1]import-route rip //重发布
[r2-ospf-1]q
[r2]rip 1
[r2-rip-1]network 2.0.0.0
[r2-rip-1]import-route ospf 1 //重发布
R3:配置RIP和OSPF、双向重发布
[r3]rip 1
[r3-rip-1]version 2
[r3-rip-1]network 13.0.0.0
[r3-rip-1]import-route ospf 1 //重发布
[r3-rip-1]ospf 1
[r3-ospf-1]area 0
[r3-ospf-1-area-0.0.0.0]network 3.3.3.3 0.0.0.0
[r3-ospf-1-area-0.0.0.0]network 34.0.0.1 0.0.0.0
[r3-ospf-1-area-0.0.0.0]q
[r3-ospf-1]import-route rip //重发布
步骤三:优化路由
此时检查R1上的RIP路由信息
会发现有两条3.3.3.0的网段,它们分别来自R2和R3的重发布
原因是环回接口OSPF的默认网络类型是P2P型,导致重发布后会学习到两条R3的环回网段
查询R2的路由表,可以发现这两个指向,会造成选路不佳
改进方法:进入R3的环回接口将P2P型改为broadcast型,使R2学习到R3的环回
[r3]interface LoopBack 0
[r3-LoopBack0]ospf network-type broadcast
发现现在3.3.3.0网段只有一个了,但可以发现应为双点双向的重发布,出现了负载均衡的情况;针对这些情况需要路由策略进行控制
步骤四:使用路由策略控制选路
路由策略不能单独使用,只能在重发布过程中进行调用
R2
r2要抓取34.0.0..0 24 和3.0.0.0 24、13.0.0.0 24 的流量,13.0.0.0在抓取后要在ospf中重发布调用
[r2]ip ip-prefix a permit 34.0.0.0 24 //抓取流量
[r2]ip ip-prefix a permit 3.3.3.0 24
[r2]route-policy a permit node 10 //创建路由策略写规则
Info: New Sequence of this List.
[r2-route-policy]if-match ip-prefix a
[r2-route-policy]apply cost 10
//创建空表放通流量,因为路由策略隐含了一条拒绝所有的规则,
如果没有这个空表会导致开销值为10的34.0.0.0 24 网段以外的其他网段都被拒绝
[r2-route-policy]q
[r2]route-policy a permit node 20
Info: New Sequence of this List.
//重发布过程中调用路由策略
[r2-rip-1]import-route ospf route-policy a
对13.0..0.0抓取后在OSPF中重发布调用
[r2]ip ip-prefix b permit 13.0.0.0 24
[r2]route-policy b permit node 10
Info: New Sequence of this List.
[r2-route-policy]if-match ip-prefix b
[r2-route-policy]apply cost 10
[r2-route-policy]q
[r2]route-policy b permit node 20
Info: New Sequence of this List.
[r2-ospf-1]import-route rip route-policy b
R3
r3要抓取12.0.0.0 24 、2.0.0.0 24 、24.0.0.0 24 的流量,其中24.0.0.0 24要在RIP中重发布调用
[r3]ip ip-prefix b permit 12.0.0.0 24
[r3]ip ip-prefix b permit 2.2.2.0 24
[r3]route-policy b permit node 10
Info: New Sequence of this List.
[r3-route-policy]if-match ip-prefix b
[r3-route-policy]apply cost 10
[r3-route-policy]q
//创建空表,放通路由
[r3]route-policy b permit node 20
Info: New Sequence of this List.
24.0.0.0 24 在RIP中重发布
[r3]ip ip-prefix a permit 24.0.0.0 24
[r3]route-policy a permit node 10
Info: New Sequence of this List.
[r3-route-policy]if-match ip-prefix a
[r3-route-policy]apply cost 10
[r3-route-policy]q
[r3]route-policy a permit node 20
Info: New Sequence of this List.
[r3-route-policy]q
[r3]rip
[r3-rip-1]version 2
[r3-rip-1]import-route ospf route-policy a
[r3-rip-1]q
[r3]ospf
[r3-ospf-1]import-route rip route-policy b
检查优化情况