BGP Local Preference and AS Path Prepending

Nov 05, 2021

BGP or Border Gateway Protocol is the routing protocol of the Internet, designed for massive global scale networking topologies exchanging 100,000’s of routes between ISP’s. This also means that BGP has many knobs and buttons for tuning routing decisions and can be complex compared to other routing protocols such as OSPF or EIRGP, but don’t let this put you off from using BGP. There are 2 features that are useful and simple for controlling BGP which are Local Preferences and AS Path Prepending, but first we need to understand ASN’s (Autonomous System Number). A ASN is similar to OSPF Areas in that it’s a logical representation of a bunch of routers, eg a global company have routers in New Zealand and all may have the private ASN number 64600 while their Australian routers are all 64700. All BGP connections (also called peering's) within a ASN are iBGP and all connections external to a ASN are eBGP and behave differently but is beyond is article.

Now let’s imagine this global company has 2 links between Australia and New Zealand, one is 100Mbit/s and the other is 40Mbit/s, BGP easily allows you to control the routing so that the 100Mbit link is always used. Frist is Local Preference which controls egress traffic from a ASN, a higher Local Preference is always used. Then AS Path Prepending controls ingress traffic and a shorter ASN path is always used.

Below shows both features work.

So, all routers in a ASN have iBGP connections and the links between AU and NZ are eBGP, next NZ RTR01 is applying any routes from AS64700(AU) with Local Preference to 300 and NZ RTR02 is setting any routes from AS64700(AU) to 200, both routers will advertise their local preference to all other routers in the NZ ASN64600, so all traffic will egress NZRTR01 with the 100Mbit link because of value 300 over 200. Note that the Local Preference is “Non-Transitive Attribute” so will not be advertised across eBGP connection.

Next for ingress traffic, we want AU to always sending traffic across the 100Mbit link, on NZ RTR01 we have the eBGP to AU RTR01 and on NZ RTR02 we have a eBGP to AU RTR02 which we prepend the NZ AS64600 twice. So AU RTR01 will have the AS PATH to NZ ASN of just 64600 and the AU RTR02 will have the AS PATH to NZ ASN of 64600 64600, like iBGP this is advertised to all iBGP routers and AU RTR01 is used, remember that lowest AS PATH is used. Unlike Local Preference, AS PATH is "Transitive Attribute" so will be sent to eBGP neighbors.