BGP路由优化

一,拓扑

二,要求

用preva1策略确保R4通过R2到达192.168.10.0/24
,用AS Path策略,确保R4通过R3到达192.168.11.0/24
置MED策略,确保R4通过R3到达192.168.12.0/24
.用Local Preference策略,确保R1通过R2到达192.168.1.0/24
确保R1通过R3到达192.168.2.0/24用Local
 Preference策略,2置负载均衡,确保R1通过R2和R3到达192.168.3.0/24
使用As策略,As 5aa不接受任何始发于As 123的路由
使用自定义community策略,确保192.168.3.0/24路由不会被发布到AS 5009、
IBGP使用环回接口建邻,EBGP使用物理接口建邻方便后续在BGP中宣告修改AS 123中的用户网段为Broadcast
,18、11、BGP宣告路由时,仅宣告24网段的用户路由

三,配置

r1
IP配置;
[r1]interface GigabitEthernet 0/0/0
[r1-GigabitEthernet0/0/0]ip address 24.0.0.1 24
[r1]interface GigabitEthernet 0/0/1
[r1-GigabitEthernet0/0/1]ip address 34.0.0.1 24
[r1]interface GigabitEthernet 0/0/2
[r1-GigabitEthernet0/0/2]ip address 15.0.0.1 24
[r1]interface LoopBack 0
[r1-LoopBack0]ip address 1.1.1.1 32      
[r1]interface LoopBack 1
[r1-LoopBack1]ip add    
[r1-LoopBack1]ip address 192.168.100.1 24
[r1-LoopBack1]ospf network-type broadcast ---修改环回接口类型为broadcast(让环回接口ip地址掩码在路由表中为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 192.168.100.0 0.0.0.255
[r1-ospf-1-area-0.0.0.0]network 24.0.0.1 0.0.0.0    
[r1-ospf-1-area-0.0.0.0]network 34.0.0.1 0.0.0.0

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 LoopBack 0
[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 LoopBack 0
[r1-bgp]peer 3.3.3.3 next-hop-local
[r1-bgp]network 192.168.100.0 24


[r1]ip ip-prefix aa permit 192.168.1.0 24---抓流量
[r1]ip ip-prefix bb permit 192.168.2.0 24

[r1]route-policy aa permit node 10--做策略,修改locprf值越大越优
[r1-route-policy]if-match ip-prefix aa
[r1-route-policy]apply local-preference 200

[r1]route-policy aa permit node 20--放通所有


[r1]route-policy bb permit node 10
[r1-route-policy]if-match ip-prefix bb    
[r1-route-policy]apply local-preference 200

[r1]route-policy bb permit node 20
    
[r1]bgp 123---调用
[r1-bgp]peer 2.2.2.2 route-policy aa import
[r1-bgp]peer 3.3.3.3 route-policy bb import 

[r1-bgp]maximum load-balancing 2---满足负载平衡规则,修改最大负载条目为2

方法1(使用自定义community策略,确保192.168.3.0/24路由不会被发布到AS 500)
[r1]ip ip-prefix cc permit 192.168.3.0 24--抓流量

[r1]route-policy aa permit node 15--做策略调用community中的no-export(不传递给EBGP但会传递给联邦EBGP)
[r1-route-policy]if-match ip-prefix cc
[r1-route-policy]apply community no-export
    
[r1]route-policy bb permit node 15    
[r1-route-policy]if-match ip-prefix cc    
[r1-route-policy]apply community no-export


方法2:
[r1-bgp]peer 15.0.0.5 advertise-community---开启社团属性传播性

[r1]ip community-filter 1 permit 400:500---抓流量(有标签400:500)

[r1]route-policy cc deny node 10--做策略(拒绝标签400:500)
[r1-route-policy]if-match community-filter 1 
    
[r1]route-policy cc permit node 20---放通所有
    
[r1]bgp 123---出方向调用    
[r1-bgp]peer 15.0.0.5 route-policy cc export 

r2
[r2]interface GigabitEthernet 0/0/0
[r2-GigabitEthernet0/0/0]ip address 12.0.0.2 24
[r2]interface GigabitEthernet 0/0/1
[r2-GigabitEthernet0/0/1]ip address 24.0.0.2 24
[r2]interface LoopBack 0
[r2-LoopBack0]ip address 2.2.2.2 32 
[r2]interface LoopBack 1
[r2-LoopBack1]ip address 192.168.20.1 24
[r2-LoopBack1]ospf network-type broadcast

[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 192.168.20.0 0.0.0.255
[r2-ospf-1-area-0.0.0.0]network 24.0.0.2 0.0.0.0

[r2]bgp 123
[r2-bgp]router-id 2.2.2.2
[r2-bgp]peer 12.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 LoopBack 0    
[r2-bgp]peer 1.1.1.1 next-hop-local
[r2-bgp]network 192.168.20.0 24

[r2]ip ip-prefix aa permit 192.168.12.0 24---抓流量
    
[r2]route-policy aa permit node 10---修改cost值
[r2-route-policy]if-match ip-prefix aa
[r2-route-policy]apply cost 200

[r2]route-policy aa permit node 20--放通所有

[r2]bgp 123    ---调用
[r2-bgp]peer 12.0.0.4 route-policy aa export 

[r2-bgp]peer 1.1.1.1 advertise-community---开启社团属性传播性    
r3
[r3]interface GigabitEthernet 0/0/0
[r3-GigabitEthernet0/0/0]ip address 13.0.0.3 24
[r3]interface GigabitEthernet 0/0/1
[r3-GigabitEthernet0/0/1]ip address 34.0.0.3 24
[r3]interface LoopBack 0
[r3-LoopBack0]ip address 3.3.3.3 32
[r3]interface LoopBack 1
[r3-LoopBack1]ip address 192.168.30.1 24
[r3-LoopBack1]ospf network-type broadcast 

[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 34.0.0.3 0.0.0.0 
[r3-ospf-1-area-0.0.0.0]network 192.168.30.0 0.0.0.255

[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 LoopBack 0
[r3-bgp]peer 1.1.1.1 next-hop-local     
[r3-bgp]peer 13.0.0.4 as-number 400
[r3-bgp]network 192.168.30.0 24

[r3]ip ip-prefix aa permit 192.168.12.0 24---抓流量

[r3]route-policy aa permit node 10---做策略,修改cost(med(干涉别人的))值,越小越优
[r3-route-policy]if-match ip-prefix aa
[r3-route-policy]apply cost 20    

[r3]route-policy aa permit node 20---放通所有

[r3]bgp 123---调用(出方向)
[r3-bgp]peer 13.0.0.4 route-policy aa export

[r3-bgp]peer 1.1.1.1 advertise-community---开启社团属性传播性
r4
[r4]interface GigabitEthernet 0/0/0
[r4-GigabitEthernet0/0/0]ip address 12.0.0.4 24
[r4]interface GigabitEthernet 0/0/1
[r4-GigabitEthernet0/0/1]ip address 13.0.0.4 24
[r4]interface LoopBack 0    
[r4-LoopBack0]ip address 4.4.4.4 32
[r4]interface LoopBack 1
[r4-LoopBack1]ip address 192.168.2.1 24
[r4-LoopBack1]interface LoopBack 2
[r4-LoopBack2]ip address 192.168.3.1 24
[r4]interface LoopBack 3    
[r4-LoopBack3]IP address 192.168.1.1 24

[r4]bgp 400
[r4-bgp]router-id 4.4.4.4    
[r4-bgp]peer 12.0.0.2 as-number 123    
[r4-bgp]peer 13.0.0.3 as-number 123
[r4-bgp]network 192.168.1.0 24
[r4-bgp]network 192.168.2.0 24
[r4-bgp]network 192.168.3.0 24

[r4]ip ip-prefix aa permit 192.168.10.0 24---抓流量
[r4]ip ip-prefix bb permit 192.168.11.0 24 

[r4]route-policy aa permit node 10---做策略,修改PV值让它大于r3的PV值,则会优选r2
[r4-route-policy]if-match ip-prefix aa
[r4-route-policy]apply preferred-value 100

[r4]route-policy aa permit node 15---做策略,修改AS-PATH值让它大于r3,则会优选r3
[r4-route-policy]if-match ip-prefix bb
[r4-route-policy]apply as-path 123 123 500 overwrite 

[r4]route-policy aa permit node 20---放通所有

[r4]bgp 400----调用策略10,15
[r4-bgp]peer 12.0.0.2 route-policy aa import

方法2:
[r4]route-policy cc permit node 10--做标签
[r4-route-policy]apply community 400:500

[r4]bgp 400    ---调用标签
[r4-bgp]network 192.168.3.0 route-policy cc 

[r4-bgp]peer 12.0.0.2 advertise-community---开启社团属性传播性    
[r4-bgp]peer 13.0.0.3 advertise-community


r5
[r5]interface GigabitEthernet 0/0/0
[r5-GigabitEthernet0/0/0]ip address 15.0.0.5 24    
[r5]interface LoopBack 0
[r5-LoopBack0]ip address 5.5.5.5 32 
[r5]interface LoopBack 1
[r5-LoopBack1]ip address 192.168.11.1 24
[r5-LoopBack1]interface LoopBack 2
[r5-LoopBack2]ip address 192.168.12.1 24
[r5]interface LoopBack 3
[r5-LoopBack3]ip address 192.168.10.1 24

BGP配置:

[r5]bgp 500    
[r5-bgp]router-id 5.5.5.5    
[r5-bgp]peer 15.0.0.1 as-number 123
[r5-bgp]network 192.168.10.0 24
[r5-bgp]network 192.168.11.0 24
[r5-bgp]network 192.168.12.0 24

[r5]ip as-path-filter 1 deny ^123$--拒绝始发与AS 123的路由
[r5]ip as-path-filter 1 permit .*--放通所有

[r5-bgp]peer 15.0.0.1 as-path-filter 1 import --在入方向调用

四,测试

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值