一:IP地址如图
二:配置IP地址
R1
[R1]int lo 0
[R1-LoopBack0]ip address 1.1.1.1 24
[R1-LoopBack0]int g 0/0/0
[R1-GigabitEthernet0/0/0]ip address 14.1.1.1 24
[R1-GigabitEthernet0/0/0]int g 0/0/1
[R1-GigabitEthernet0/0/1]ip address 12.1.1.2 24
R2
[R2]int lo 0
[R2-LoopBack0]ip address 2.2.2.2 24
[R2-LoopBack0]int g 0/0/0
[R2-GigabitEthernet0/0/0]ip address 12.1.1.2 24
[R2-GigabitEthernet0/0/0]int g 0/0/1
[R2-GigabitEthernet0/0/1]ip address 23.1.1.2 24
R3
[R3]int lo 0
[R3-LoopBack0]ip address 3.3.3.3 24
[R3-LoopBack0]int g 0/0/0
[R3-GigabitEthernet0/0/0]ip address 23.1.1.3 24
[R3-GigabitEthernet0/0/0]int g 0/0/1
[R3-GigabitEthernet0/0/1]ip address 34.1.1.3 24
R4
[R4]int lo 0
[R4-LoopBack0]ip address 4.4.4.4 24
[R4-LoopBack0]int g 0/0/1
[R4-GigabitEthernet0/0/1]ip address 34.1.1.4 24
[R4-GigabitEthernet0/0/1]int g 0/0/0
[R4-GigabitEthernet0/0/0]ip address 14.1.1.4 24
三:分别启用RIP和OSPF
R2的环回宣告在OSPF中,R4的环回宣告在RIP中
[R1]rip 1
[R1-rip-1]ver 2
[R1-rip-1]undo summary
[R1-rip-1]network 12.0.0.0
[R1-rip-1]network 14.0.0.0
[R1-rip-1]network 1.0.0.0
[R2]rip 1
[R2-rip-1]ver 2
[R2-rip-1]un su
[R2-rip-1]network 12.0.0.0
[R2-rip-1]ospf 1 router-id 2.2.2.2
[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-area-0.0.0.0]network 2.2.2.2 0.0.0.0
[R3]ospf 1 router-id 3.3.3.3
[R3-ospf-1]a 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 23.1.1.0 0.0.0.255
[R3-ospf-1-area-0.0.0.0]network 34.1.1.0 0.0.0.255
[R3-ospf-1-area-0.0.0.0]q
[R3-ospf-1]q
[R3-LoopBack0]ospf network-type broadcast
[R4]rip 1
[R4-rip-1]ver 2
[R4-rip-1]un su
[R4-rip-1]network 14.0.0.0
[R4-rip-1]network 4.0.0.0
[R4-rip-1]q
[R4]ospf router-id 4.4.4.4
[R4-ospf-1]a 0
[R4-ospf-1-area-0.0.0.0]network 34.1.1.0 0.0.0.255
四:配置重发布
[R2]rip 2
[R2-rip-2]q
[R2]rip 1
[R2-rip-1]import-route ospf 1
[R2-rip-1]q
[R2]ospf 1
[R2-ospf-1]import-route rip 1
[R4-ospf-1-area-0.0.0.0]q
[R4-ospf-1]q
[R4]rip 1
[R4-rip-1]import-route ospf 1
[R4-rip-1]q
[R4]ospf 1
[R4-ospf-1]import-route rip 1
修改接口类型:
[R4-LoopBack0]ospf network-type broadcast
[R3-LoopBack0]ospf network-type broadcast
五:配置路由策略
R2的配置
[r2]ip ip-prefix hcip permit 34.1.1.0 24
[r2]ip ip-prefix hcip permit 4.4.4.0 24
[r2]route-policy hcip per node 10
[r2-route-policy]if-match ip-prefix hcip
[r2-route-policy]apply cost 10
[r2]route-policy hcip p node 20
[r2]rip 1
[r2-rip-1]im ospf 1 route-policy hcip
[r2]ip ip-prefix hcip permit 14.1.1.0 24
[r2]route-policy hcip per no 10
[r2-route-policy]if-match ip-prefix hcip
[r2-route-policy]apply cost 10
[r2]route-policy hcip permit no 20
[r2]ospf 1
[r2-ospf-1]import-route rip 1 route-policy hcip
R4的配置
[r4]ip ip-prefix hcip permit 23.1.1.0 24
[r4]route-policy hcip permit node 10
[r4-route-policy]if-match ip-prefix hcip
[r4-route-policy]apply cost 10
[r4]route-policy hcip permit node 20
[r4-route-policy]rip 1
[r4-rip-1]im ospf 1 route-policy hcip
[r4]ip ip-prefix hcip per 2.2.2.0 24
[r4]ip ip-prefix hcip per 12.1.1.0 24
[r4]route-policy hcip per node 10
[r4-route-policy]if-match ip-prefix hcip
[r4-route-policy]apply cost 10
[r4]route-policy hcip per node 20
[r4]ospf 1
[r4-ospf-1]import-route rip 1 route-policy hcip
六:实验结果