实验拓扑
实验需求
1、使用PreVal策略,确保R4通过R2到达192.168.10.0/24
2、使用AS_Path策略,确保R4通过R3到达192.168.11.0/24
3、配置MED策略,确保R4通过R3到达192.168.12.0/24
4、使用Local Perference策略,确保R1通过R2到达192.168.1.0/24
5、使用Local Perference策略,确保R1通过R3到达192.168.2.0/24
6、配置负载均衡,确保R1通过R2和R3到达192.168.3.0/24
7、使用AS策略,AS 500不接受任何始发于AS 123的路由
8、使用自定义Community策略,确保192.168.3.0/24路由不被发布到AS 500
9、IBGP使用换回接口建邻,EBGP使用物理接口建邻
10、修改AS 123中的用户网段为Broadcast,方便后续在BGP中宣告
11、BGP宣告路由时,仅宣告24网段的用户路由
实验配置
配置ip及环回
配置OSPF
建立BGP环境
宣告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
使用PreVal策略,确保R4通过R2到达192.168.10.0/24
[r4]ip ip-prefix PV permit 192.168.10.0 24
[r4]route-policy PV permit node 10
[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
[r4]bgp 400
[r4-bgp]peer 12.0.0.2 route-policy PV import
使用AS_Path策略,确保R4通过R3到达192.168.11.0/24
[r4]ip ip-prefix AS permit 192.168.11.0 24
[r4]route-policy AS permit node 10
Info: New Sequence of this List.
[r4-route-policy]if-match ip-prefix AS
[r4-route-policy]apply as-path 123 overwrite
配置MED策略,确保R4通过R3到达192.168.12.0/24
[r4]ip ip-prefix MED permit 192.168.12.0 24
[r4]route-policy MED permit node 20
[r4-route-policy]if-match ip-prefix MED
[r4-route-policy]apply cost 10
[r4]route-policy MED permit node 10
使用Local Perference策略,确保R1通过R2到达192.168.1.0/24
[r1]ip ip-prefix LP permit 192.168.1.0 24
[r1]route-policy LP permit node 10
Info: New Sequence of this List.
[r1-route-policy]if-match ip-prefix LP
[r1-route-policy]apply local-preference 200
[r1-route-policy]q
[r1]bgp 123
[r1-bgp]peer 2.2.2.2 route-policy LP import
使用Local Perference策略,确保R1通过R3到达192.168.2.0/24
[r1]ip ip-prefix LP1 permit 192.168.2.0 24
[r1]route-policy LP1 permit node 10
[r1-route-policy]if-match ip-prefix LP1
[r1-route-policy]apply local-preference 200
[r1-route-policy]q
[r1]route-policy LP1 permit node 20
[r1-route-policy]q
[r1]bgp 123
[r1-bgp]peer 3.3.3.3 route-policy LP1 import
配置负载均衡,确保R1通过R2和R3到达192.168.3.0/24
[r1]bgp 123
[r1-bgp]maximum load-balancing 2
使用AS策略,AS 500不接受任何始发于AS 123的路由
[r5]ip as-path-filter 1 deny _123$
[r5]ip as-path-filter 1 permit .*
[r5]bgp 500
[r5-bgp]peer 15.0.0.1 as-path-filter 1 export
使用自定义Community策略,确保192.168.3.0/24路由不被发布到AS 500
[r2]bgp 123
[r2-bgp]peer 1.1.1.1 advertise-community
[r2]ip community-filter 1 permit 400:111
[r2]route-policy com deny node 10
[r2-route-policy]if-match community-filter 1
[r2-route-policy]apply community no-export additive
[r2-route-policy]q
[r2]route-policy com permit node 100
[r2]bgp 123
[r2-bgp]peer 12.0.0.4 route-policy com import
[r3]bgp 123
[r3-bgp]peer 1.1.1.1 advertise-community
[r3]ip community-filter 1 permit 400:111
[r3]route-policy com deny node 10
[r3-route-policy]if-match community-filter 1
[r3-route-policy]apply community no-export additive
[r3-route-policy]q
[r3]route-policy com permit node 100
[r3]bgp 123
[r3-bgp]peer 14.0.0.4 route-policy com import
[r4]route-policy com-1 permit node 10
[r4-route-policy]apply community 400:111
[r4]bgp 400
[r4-bgp]network 192.168.3.0 24 route-policy com-1
[r4-bgp]peer 12.0.0.2 advertise-ext-community
[r4-bgp]peer 14.0.0.3 advertise-ext-community