BGP路由策略实验

实验要求

要求:
要求:
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网段的用户路由

实验拓扑

实验步骤

基本配置

1、配置IP、修改环回接口类型

[R1]int g0/0/0
[R1-GigabitEthernet0/0/0]ip ad 12.0.0.1 24
[R1-GigabitEthernet0/0/0]int g0/0/1
[R1-GigabitEthernet0/0/1]ip ad 13.0.0.1 24
[R1-GigabitEthernet0/0/1]int g0/0/2
[R1-GigabitEthernet0/0/2]ip ad 15.0.0.1 24
[R1-GigabitEthernet0/0/2]int l0
[R1-LoopBack0]ip ad 1.1.1.1 32
[R1-LoopBack0]int l1
[R1-LoopBack1]ip ad 192.168.100.1 24
[R1-LoopBack1]ospf network-type broadcast 

[R2]int g0/0/0
[R2-GigabitEthernet0/0/0]ip ad 24.0.0.2 24
[R2-GigabitEthernet0/0/0]int g0/0/1
[R2-GigabitEthernet0/0/1]ip ad 12.0.0.2 24
[R2-GigabitEthernet0/0/1]int l0
[R2-LoopBack0]ip ad 2.2.2.2 32
[R2-LoopBack0]int l1
[R2-LoopBack1]ip ad 192.168.20.1 24
[R2-LoopBack1]ospf network-type  broadcast 

[R3]int g0/0/0
[R3-GigabitEthernet0/0/0]ip ad 34.0.0.3 24
[R3-GigabitEthernet0/0/0]int g0/0/1
[R3-GigabitEthernet0/0/1]ip ad 13.0.0.3 24
[R3-GigabitEthernet0/0/1]int l0
[R3-LoopBack0]ip ad 3.3.3.3 32
[R3-LoopBack0]int l1
[R3-LoopBack1]ip ad 192.168.30.1 24
[R3-LoopBack1]ospf network-type  broadcast 

[R4]int g0/0/0
[R4-GigabitEthernet0/0/0]ip ad 24.0.0.4 24
[R4-GigabitEthernet0/0/0]int g0/0/1
[R4-GigabitEthernet0/0/0]ip ad 34.0.0.4 24
[R4-GigabitEthernet0/0/0]int l0
[R4-LoopBack0]ip ad 192.168.1.1 24
[R4-LoopBack0]int l1
[R4-LoopBack1]ip ad 192.168.2.1 24
[R4-LoopBack1]int l2
[R4-LoopBack2]ip ad 192.168.3.1 24

[R5]int g0/0/0
[R5-GigabitEthernet0/0/0]ip ad 15.0.0.5 24
[R5-GigabitEthernet0/0/0]int l0
[R5-LoopBack0]ip ad 192.168.10.1 24
[R5-LoopBack0]int l1
[R5-LoopBack1]ip ad 192.168.11.1 24
[R5-LoopBack1]int l2
[R5-LoopBack2]ip ad 192.168.12.1 24

测试互通

2、开启OSPF,搭建IGP

[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 12.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 12.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 13.0.0.3 0.0.0.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 192.168.30.1 0.0.0.0

3、配置BGP

[R1]bgp 123
[R1-bgp]router-id 1.1.1.1
[R1-bgp]peer 15.0.0.5 as-number 500
[R1-bgp]peer 2.2.2.2 as-number 123	
[R1-bgp]peer 2.2.2.2 connect-interface l0
[R1-bgp]peer 2.2.2.2 next-hop-local
[R1-bgp]peer 3.3.3.3 as-number 123	
[R1-bgp]peer 3.3.3.3 connect-interface l0
[R1-bgp]peer 3.3.3.3 next-hop-local

[R2]bgp 123
[R2-bgp]router-id 2.2.2.2
[R2-bgp]peer 24.0.0.4 as-number 400
[R2-bgp]peer 1.1.1.1 as-number 123
[R2-bgp]peer 1.1.1.1 connect-interface l0
[R2-bgp]peer 1.1.1.1 next-hop-local

[R3]bgp 123
[R3-bgp]router-id 3.3.3.3
[R3-bgp]peer 34.0.0.4 as-number 400
[R3-bgp]peer 1.1.1.1 as-number 123
[R3-bgp]peer 1.1.1.1 connect-interface l0
[R3-bgp]peer 1.1.1.1 next-hop-local

[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

[R5]bgp 500
[R5-bgp]router-id 5.5.5.5
[R5-bgp]peer 15.0.0.1 as-number 123

display bgp peer

4、宣告BGP路由

[R1]bgp 123
[R1-bgp]net 192.168.20.0 24
[R1-bgp]net 192.168.30.0 24
[R1-bgp]net 192.168.100.0 24

[R2]bgp 123
[R2-bgp]net 192.168.20.0 24
[R2-bgp]net 192.168.30.0 24
[R2-bgp]net 192.168.100.0 24

[R3]bgp 123
[R3-bgp]net 192.168.20.0 24
[R3-bgp]net 192.168.30.0 24
[R3-bgp]net 192.168.100.0 24

[R4]bgp 400
[R4-bgp]net 192.168.1.0 24
[R4-bgp]net 192.168.2.0 24
[R4-bgp]net 192.168.3.0 24

[R5]bgp 500
[R5-bgp]net 192.168.10.0 24
[R5-bgp]net 192.168.11.0 24
[R5-bgp]net 192.168.12.0 24

display bgp routing-table

需求配置

1、使用preval策略,确保R4通过R2到达192.168.10.0/24

  • PV属性,是华为的私有属性,可以看做为权重,数值越大,对应的路由优先级越高。
  • 默认值为0。 ​
  • 因为PV值是所有选路原则中的第一条原则,所以,该属性是本设备上选路最方便的一个属性——该属性只有在本地生效,无法传递给任何BGP对等体
[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 20
[R4-route-policy]q
[R4]bgp 400
[R4-bgp]peer 24.0.0.2 route-policy PV import

display bgp routing-table

display bgp routing-table 192.168.10.0

2、使用AS Path策略,确保R4通过R3到达192.168.11.0/24

  •  AS-Path属性越短则该路由越优,因为这条路径距离目的地所要经过的AS个数更少。
  •  AS_Path属性最开始是空的列表,当该路由被通告给一个EBGP对等体邻居时,才会被加上一个AS号,在每次经过一个AS时,都会在AS_Path属性的最前端增加最新的AS号。
    • 而该属性在IBGP对等体之间传播时,这条属性是不会发生改变
[R4]ip ip-prefix AS permit 192.168.11.0 24
[R4]route-policy AS permit node 10
[R4-route-policy]if-match ip-prefix AS
[R4-route-policy]apply as-path 123 overwrite
[R4-route-policy]q

[R4]bgp 400
[R4-bgp]peer 34.0.0.3 route-policy PV import

3、配置MED策略,确保R4通过R3到达192.168.12.0/24

  • MED值是继承了IGP协议的度量值。
  • MED属性值可以传递给自己的EBGP对等体,并且该EBGP对等体可以将该路由传递给自己的IBGP对等体,并且因为AS-BY-AS规则,该属性在IBGP对等体之间传递时不变。
  • MED属性可以干扰访问本地的流量的走向。也就是说,本AS的策略调整可以影响到别的AS对路径的判断,这是在BGP选路中唯一一个可以影响到其他AS的属性
    • 即MED是干涉其他的设备,所以MED不在R4上配置
  • BGP规定,非本地始发的BGP路由信息,在传递给自己的EBGP对等体时,将MED值修改为0。
[R2]ip ip-prefix MED permit 192.168.12.0 24
[R2]route-policy MED permit node 10
[R2-route-policy]if-match ip-prefix MED
[R2-route-policy]apply cost 200
[R2-route-policy]q
[R2]route-policy MED permit node 20

[R2]bgp 123
[R2-bgp]peer 24.0.0.4 route-policy MED export
[R3]ip ip-prefix MED permit 192.168.12.0 24
[R3]route-policy MED permit node 10
[R3-route-policy]if-match ip-prefix MED
[R3-route-policy]apply cost 200
[R3-route-policy]q
[R3]route-policy MED permit node 20

[R3]bgp 123
[R3-bgp]peer 34.0.0.4 route-policy MED export

4、使用Local Preference策略,确保R1通过R2到达192.168.1.0/24

  • 该属性的默认值为100,并且LP属性只能在IBGP对等体之间传递,而不能在EBGP对等体之间传递。
  • 如果路由在传递到本地时并不携带LP属性,则BGP在决策时,使用缺省值来计算。
  • 该属性越大越优。
  • 该属性的传递范围为本AS内部。
  • 该属性是AS内部优选路由的最佳选择。
[R1]ip ip-prefix LP1 permit 192.168.1.0 24
[R1]route-policy LP1 permit node 10
[R1-route-policy]if-match ip-prefix LP
[R1-route-policy]apply local-preference 200
[R1-route-policy]q
[R1]route-policy LP1 permit node 20

[R1]bgp 123
[R1-bgp]peer 2.2.2.2 route-policy LP 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 LP2 permit node 10
[R1-route-policy]if-match ip-prefix LP2
[R1-route-policy]apply local-preference 200
[R1-route-policy]q
[R1]route-policy LP1 permit node 20

[R1]bgp 123
[R1-bgp]peer 3.3.3.3 route-policy LP import

6、配置负载均衡,确保R1通过R2和R3到达192.168.3.0/24

[R1]bgp 123
[R1-bgp]maximum load-balancing 2

7、使用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 import
方法二:
[R1]ip as-path-filter 1 deny ^$
[R1]ip as-path-filter 1 permit .*

[R1]bgp 123
[R1-bgp]peer 15.0.0.5 as-path-filter 1 export

8、使用自定义Community策略,确保192.168.3.0/24路由不会被发布到AS 500

自定义Community策略 
[R4]route-policy com permit node 10
[R4-route-policy]apply community 400:500

[R4]bgp 400
[R4-bgp]network 192.168.3.0 24 route-policy com
[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

[R1]bgp 123
[R1-bgp]peer 15.0.0.5 advertise-community 
其他方法
[R1]ip ip-prefix cc permit 192.168.3.0 24
[R1]route-policy LP1 permit node 15
[R1-route-policy]if-match ip-prefix cc
[R1-route-policy]apply community no-export   #打上社团属性
[R1]route-policy LP2 permit node 15
[R1-route-policy]if-match ip-prefix cc
[R1-route-policy]apply community no-export   #打上社团属性
[R1]ip community-filter 1 permit 400:500
[R1]route-policy com deny node 10
[R1-route-policy]if-match community-filter 1
[R1-route-policy]q
[R1]route-policy com permit node 20

[R1]bgp 123
[R1]peer 15.0.0.5 route-policy com export
  • 26
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值