An Introduction to BGP
BGP is a Path-Vector Routing Protocol. Similar to RIP, BGP uses hop-count as it's primary metric for finding the best route, but BGP uses hops between Autonomous Systems as opposed to hops between routers. Running over TCP Port 179, BGP is able to use TCP windowing to reliably exchange large databases of routes over the Internet. These databases contain routes for every network connected to the Internet, which at the time of writing stands at an incredulous 700,000 prefix entries! In Networking terms, this is the BGP Table, but many refer to it simply as the Internet Routing Table.
Any router running BGP will receive a copy of this Table, but BGP Attributes allow for the filtering of routes, as well as the parameter modification of all prefixed received and advertised. When processing a mulitple routes to the same network, BGP will run the Best Path Selection Algorithm to select a route from it's BGP Table. The algorithm determines the best path by comparing each valid route based on BGP Attributes. The Attributes listed from highest to lowest Priority are as follows:
-
Weight
Action: Prefer the path with the highest locally-configured WEIGHT
Description: WEIGHT is a Cisco-propreitary per-neighbor attribute that can be configured to priorise routes learned from specific neighbors. -
Local Preference
Action: Prefer the path with the highest locally-configured LOCAL_PREF.
Description: LOCAL_PREF is an attribute built into the BGP Standard and operates similarly to WEIGHT, however the Local Preference is configured locally on the actual router you would like to be preffered, not on a per-neighbor basis. -
Locally Originated
Action: Prefer the path that was locally originated via a network or aggregate BGP subcommand or through redistribution from an IGP.
Description: Any path that has been originated on a local router will be preferred over any paths learned from a BGP Peer. If no locally originated prefix exists in the BGP table for the paths being compared then this attribute is ignored. -
AS Path
Action: Prefer the path with the shortest AS_PATH.
Description: The original and the most fundamental attribute of BGP, the AS_PATH attribute stores a list of the BGP Automomous System numbers through which the route was learned. If AS1 advertises a route to AS2, the AS_PATH observed in AS2 would be "1". If AS2 then passes this UPDATE to AS3, AS3 would observe an AS_PATH of "1 2". As BGP routers will by default ignore any prefix updates with an AS_PATH attribute containing their own AS number, this attribute prevents routing loops occurring on the Internet for routes learned from multiple sources. -
MED
Action: Prefer the path with the lowest Multi-Exit Discriminator (MED)
Description: The MED, commonly reffered to as BGP Metric, is an optional, non-transitive attribute. This means that it is not enabled by default, and if it is enabled then the attribute will only be passed to immediate neighbors. If an AS has multiple connections to a neighboring AS, the MED allows BGP to directly which path we would like neighboring AS to route traffic to us over. -
Network Type
Action: Prefer routes learned through eBGP (External BGP) over iBGP (Internal BGP) routes.
Description: This attribute sets the BGP instance to make routing decisions solely based on the Internet Routing Table. It will only fall back to iBGP should a route entry not exist in the BGP Table. -
Router ID (RID)
Action: Prefer the route that comes from the BGP router with the lowest Router-ID.
Description: Every BGP Speaker is configured with a unique Router-ID. In private networks running iBGP, this will likely be a logical loopback IP address for enhanced resiliency. In eBGP, the Router-ID will be the external-facing Public IP Address of that router. -
Neighbor IP
Action: Prefer the path that comes from the lowest neighbor IP Address.
Description: If the Router-ID is the same for multiple routes in the BGP Table, this is indicitave that the routes were learned from the same neighbor. In this case, BGP will choose the lowest originating IP Address as a tie-breaker.
BGP Configuration
Here I am going to give a quick overview of some BGP configuration examples. I will be using the well-known Cisco IOS syntax, though the protocol-specific concepts remain true for any vendor.
Now, to enable a base BGP configuration, first we need to configure our external interface to Router 2...
Router 1(config)#interface GigabitEthernet 0/0
Router 1(config-if)#description Link to Router 2
Router 1(config-if)#ip address 200.0.0.0 255.255.255.254
Router 1(config-if)#no shutdown
Next we will then configure an ACL to only receive BGP advertisements for the remote private network...
Router 1(config)#access-list 1 permit 192.168.100.0 0.0.0.255
Router 1(config)#access-list 1 deny any
Finally we will configure eBGP neighborship to Router 2, and filter all prefixes except the remote private network.
Router 1(config)#router bgp 65000
Router 1(config-router)#no auto-summary
Router 1(config-router)#neighbor 200.0.0.1 remote-as 65001
Router 1(config-router)#neighbor 200.0.0.1 distribute-list 1 in
Router 1(config-router)#network 192.168.0.0 mask 255.255.255.0
And now we are good to go. Applying a similar configuraton on Router 2 will bring up our BGP session establishment:
Router 2(config)#interface GigabitEthernet 0/0
Router 2(config-if)#description Link to Router 1
Router 2(config-if)#ip address 200.0.0.1 255.255.255.254
Router 2(config-if)#no shutdown
Router 2(config)#access-list 1 permit 192.168.0.0 0.0.0.255
Router 2(config)#access-list 1 deny any
Router 2(config)#router bgp 65001
Router 2(config-router)#no auto-summary
Router 2(config-router)#neighbor 200.0.0.0 remote-as 65000
Router 2(config-router)#neighbor 200.0.0.0 distribute-list 1 in
Router 2(config-router)#network 192.168.100.0 mask 255.255.255.0