bgp LP本地优先属性配置与详解

本文旨在深入理解BGP的本地优选属性,包括其配置方法和默认值。实验显示,当本地优先属性值较高时,路径将被优先选择。通过调整此属性,可以控制数据流离开自治系统的路径。在实验中,通过改变R4的本地优先属性值,影响了R3的路由选择,展示了BGP如何根据本地优先属性选择最佳路由。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

实验目的:

1、理解掌握BGP的本地优选属性概念和配置方法。

2、本地优选的属性默认值为100,较高值的路径会被优先选择。

3、本地优先属性,决定离开本自治系统最佳的路径。

实验拓扑:

步骤1:接口IP配置

R1(config)#interface f0/0
R1(config-if)#ip address 12.12.12.1 255.255.255.0
R1(config-if)#no shutdown 
R1(config-if)#interface f0/1                     
R1(config-if)#ip address 14.14.14.1 255.255.255.0
R1(config-if)#no shutdown 
R1(config)#interface loopback 0
R1(config-if)#ip address 1.1.1.1  255.255.255.0 

R2(config)#interface f0/0
R2(config-if)#ip address 12.12.12.2 255.255.255.0
R2(config-if)#no shutdown 
R2(config-if)#interface f0/1                     
R2(config-if)#ip address 23.23.23.2 255.255.255.0
R2(config-if)#no shutdown 

R3(config)#interface f0/1
R3(config-if)#ip address 23.23.23.3 255.255.255.0
R3(config-if)#no shutdown 
R3(config-if)#interface f0/0                     
R3(config-if)#ip address 34.34.34.3 255.255.255.0
R3(config-if)#no shutdown 

R4(config)#interface f0/0
R4(config-if)#ip address 34.34.34.4 255.255.255.0
R4(config-if)#no shutdown 
R4(config-if)#interface f0/1                     
R4(config-if)#ip address 14.14.14.4 255.255.255.0 
R4(config-if)#no shutdown 

步骤2 :bgp协议基本配置

R1(config)#router bgp  12
R1(config-router)#network 12.12.12.0 mask 255.255.255.0
R1(config-router)#network 14.14.14.0 mask 255.255.255.0
R1(config-router)#network 1.1.1.0  mask 255.255.255.0
R1(config-router)#neighbor 12.12.12.2 remote-as 12
R1(config-router)#neighbor 23.23.23.3 remote-as 34
R1(config-router)#neighbor 14.14.14.4 remote-as 34

R2(config)#router bgp  12
R2(config-router)#network 12.12.12.0 mask 255.255.255.0
R2(config-router)#network 23.23.23.0 mask 255.255.255.0
R2(config-router)#neighbor 12.12.12.1 remote-as 12
R2(config-router)#neighbor 23.23.23.3 remote-as 34
R2(config-router)#neighbor 34.34.34.4  remote-as 34

R3(config)#router bgp 34
R3(config-router)#network 23.23.23.0 mask 255.255.255.0
R3(config-router)#network 34.34.34.0 mask 255.255.255.0
R3(config-router)#neighbor 34.34.34.4 remote-as 34
R3(config-router)#neighbor 12.12.12.1 remote-as 12
R3(config-router)#neighbor 23.23.23.2 remote-as 12

R4(config)#router bgp 34
R4(config-router)#network 14.14.14.0 mask 255.255.255.0
R4(config-router)#network 34.34.34.0 mask 255.255.255.0
R4(config-router)#neighbor 34.34.34.3 remote-as 34
R4(config-router)#neighbor 14.14.14.1 remote-as 12
R4(config-router)#neighbor 23.23.23.2 remote-as 12

查看bgp peer关系建立情况:

R1(config-router)#do show ip bgp summary 
BGP router identifier 1.1.1.1, local AS number 12
BGP table version is 5, main routing table version 5
4 network entries using 468 bytes of memory
5 path entries using 260 bytes of memory
3/2 BGP path/bestpath attribute entries using 372 bytes of memory
0 BGP route-map cache entries using 0 bytes of memory
0 BGP filter-list cache entries using 0 bytes of memory
BGP using 1100 total bytes of memory
BGP activity 4/0 prefixes, 5/0 paths, scan interval 60 secs

Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
12.12.12.2      4    12      10      10        5    0    0 00:06:41        2
14.14.14.4      4    34       0       0        0    0    0 never    Active
23.23.23.3      4    34       0       0        0    0    0 never    Active

这是因为bgp的水平分割防环机制。对当前路由器而言,路由更新来自于ibgp peer,就不会发送给其他任何ibgp peer。水平拓扑上ibgp水平分割会导致路由更新不学习。

以23.23.23.0/24网络为例,R2将该路由条目更新发送给R1,R1将其转发给R4学习。对于R1而言,该路由条目更新来自ibgp,则学习,对于R4而言,该路由条目更新来自于ebgp,但该ebgp 属于自身所在as内,故不学习,导致bgp peer-address不可达,peer关系建立失败。

R1(config-router)#router bgp 12
R1(config-router)# neighbor 14.14.14.4 next-hop-self
//将发给对等体的路由下一跳设为自己

R2(config-router)#router bgp 12
R2(config-router)# neighbor 23.23.23.3 next-hop-self

R3(config-router)#router bgp 34
R3(config-router)# neighbor 23.23.23.2 next-hop-self

R4(config-router)#router bgp 34
R4(config-router)# neighbor 14.14.14.1 next-hop-self

此时全网互通

R1#show ip route 

Gateway of last resort is not set

     34.0.0.0/24 is subnetted, 1 subnets
B       34.34.34.0 [20/0] via 14.14.14.4, 00:09:15
     1.0.0.0/24 is subnetted, 1 subnets
C       1.1.1.0 is directly connected, Loopback0
     23.0.0.0/24 is subnetted, 1 subnets
B       23.23.23.0 [200/0] via 12.12.12.2, 00:09:15
     12.0.0.0/24 is subnetted, 1 subnets
C       12.12.12.0 is directly connected, FastEthernet0/0
     14.0.0.0/24 is subnetted, 1 subnets
C       14.14.14.0 is directly connected, FastEthernet0/1

查看R3路由表

R3#show ip route 

Gateway of last resort is not set

     34.0.0.0/24 is subnetted, 1 subnets
C       34.34.34.0 is directly connected, FastEthernet0/0
     1.0.0.0/24 is subnetted, 1 subnets
B       1.1.1.0 [20/0] via 23.23.23.2, 00:10:56
//R3到达1.1.1.0/24网络的下一跳是23.23.23.2
     23.0.0.0/24 is subnetted, 1 subnets
C       23.23.23.0 is directly connected, FastEthernet0/1
     12.0.0.0/24 is subnetted, 1 subnets
B       12.12.12.0 [20/0] via 23.23.23.2, 00:27:09
     14.0.0.0/24 is subnetted, 1 subnets
B       14.14.14.0 [200/0] via 34.34.34.4, 00:29:09

查看R4路由表

R4#show ip route 

Gateway of last resort is not set

     34.0.0.0/24 is subnetted, 1 subnets
C       34.34.34.0 is directly connected, FastEthernet0/0
     1.0.0.0/24 is subnetted, 1 subnets
B       1.1.1.0 [20/0] via 14.14.14.1, 00:12:35
//R4到达1.1.1.0/24的网络下一跳是14.14.14.1
     23.0.0.0/24 is subnetted, 1 subnets
B       23.23.23.0 [200/0] via 34.34.34.3, 00:30:37
     12.0.0.0/24 is subnetted, 1 subnets
B       12.12.12.0 [20/0] via 14.14.14.1, 00:12:35
     14.0.0.0/24 is subnetted, 1 subnets
C       14.14.14.0 is directly connected, FastEthernet0/1

理论上BGP选择的都是最佳路由,但该例中我们通过本地配置“本地优先”来确定数据流如何流出本自治系统。

查看R3的BGP数据库信息表。

R3#show ip bgp
BGP table version is 19, local router ID is 34.34.34.3
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
* i1.1.1.0/24       14.14.14.1               0    100      0 12 i
//100为默认的本地优先属性值。
*>                  23.23.23.2                             0 12 i
* i12.12.12.0/24    14.14.14.1               0    100      0 12 i
*>                  23.23.23.2               0             0 12 i
*  14.14.14.0/24    23.23.23.2                             0 12 i
*>i                 34.34.34.4               0    100      0 i
*  23.23.23.0/24    23.23.23.2               0             0 12 i
*>                  0.0.0.0                  0         32768 i
*> 34.34.34.0/24    0.0.0.0                  0         32768 i
* i                 34.34.34.4               0    100      0 i

查看R4的BGP的数据库信息表:

R4#show ip bgp 
BGP table version is 22, local router ID is 34.34.34.4
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
* i1.1.1.0/24       23.23.23.2               0    100      0 12 i
*>                  14.14.14.1               0             0 12 i
*> 12.12.12.0/24    14.14.14.1               0             0 12 i
* i                 23.23.23.2               0    100      0 12 i
*  14.14.14.0/24    14.14.14.1               0             0 12 i
*>                  0.0.0.0                  0         32768 i
*  23.23.23.0/24    14.14.14.1                             0 12 i
*>i                 34.34.34.3               0    100      0 i
* i34.34.34.0/24    34.34.34.3               0    100      0 i
*>                  0.0.0.0                  0         32768 i

通过对比R3与R4路由器的BGP数据库,只需要调整R4路由器所学习的所有BGP路由的本地优先值。因为BGP会优先选择本地优先属性值较高的路由。

配置R4的路由器,调整本地优先属性值为200:

R4(config)#router bgp 34
R4(config-router)#bgp default local-preference 200

查看R3的BGP数据库:

R3#show ip bgp     
BGP table version is 11, local router ID is 34.34.34.3
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 1.1.1.0/24       23.23.23.2                             0 12 i
//当对R4的本地优先属性进行调整后,在R3上会发现从R4学习到的路由的本地优先已经改变200。
//同时,也可以看出,此时,R3到达1.1.1.0/24的子网,其下一跳为23.23.23.2,为最佳路由。
*> 12.12.12.0/24    23.23.23.2               0             0 12 i
*> 14.14.14.0/24    23.23.23.2                             0 12 i
*> 23.23.23.0/24    0.0.0.0                  0         32768 i
*                   23.23.23.2               0             0 12 i
*> 34.34.34.0/24    0.0.0.0                  0         32768 i

再次查看R3的路由表:

R3#show ip route 

Gateway of last resort is not set

     34.0.0.0/24 is subnetted, 1 subnets
C       34.34.34.0 is directly connected, FastEthernet0/0
     1.0.0.0/24 is subnetted, 1 subnets
B       1.1.1.0 [20/0] via 23.23.23.2, 00:01:01
     23.0.0.0/24 is subnetted, 1 subnets
C       23.23.23.0 is directly connected, FastEthernet0/1
     12.0.0.0/24 is subnetted, 1 subnets
B       12.12.12.0 [20/0] via 23.23.23.2, 00:01:01
     14.0.0.0/24 is subnetted, 1 subnets
B       14.14.14.0 [20/0] via 23.23.23.2, 00:01:01

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值