1.先配置IP和环回
[Huawei]sysname R1
[R1]interface GigabitEthernet 0/0/0
[R1-GigabitEthernet0/0/0]ip add 12.1.1.1 24
[R1-GigabitEthernet0/0/0]int g 0/0/1
[R1-GigabitEthernet0/0/1]ip add 22.1.1.1 24
[R1-GigabitEthernet0/0/1]q
[R1]int l 0
[R1-LoopBack0]ip add 1.1.1.1 24
其他同理
2.添加路由协议
[R1]rip 1
[R1-rip-1]version 2
[R1-rip-1]network 1.0.0.0
[R1-rip-1]network 12.0.0.0
[R1-rip-1]network 22.0.0.0
[R2]rip 1
[R2-rip-1]version 2
[R2-rip-1]network 12.0.0.0
[R2-rip-1]network 2.0.0.0
[R2-rip-1]q
[R2]ospf 1
[R2-ospf-1]area
[R2-ospf-1]area 0
[R2-ospf-1-area-0.0.0.0]network 32.1.1.1 0.0.0.0
[R4]ospf 1
[R4-ospf-1]area
[R4-ospf-1]area 0
[R4-ospf-1-area-0.0.0.0]network 0.0.0.0 255.255.255.255
R5,R6同理
[R7]ospf 1 router-id 7.7.7.7
[R7-ospf-1]area 0
[R7-ospf-1-area-0.0.0.0]network 72.1.1.2 0.0.0.0
3.把R7的环回导入
[R7]ospf 1
[R7-ospf-1]import-route direct
4.把R2,R3上做重发布
[R2]ospf 1
[R2-ospf-1]import-route rip
[R2]rip 1
[R2-rip-1]import-route ospf 1
[R3]ospf 1
[R3-ospf-1]import-route rip
[R3]rip
[R3-rip-1]import-route ospf 1
5.将R1发给R3的路由优先级改为151
[R3]ip ip-prefix a index 10 permit 7.7.7.0 24
[R3]route-policy qq permit node 10
Info: New Sequence of this List.
[R3-route-policy]if-match ip-prefix a
[R3-route-policy]apply preference 151
[R3-route-policy]q
[R3]rip 1
[R3-rip-1]preference route-policy qq
6.如果R2R4线路断,重连后发现R7环回会通过优先级为100的R1到R2路线,和R3上同理配置优先级
[R2]ip ip-prefix a permit 7.7.7.0 24
[R2]route-policy qq permit node 10
Info: New Sequence of this List.
[R2-route-policy]if-match ip-prefix a
[R2-route-policy]apply preference 151
[R2-route-policy]q
[R2]rip 1
[R2-rip-1]preference route-policy qq
7.测试
8.选路最优
[R3-LoopBack0]ip add 3.3.3.3 32
加度量
[R3]ip ip-prefix we permit 32.1.1.0/ 24
[R3]int g 0/0/0
[R3-GigabitEthernet0/0/0]rip metricin ip-
[R3-GigabitEthernet0/0/0]rip metricin ip-prefix we 2
[R2]ip ip-prefix er permit 3.3.3.3 32
[R2]ip ip-prefix er permit 42.1.1.0 24
[R2]int g 0/0/0
[R2-GigabitEthernet0/0/1]ri
[R2-GigabitEthernet0/0/1]rip metricout ip-prefix er 2
[R2]ip ip-prefix rr permit 12.1.1.0 24
[R2]ip ip-prefix rr permit 2.2.2.0 24
[R2]route-policy rr permit node 10
Info: New Sequence of this List.
[R2-route-policy]if-match ip-prefix rr
[R2-route-policy]apply cost-type type-1
[R2-route-policy]q
[R2]route-policy rr permit node 20
Info: New Sequence of this List.
[R2-route-policy]q
[R2]ospf 1
[R2-ospf-1]import-route rip route-policy rr
[R3]ip ip-prefix rr permit 22.1.1.0 24
[R3]route-policy rr permit node 10
Info: New Sequence of this List.
[R3-route-policy]if-match ip-prefix rr
[R3-route-policy]apply cost-type type-1
[R3-route-policy]q
[R3]route-policy rr permit node 20
Info: New Sequence of this List.
[R3-route-policy]q
[R3]ospf 1
[R3-ospf-1]import-route rip route-policy rr