一、配置ip地址及环回地址
[Huawei]sysname R1
[R1]int g 0/0/0
[R1-GigabitEthernet0/0/0]ip add 12.0.0.1 24
[R1-GigabitEthernet0/0/0]int g 0/0/1
[R1-GigabitEthernet0/0/1]ip add 14.0.0.1 24
[R1-GigabitEthernet0/0/1]int l 0
[R1-LoopBack0]ip add 1.1.1.1 24
[R1-LoopBack0]int l 1
[R1-LoopBack1]ip add 172.16.1.1 24
[R1-LoopBack1]int l 2
[R1-LoopBack2]ip add 172.16.2.1 24
[R1-LoopBack2]int l 3
[R1-LoopBack3]ip add 172.16.3.1 24
[R1-LoopBack3]int l 4
[R1-LoopBack4]ip add 172.16.4.1 24
[Huawei]sysname R2
[R2]int g 0/0/0
[R2-GigabitEthernet0/0/0]ip add 12.0.0.2 24
[R2-GigabitEthernet0/0/0]int g 0/0/1
[R2-GigabitEthernet0/0/1]ip add 23.0.0.2 24
[R2-GigabitEthernet0/0/1]int l 0
[R2-LoopBack0]ip add 2.2.2.2 24
[Huawei]sysname R3
[R3]int g 0/0/0
[R3-GigabitEthernet0/0/0]ip add 34.0.0.3 24
[R3-GigabitEthernet0/0/0]int g 0/0/1
[R3-GigabitEthernet0/0/1]ip add 23.0.0.3 24
[R3-GigabitEthernet0/0/1]int l 0
[R3-LoopBack0]ip add 3.3.3.3 24
[Huawei]sysname R4
[R4]int g 0/0/0
[R4-GigabitEthernet0/0/0]ip add 34.0.0.4 24.
[R4-GigabitEthernet0/0/0]int g 0/0/1
[R4-GigabitEthernet0/0/1]ip add 14.0.0.4 24
[R4-GigabitEthernet0/0/1]int l 0
[R4-LoopBack0]ip add 4.4.4.4 24
二、启动RIP协议及OSPF协议
[R1]rip 1
[R1-rip-1]version 2
[R1-rip-1]undo summary
[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
[R2]rip 1
[R2-rip-1]version 2
[R2-rip-1]undo summary
[R2-rip-1]network 12.0.0.0
[R2-rip-1]network 2.0.0.0
[R2]ospf 1 router-id 2.2.2.2
[R2-ospf-1]area 0
[R2-ospf-1-area-0.0.0.0]network 23.0.0.2 0.0.0.0
[R3]ospf 1 router-id 3.3.3.3
[R3-ospf-1]area 0
[R3-ospf-1-area-0.0.0.0]network 23.0.0.3 0.0.0.0
[R3-ospf-1-area-0.0.0.0]network 34.0.0.3 0.0.0.0
[R3-ospf-1-area-0.0.0.0]network 3.3.3.3 0.0.0.0
[R4]ospf 1 router-id 4.4.4.4
[R4-ospf-1]area 0
[R4-ospf-1-area-0.0.0.0]network 34.0.0.4 0.0.0.0
[R4-ospf-1-area-0.0.0.0]network 4.4.4.4 0.0.0.0
[R4]rip 1
[R4-rip-1]version 2
[R4-rip-1]undo summary
[R4-rip-1]network 14.0.0.0
三、在R2、R4上进行双点双向重发布
[R2]ospf 1
[R2-ospf-1]import-route rip
[R2-ospf-1]rip 1
[R2-rip-1]import-route ospf
[R4]ospf 1
[R4-ospf-1]import-route rip
[R4-ospf-1]rip 1
[R4-rip-1]import-route ospf
四、如图,R1的路由表里有一条4.4.4.0/24及4.4.4.0/32的路由
最简单的解决方法即:将OSPF的接口网络类型改为broadcast
因为华为设备定义环回接口OSPF的接口网络类型为P2P类型,默认学习32位主机路由
[R4]int l 0
[R4-LoopBack0]ospf network-type broadcast
五、做路由策略
[R2]acl 2000
[R2-acl-basic-2000]rule permit source 4.4.4.0 0.0.0.0
[R2-acl-basic-2000]acl 2001
[R2-acl-basic-2001]rule permit source 34.0.0.0 0.0.0.0
[R2-acl-basic-2001]q
[R2]route-policy a permit node 10
[R2-route-policy]if-match acl 2000
[R2-route-policy]apply cost 4
[R2-route-policy]q
[R2]route-policy a per node 20
[R2-route-policy]if-match acl 2001
[R2-route-policy]apply cost 4
[R2]route-policy a permit node 30
[R2-route-policy]rip 1
[R2-rip-1]import-route ospf route-policy a
[r2]ip ip-prefix k permit 2.2.2.0 24
[r2]route-policy k permit node 10
[r2-route-policy]if-match ip-prefix k
[r2-route-policy]apply cost-type type-1
[r2]ip ip-prefix k permit 12.0.0.0 24
[r2]route-policy k permit node 200
[r2-route-policy]if-match ip-prefix k
[r2-route-policy]apply cost-type type-1
[r2]route-policy k permit node 300
[r2]ospf 1
[r2-ospf-1]import-route rip 1 route-policy k
[R4]ip ip-prefix d permit 14.0.0.0 24
[R4]route-policy d permit node 10
[R4-route-policy]if-match ip-prefix d
[R4-route-policy]apply cost-type type-1
[R4]route-policy d permit node 20
[R4]acl 2000
[R4-acl-basic-2000]rule permit source 23.0.0.0 0.0.0.0
[R4]route-policy f permit node 15
[R4-route-policy]if-match acl 2000
[R4-route-policy]apply cost 4
[R4-route-policy]ospf 1
[R4-ospf-1]import-route rip 1 route-policy f
六、R1除本身环回外,外加几条环回
172.16.1.0/24 deny
172.16.2.0/24 type 1
172.16.3.0/24 cost 6
172.16.4.0/24 type 1 cost 9
更改如上参数
[r2]ip ip-prefix 1 permit 172.16.1.1 24
[r2]ip ip-prefix 2 permit 172.16.2.1 24
[r2]ip ip-prefix 3 permit 172.16.3.1 24
[r2]ip ip-prefix 4 permit 172.16.4.1 24
[r2]route-policy huawei deny node 10
[r2-route-policy]if-match ip-prefix 1
[r2]route-policy huawei permit node 20
[r2-route-policy]if-match ip-prefix 2
[r2-route-policy]apply cost-type type-1
[r2]route-policy huawei permit node 30
[r2-route-policy]if-match ip-prefix 3
[r2-route-policy]apply cost 6
[r2]route-policy huawei permit node 40
[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
[r2]ospf 1
[r2-ospf-1]import-route rip 1 route-policy huawei
[r4]ip ip-prefix 1 permit 172.16.1.1 24
[r4]ip ip-prefix 2 permit 172.16.2.1 24
[r4]ip ip-prefix 3 permit 172.16.3.1 24
[r4]ip ip-prefix 4 permit 172.16.4.1 24
[r4]route-policy huawei deny node 10
[r4-route-policy]if-match ip-prefix 1
[r4-route-policy]route-policy huawei permit node 20
[r4-route-policy]if-match ip-prefix 2
[r4-route-policy]apply cost-type type-1
[r4-route-policy]route-policy huawei permit node 30
[r4-route-policy]if-match ip-prefix
[r4-route-policy]apply cost 6
[r4-route-policy]route-policy huawei permit node 40
[r4-route-policy]if-match ip-prefix 4
[r4-route-policy]apply cost-type type-1
[r4-route-policy]apply cost 9
[r4-route-policy]route-policy huawei permit node 50
[r4-route-policy]ospf 1
[r4-ospf-1]import-route rip 1 route-policy huawei
实验结果如下: