实验要求
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 Preference策略,确保R1通过R2到达192.168.1.0/24 |
5 使用Local Preference策略,确保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
R1
<Huawei>sys
[Huawei]sys r1
[r1]int g0/0/0
[r1-GigabitEthernet0/0/0]ip add 12.0.0.1 24
[r1-GigabitEthernet0/0/0]int g0/0/1
[r1-GigabitEthernet0/0/1]ip add 13.0.0.1 24
[r1-GigabitEthernet0/0/1]int g0/0/2
[r1-GigabitEthernet0/0/2]ip add 15.0.0.1 24
[r1-GigabitEthernet0/0/2]int lo0
[r1-LoopBack0]ip add 1.1.1.1 32
[r1-LoopBack0]int lo1
[r1-LoopBack1]ip add 192.168.100.1 24
R2
<Huawei>sys
[Huawei]sys r2
[r2]int g0/0/0
[r2-GigabitEthernet0/0/0]ip add 24.0.0.2 24
[r2-GigabitEthernet0/0/0]int g0/0/1
[r2-GigabitEthernet0/0/1]ip add 12.0.0.2 24
[r2-GigabitEthernet0/0/1]int lo0
[r2-LoopBack0]ip add 2.2.2.2 32
[r2-LoopBack0]int lo1
[r2-LoopBack1]ip add 192.168.20.1 24
R3
<Huawei>sys
[Huawei]sys r3
[r3]int g0/0/0
[r3-GigabitEthernet0/0/0]ip add 34.0.0.3 24
[r3-GigabitEthernet0/0/0]int g0/0/1
[r3-GigabitEthernet0/0/1]ip add 13.0.0.3 24
[r3-GigabitEthernet0/0/1]int lo0
[r3-LoopBack0]ip add 3.3.3.3 32
[r3-LoopBack0]int lo1
[r3-LoopBack1]ip add 192.168.30.1 24
R4
<Huawei>sys
[Huawei]sys r4
[r4]int g0/0/0
[r4-GigabitEthernet0/0/0]ip add 24.0.0.4 24
[r4-GigabitEthernet0/0/0]int g0/0/1
[r4-GigabitEthernet0/0/1]ip add 34.0.0.4 24
[r4-GigabitEthernet0/0/1]int lo0
[r4-LoopBack0]ip add 192.168.1.1 24
[r4-LoopBack0]int lo1
[r4-LoopBack1]ip add 192.168.2.1 24
[r4-LoopBack1]int lo2
[r4-LoopBack2]ip add 192.168.3.1 24
R5
<Huawei>sys
[Huawei]sys r5
[r5]int g0/0/0
[r5-GigabitEthernet0/0/0]ip add 15.0.0.5 24
[r5-GigabitEthernet0/0/0]int lo0
[r5-LoopBack0]ip add 192.168.10.1 24
[r5-LoopBack0]int lo1
[r5-LoopBack1]ip add 192.168.11.1 24
[r5-LoopBack1]int lo2
[r5-LoopBack2]ip add 192.168.12.1 24
在AS123中配置OSPF
R1
[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.0 0.0.0.255
[r1-ospf-1-area-0.0.0.0]network 12.0.0.0 0.0.0.255
[r1-ospf-1-area-0.0.0.0]network 13.0.0.0 0.0.0.255
[r1-ospf-1-area-0.0.0.0]network 192.168.100.0 0.0.0.255
R2
[r2]ospf 1 router-id 2.2.2.2
[r2-ospf-1]a 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 12.0.0.0 0.0.0.255
[r2-ospf-1-area-0.0.0.0]network 192.168.20.0 0.0.0.255
R3
[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 13.0.0.0 0.0.0.255
[r3-ospf-1-area-0.0.0.0]network 192.168.30.0 0.0.0.255
ping测试
BGP配置
R4
[r4]bgp 400
[r4-bgp]router-id 4.4.4.4
[r4-bgp]peer 24.0.0.2 as-number 123
[r4-bgp]peer 34.0.0.3 as-number 123
[r4-bgp]network 192.168.1.0
[r4-bgp]network 192.168.2.0
[r4-bgp]network 192.168.3.0
R2
[r2]bgp 123
[r2-bgp]router-id 2.2.2.2
[r2-bgp]peer 1.1.1.1 as-number 123
[r2-bgp]peer 1.1.1.1 connect-interface lo0
[r2-bgp]peer 24.0.0.4 as-number 400
[r2-bgp]network 192.168.20.0
[r2-bgp]network 192.168.30.0
[r2-bgp]network 192.168.100.00
[r2-bgp]peer 1.1.1.1 next-hop-local
R3
[r3]bgp 123
[r3-bgp]router-id 3.3.3.3
[r3-bgp]peer 1.1.1.1 as-number 123
[r3-bgp]peer 1.1.1.1 connect-interface lo0
[r3-bgp]peer 34.0.0.4 as-number 400
[r3-bgp]network 192.168.20.0
[r3-bgp]network 192.168.30.0
[r3-bgp]network 192.168.100.0
[r3-bgp]peer 1.1.1.1 next-hop-local
R1
[r1]bgp 123
[r1-bgp]peer 2.2.2.2 as-number 123
[r1-bgp]peer 2.2.2.2 connect-interface lo0
[r1-bgp]peer 3.3.3.3 as-number 123
[r1-bgp]peer 3.3.3.3 connect-interface lo0
[r1-bgp]peer 15.0.0.5 as-number 500
[r1-bgp]network 192.168.20.0
[r1-bgp]network 192.168.30.0
[r1-bgp]network 192.168.100.0
[r1-bgp]peer 2.2.2.2 next-hop-local
[r1-bgp]peer 3.3.3.3 next-hop-local
R5
[s5]bgp 500
[s5-bgp]peer 15.0.0.1 as-number 123
[s5-bgp]network 192.168.10.0
[s5-bgp]network 192.168.11.0
[s5-bgp]network 192.168.12.0
检查对等体是否建立成功 display bgp peer
要求
1 使用PreVal策略,确保R4通过R2到达192.168.10.0/24
[r4]ip ip-prefix aa permit 192.168.10.0 24
[r4]route-policy aa permit node 10
Info: New Sequence of this List.
[r4-route-policy]if-match ip-prefix aa
[r4-route-policy]apply preferred-value 1000
[r4-route-policy]q
[r4]route-policy aa permit node 20
Info: New Sequence of this List.
[r4]bgp 400
[r4-bgp]peer 24.0.0.2 route-policy aa import
2 使用AS_Path策略,确保R4通过R3到达192.168.11.0/24
[r4]ip ip-prefix bb index 10 permit 192.168.11.0 24
[r4]route-policy aa permit node 15
Info: New Sequence of this List.
[r4-route-policy]if-match ip-prefix bb
[r4-route-policy]apply as-path 123 123 500 500 overwrite
Warning: The AS-Path lists of routes to which this route-policy is applied will
be overwritten. Continue? [Y/N]y
查看BGP路由表AS_Path属性
3 配置MED策略,确保R4通过R3到达192.168.12.0/24
[r4]ip ip-prefix MED permit 192.168.12.0 24
[r4]route-policy aa permit node 16
[r4-route-policy]if-match ip-prefix MED
[r4-route-policy]apply cost 500
[r4-route-policy]q
[r4]route-policy bb permit node 10
[r4-route-policy]if-match ip-prefix MED
[r4-route-policy]apply cost 200
[r4-route-policy]q
[r4]route-policy bb permit node 20
[r4-route-policy]bgp 400
[r4-bgp]peer 34.0.0.3 route-policy bb import
4 使用Local Preference策略,确保R1通过R2到达192.168.1.0/24
[R1]ip ip-prefix LP permit 192.168.1.0 24
[R1]route-policy aa permit node 10
[R1-route-policy]if-match ip-prefix LP PE
[R1-route-policy]apply local-preference 200
[R1]route-policy aa permit node 20
[R1]bgp 123
[R1-bgp]peer 2.2.2.2 route-policy aa import
5 使用Local Preference策略,确保R1通过R3到达192.168.2.0/24
[R1]ip ip-prefix LP2 permit 192.168.2.0 24
[R1]route-policy bb permit node 10
[R1-route-policy]if-match ip-prefix LP2
[R1-route-policy]apply local-preference 200
[R1]route-policy bb permit node 20
[R1]bgp 123
[R1-bgp]peer 3.3.3.3 route-policy bb import
6、配置负载均衡,确保R1通过R2和R3到达192.168.3.0/24
[R1]bgp 123
[R1-bgp]maximum load-balancing 2 //配置BGP最大负载均衡条目为2,默认情况1,所以BGP默认情况不存在负载分担。
7、使用AS策略,AS 500不接受任何始发于AS 123的路由
1、抓取流量
[R5]ip as-path-filter 1 deny ^123$
[R5]ip as-path-filter 1 permit .*
2、调用
[R5]bgp 500
[R5-bgp]peer 15.0.0.1 as-path-filter 1 import
8、使用自定义Community策略,确保192.168.3.0/24路由不会被发布到AS 500
[R4]route-policy com permit node 10
[R4-route-policy]apply community 400:500
[R4]bgp 400
[R4-bgp]network 192.168.3.0 route-policy com
开通社团属性功能
[R4]bgp 400
[R4-bgp]peer 24.0.0.2 advertise-community
[R4-bgp]peer 34.0.0.3 advertise-community
[R2]bgp 123
[R2-bgp]peer 1.1.1.1 advertise-community
[R3]bgp 123
[R3-bgp]peer 1.1.1.1 advertise-community
对携带社团属性的流量做路由策略
1、抓取社团属性为 400:500 的流量
[R1]ip community-filter 1 permit 400:500
2、做策略
[R1]route-policy com deny node 10
[R1-route-policy]if-match community-filter 1
[R1]route-policy com permit node 20
3、调用
[R1]bgp 123
[R1-bgp]peer 15.0.0.5 route-policy com export