第一步:配置IP及环回![](https://img-blog.csdnimg.cn/direct/d72279be3d614107b557d9de846a567e.png)
[r1]int g 0/0/0
[r1-GigabitEthernet0/0/0]ip a 11.0.0.1 24
[r1]int g 0/0/1
[r1-GigabitEthernet0/0/1]ip a 13.0.0.1 24
[r1]int g 0/0/2
[r1-GigabitEthernet0/0/2]ip a 15.0.0.1 24
[r1]int l 0
[r1-LoopBack0]ip a 1.1.1.1 32
[r1]int l 1
[r1-LoopBack1]ip a 192.168.10.1 24
[r2]int g 0/0/0
[r2-GigabitEthernet0/0/0]ip a 12.0.0.2 24
[r2]int g 0/0/1
[r2-GigabitEthernet0/0/1]ip a 11.0.0.2 24
[r2]int l 0
[r2-LoopBack0]ip a 2.2.2.2 32
[r2]int l 1
[r2-LoopBack1]ip a 192.168.20.1 24
[r3]int g 0/0/0
[r3-GigabitEthernet0/0/0]ip a 14.0.0.3 24
[r3-GigabitEthernet0/0/0]int g 0/0/1
[r3-GigabitEthernet0/0/1]ip a 13.0.0.3 24
[r3]int l 0
[r3-LoopBack0]ip a 3.3.3.3 32
[r3]int l 1
[r3-LoopBack1]ip a 192.168.30.1 24
[r4]int g 0/0/0
[r4-GigabitEthernet0/0/0]ip a 12.0.0.4 24
[r4]int g 0/0/1
[r4-GigabitEthernet0/0/1]ip a 14.0.0.4 24
[r4]int l 0
[r4-LoopBack0]ip a 192.168.1.1 24
[r4]int l 1
[r4-LoopBack1]ip a 192.168.2.1 24
[r4]int l 2
[r4-LoopBack2]ip a 192.168.3.1 24
[r5]int g 0/0/0
[r5-GigabitEthernet0/0/0]ip a 15.0.0.1 24
[r5]int l 0
[r5-LoopBack0]ip a 192.168.10.1 24
[r5]int l 1
[r5-LoopBack1]ip a 192.168.11.1 24
[r5]int l 2
[r5-LoopBack2]ip a 192.168.12.1 24
第二步:ospf
[r1]ospf 1 router-id 1.1.1.1
[r1-ospf-1]area 0
[r1-ospf-1-area-0.0.0.0]network 1.1.1.1 0.0.0.0
[r1-ospf-1-area-0.0.0.0]network 11.0.0.1 0.0.0.0
[r1-ospf-1-area-0.0.0.0]network 13.0.0.1 0.0.0.0
[r1-ospf-1-area-0.0.0.0]network 192.168.100.1 0.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 2.2.2.2 0.0.0.0
[r2-ospf-1-area-0.0.0.0]network 11.0.0.2 0.0.0.0
[r2-ospf-1-area-0.0.0.0]network 192.168.20.1 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 3.3.3.3 0.0.0.0
[r3-ospf-1-area-0.0.0.0]network 13.0.0.3 0.0.0.0
[r3-ospf-1-area-0.0.0.0]network 192.168.30.1 0.0.0.0
第三步:BGP协议
[r1]bgp 123
[r1-bgp]router-id 1.1.1.1
[r1-bgp]peer 2.2.2.2 as 123
[r1-bgp]peer 2.2.2.2 connect-interface LoopBack 0
[r1-bgp]peer 2.2.2.2 next-hop-local
[r1-bgp]peer 3.3.3.3 as 123
[r1-bgp]peer 3.3.3.3 connect-interface LoopBack 0
[r1-bgp]peer 3.3.3.3 next-hop-local
[r2]bgp 123
[r2-bgp]router-id 2.2.2.2
[r2-bgp]peer 12.0.0.3 as 400
[r2-bgp]peer 1.1.1.1 as 123
[r2-bgp]peer 1.1.1.1 connect-interface LoopBack 0
[r2-bgp]peer 1.1.1.1 next-hop-local
[r3]bgp 123
[r3-bgp]router-id 3.3.3.3
[r3-bgp]peer 14.0.0.4 as 400
[r3-bgp]peer 1.1.1.1 as 123
[r3-bgp]peer 1.1.1.1 connect-interface LoopBack 0
[r3-bgp]peer 1.1.1.1 next-hop-local
[r4]bgp 400
[r4-bgp]router-id 4.4.4.4
[r4-bgp]peer 12.0.0.2 as 123
[r4-bgp]peer 14.0.0.3 as 123
[r5]bgp 500
[r5-bgp]router-id 5.5.5.5
[r5-bgp]peer 15.0.0.5 as 123
第四步:宣告BGP路由
[r1]bgp 123
[r1-bgp]network 192.168.100.0 24
[r2]bgp 123
[r2-bgp]network 192.168.20.0 24
[r3]bgp 123
[r3-bgp]network 192.168.30.0 24
[r4]bgp 400
[r4-bgp]network 192.168.1.0 24
[r4-bgp]network 192.168.2.0 24
[r4-bgp]network 192.168.3.0 24
[r5]bgp 500
[r5-bgp]network 192.168.10.0 24
[r5-bgp]network 192.168.11.0 24
[r5-bgp]network 192.168.12.0 24
第五步
[r4]ip ip-prefix PV permit 192.168.10.0 24
[r4]route-policy PV permit node 10
Info: New Sequence of this List.
[r4-route-policy]if-match ip-prefix PV
[r4-route-policy]apply preferred-value 100
[r4-route-policy]q
[r4]route-policy PV permit node 80
Info: New Sequence of this List.
[r4-route-policy]q
[r4]bgp 400
[r4-bgp]peer 12.0.0.2 route-policy PV import