当使用BGP路径属性——本地优先级,进行路由优选时,优选“本地优先级”数值较大的那个。(eBGP之间更新不携带这个属性)
实验拓扑如下:
在未实现本地优先级策略前,先在各个BGP之间配置完成基本连接。
R1的基础配如下:
hostname R1
!
interface Loopback0
ip address 10.1.0.1 255.255.255.0
!
interface Loopback1
ip address 10.1.1.1 255.255.255.0
!
interface Ethernet0/0
ip address 100.100.12.1 255.255.255.0
no shut
!
interface Ethernet0/1
ip address 100.105.15.1 255.255.255.0
no shut
!
router bgp 100
network 10.1.0.0 mask 255.255.255.0
network 10.1.1.0 mask 255.255.255.0
aggregate-address 10.1.0.0 255.255.254.0 summary-only
neighbor 100.100.12.2 remote-as 234
neighbor 100.105.15.5 remote-as 500
!
end
R2的基础配如下:
hostname R2
!
interface Ethernet0/0
ip address 100.100.12.2 255.255.255.0
duplex auto
!
interface Ethernet0/1
ip address 10.23.88.2 255.255.255.0
duplex auto
!
router bgp 234
neighbor 10.23.88.3 remote-as 234
neighbor 10.23.88.3 next-hop-self
neighbor 100.100.12.1 remote-as 100
!
end
R3的基础配如下:
hostname R3
!
interface Loopback0
ip address 10.3.3.3 255.255.255.255
!
interface Ethernet0/0
ip address 10.23.88.3 255.255.255.0
no shut
!
interface Ethernet0/1
ip address 10.34.88.3 255.255.255.0
no shut
!
router bgp 234
network 10.3.3.3 mask 255.255.255.255
neighbor IBGP peer-group
neighbor IBGP remote-as 234
neighbor IBGP route-reflector-client
neighbor 10.23.88.2 peer-group IBGP
neighbor 10.34.88.4 peer-group IBGP
!
end
R4的基础配如下:
hostname R4
!
interface Ethernet0/0
ip address 10.34.88.4 255.255.255.0
no shut
!
interface Ethernet0/1
ip address 100.200.45.4 255.255.255.0
no shut
!
router bgp 234
neighbor 10.34.88.3 remote-as 234
neighbor 10.34.88.3 next-hop-self
neighbor 100.200.45.5 remote-as 500
!
end
R5的基础配如下:
hostname R5
!
interface Loopback2
ip address 10.1.2.5 255.255.255.0
!
interface Loopback3
ip address 10.1.3.5 255.255.255.0
!
interface Ethernet0/0
ip address 100.200.45.5 255.255.255.0
no shut
!
interface Ethernet0/1
ip address 100.105.15.5 255.255.255.0
no shut
!
router bgp 500
network 10.1.2.0 mask 255.255.255.0
network 10.1.3.0 mask 255.255.255.0
aggregate-address 10.1.2.0 255.255.254.0 summary-only
neighbor 100.105.15.1 remote-as 100
neighbor 100.200.45.4 remote-as 234
!
end
R1 ~ R5的BGP表如下:
使用本地优先级的作用在R2上应用eBGP入站策略,针对来自eBGP对等体的路由设置本地优先级设置为222;相同情况的R4针对目标网络10.1.3.0/24的路由设置本地优先级为333。
R2新增的配置如下:
conf t
!
route-map LocPrf permit 10
set local-preference 222
!
router bgp 234
neighbor 100.100.12.1 route-map LocPrf in
!
end
cle ip b * so
R4新增的配置如下:
conf t
!
ip prefix-list R5L3 seq 5 permit 10.1.2.0/23
!
route-map LOCPRF permit 10
match ip address prefix-list R5L3
set local-preference 333
!
route-map LOCPRF permit 20
!
router bgp 234
neighbor 100.200.45.5 route-map LOCPRF in
!
end
cle ip b * so
更新策略后,在R3上验证本地优先级和BGP路由优选路径如下:
R3测试数据转发路径如下:
由此可见,BGP路径属性——本地优先级,主要应用在多宿主网络环境中控制本地出站流量。
如果一条BGP路由携带P周知团体属性值0xFFFFFF03,该路由只能传递给联邦内部子AS的对等体;如果一条BGP路由携带P周知团体属性值0xFFFFFF02,该路由不会通告给任何对等体。