1.拓扑
2.IP
R1环回:1.1.1.1/24 R2环回:2.2.2.2/24 R3环回:3.3.3.3/24 R4环回:4.4.4.4/24
R1-R2:12.1.1.0/24 R2-R3:23.1.1.0/24 R3-R4:34.1.1.0/24 R1-R4:14.1.1.0/24
3.配置
R1:
[r1]int g 0/0/0
[r1-GigabitEthernet0/0/0]ip address 12.1.1.1 255.255.255.0
[r1-GigabitEthernet0/0/0]int g 0/0/1
[r1-GigabitEthernet0/0/1]ip address 14.1.1.1 255.255.255.0
[r1]int l0
[r1-LoopBack0]ip address 1.1.1.1 255.255.255.0
[r1]int l1
[r1]rip 1
[r1-rip-1]version 2
[r1-rip-1]network 12.0.0.0
[r1-rip-1]network 1.0.0.0
[r1-rip-1]network 14.0.0.0
[r1-rip-1]network 172.16.0.0
[r1]ip ip-prefix 23 permit 23.1.1.0 24
[r1]int g 0/0/1
[r1-GigabitEthernet0/0/1]rip metricin ip-prefix 23 2
[r1]ip ip-prefix 4 permit 4.4.4.0 24
[r1]ip ip-prefix 43 permit 43.1.1.0 24
[r1]int g 0/0/0
[r1-GigabitEthernet0/0/0]rip metricin ip-prefix 4 2
[r1-GigabitEthernet0/0/0]rip metricin ip-prefix 43 2
R2:
[r2]int g 0/0/0
[r2-GigabitEthernet0/0/0]ip address 12.1.1.2 255.255.255.0
[r2-GigabitEthernet0/0/0]int g 0/0/1
[r2-GigabitEthernet0/0/1]ip address 23.1.1.2 255.255.255.0
[r2]int l0
[r2-LoopBack0]ip address 2.2.2.2 255.255.255.0
[r2-LoopBack0]ospf network-type broadcast
[r2]ospf 1
[r2-ospf-1]area 0
[r2-ospf-1-area-0.0.0.0]network 23.1.1.0 0.0.0.255
[r2]ospf 1
[r2-ospf-1] import-route direct
[r2-ospf-1] import-route rip 1
[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] import-route direct
[r2-rip-1] import-route ospf 1
[r2]ip ip-prefix 5 permit 4.4.4.0 24
[r2]ip ip-prefix 6 permit 43.1.1.0 24
[r2]route-policy haha deny node 10
[r2-route-policy]if-match ip-prefix 1
[r2]route-policy haha permit node 20
[r2-route-policy]if-match ip-prefix 2
[r2-route-policy]apply cost-type type-1
[r2]route-policy haha permit node 30
[r2-route-policy]if-match ip-prefix 3
[r2-route-policy]apply cost 6
[r2]route-policy haha permit node 40
[r2-route-policy]if-match ip-prefix 4
[r2-route-policy]apply cost 9
[r2-route-policy]apply cost-type type-1
[r2]route-policy haha permit node 50
[r2]route-policy haha permit node 15
[r2-route-policy]if-match ip-prefix 5
[r2-route-policy]apply cost-type type-1
[r2]route-policy haha permit node 25
[r2-route-policy]if-match ip-prefix 6
[r2-route-policy]apply cost-type type-1
[r2]ospf 1
[r2-ospf-1]import-route rip 1 route-policy haha
R3:
[r3]ospf 1
[r3-ospf-1]area 0
[r3-ospf-1-area-0.0.0.0] network 3.3.3.0 0.0.0.255
[r3-ospf-1-area-0.0.0.0] network 23.1.1.0 0.0.0.255
[r3-ospf-1-area-0.0.0.0] network 43.1.1.0 0.0.0.255
[r3]int g 0/0/0
[r3-GigabitEthernet0/0/0]ip address 43.1.1.3 255.255.255.0
[r3-GigabitEthernet0/0/0]int g 0/0/1
[r3-GigabitEthernet0/0/1]ip address 23.1.1.3 255.255.255.0
R4:
[r4]int g 0/0/0
[r4-GigabitEthernet0/0/0]ip address 14.1.1.4 255.255.255.0
[r4-GigabitEthernet0/0/0]int g 0/0/1
[r4-GigabitEthernet0/0/1] ip address 43.1.1.4 255.255.255.0
[r4-GigabitEthernet0/0/1]int l0
[r4-LoopBack0]ip address 4.4.4.4 255.255.255.0
[r4-LoopBack0]ospf network-type broadcast
[r4]rip 1
[r4-rip-1]version 2
[r4-rip-1]network 14.0.0.0
[r4-rip-1]import-route direct
[r4-rip-1]import-route ospf 1
[r4]ip ip-prefix 5 permit 23.1.1.0 24
[r4]ip ip-prefix 6 permit 2.2.2.0 24
[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 haha deny node 10
[r4-route-policy]if-match ip-prefix 1
[r4]route-policy haha permit node 20
[r4-route-policy]if-match ip-prefix 2
[r4-route-policy]apply cost-type type-1
[r4]route-policy haha permit node 30
[r4-route-policy]if-match ip-prefix 3
[r4-route-policy]apply cost 6
[r4]route-policy haha permit node 40
[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 haha permit node 50
[r4]route-policy haha permit node 15
[r4-route-policy]if-match ip-prefix 5
[r4-route-policy]apply cost-type type-1
[r4]route-policy haha permit node 25
[r4-route-policy]if-match ip-prefix 6
[r4-route-policy]apply cost-type type-1
[r4]ospf 1
[r4-ospf-1]import-route rip 1 route-policy haha