一,给每一台路由器上配置上相应的ip地址
R1
[R1]interface GigabitEthernet0/0/0
[R1] ip address 12.1.1.1 255.255.255.0
[R1]interface GigabitEthernet0/0/1
[R1] ip address 14.1.1.1 255.255.255.0
[R1]interface GigabitEthernet0/0/2
[R1]interface NULL0
[R1]interface LoopBack0
[R1] ip address 1.1.1.1 255.255.255.0
[R1]interface LoopBack1
[R1] ip address 172.16.1.1 255.255.255.0
[R1]vinterface LoopBack2
[R1] ip address 172.16.2.1 255.255.255.0
[R1]interface LoopBack3
[R1] ip address 172.16.3.1 255.255.255.0
[R1]interface LoopBack4
[R1] ip address 172.16.4.1 255.255.255.0
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
[R3]interface GigabitEthernet0/0/0
[R3] ip address 23.1.1.2 255.255.255.0
[R3]interface GigabitEthernet0/0/1
[R3] ip address 34.1.1.1 255.255.255.0
[R3]interface GigabitEthernet0/0/2
[R3]interface NULL0
[R3]interface LoopBack0
[R3] ip address 3.3.3.3 255.255.255.0
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
[R1]rip 1
[R1] version 2
[R1] network 12.0.0.0
[R1] network 14.0.0.0
[R1] network 1.0.0.0
[R1] network 172.16.0.0
R2
[R2]rip 1
[R2-rip-1]v 2
[R2-rip-1]network 2.0.0.0
[R2-rip-1]network 12.0.0.0
[R2]ospf 1
[R2-ospf-1]a 0
[R2-ospf-1-area-0.0.0.0]network 23.1.1.1 0.0.0.0
R3
[R3]ospf 1
[R3] area 0.0.0.0[R3]network 3.3.3.0 0.0.0.255
[R3] network 23.1.1.0 0.0.0.255
[R3] network 34.1.1.0 0.0.0.255
[r4]rip 1
[R4-rip-1]v 2
[R4-rip-1]network 14.0.0.0
[R4]ospf 1
[R4-ospf-1]a 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 34.1.1.2 0.0.0.0
三,在R2,R4上做路由决策
[R2]ip ip-prefix 1 permit 172.16.1.0 4
[R2]ip ip-prefix 2 permit 172.16.2.0 24
[R2]ip ip-prefix 3 permit 172.16.3.0 24
[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-match ip-prefix 1
[R2]route-policy huawei permit node 20
Info: New Sequence of this List.
[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]apply cost-type type-1
[R2]route-policy huawei permit node 30
Info: New Sequence of this List.
[R2-route-policy]if-match ip-prefix 3
[R2-route-policy]apply cost 6
[R2]route-policy huawei permit node 40
Info: New Sequence of this List.
[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 huawei permit node 50
[R4]ip ip-prefix 1 permit 172.16.1.0 24
[R4]ip ip-prefix 2 permit 172.16.2.0 24
[R4]ip ip-prefix 3 permit 172.16.3.0 24
[R4]ip ip-prefix 4 permit 172.16.4.0 24
[R4]route-policy huawei deny node 10
Info: New Sequence of this List.
[r4-route-policy]if-match ip-prefix 1
[R4]route-policy huawei permit node 20
Info: New Sequence of this List.
[R4-route-policy]if-match ip-prefix 2
[R4-route-policy]apply cost-type type
[R4-route-policy]apply cost-type type-1
[R4]route-policy huawei permit node 30
Info: New Sequence of this List.
[R4-route-policy]if-match ip-prefix 3
[R4-route-policy]apply cost 6
[R4]route-policy huawei permit node 40
Info: New Sequence of this List.
[R4-route-policy]if-match ip-prefix 4
[R4-route-policy]apply cost 9
[R4-route-policy]apply cost-type type-1
[R4]route-policy huawei permit node 50
四,将策略进行应用
[R2]ospf 1
[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]rip 1
[R2-rip-1]import-route ospf 1 route-policy huawei
[r4]rip 1
[r4-rip-1]import-route ospf 1 route-policy huawei
[r4]ospf 1
[r4-ospf-1]import-route rip 1 route-policy huawei