BGP - attributes and path selection

In a typical BGP topology, BGP routers will often receive information about multiple paths to the same destination. Similar to IGPs such as RIP, EIGRP, and OSPF, we need to select the best path to each destination.

IGPs select the path with the lowest metric. BGP however, selects the best path based on a list of attributes. On the Internet, it’s more important that you have granular control over how you forward your traffic and to which autonomous systems you send traffic, rather than just going for the shortest path based on a metric.

When a BGP router receives information about multiple paths to a particular destination, it will go through the following attributes, in this order, to determine which is the best path. If there is a tie on a particular attribute, it examines the next attribute down the line. Here is the list of attributes used by BGP:

  1. Weight: This is a Cisco-specific attribute. It's locally significant and not advertised to neighboring routers. Higher weight values have preference over lower ones.
  2. Local Preference: This is the second attribute checked, and it's more significant than most others as it influences outbound routing decisions. Like Weight, it is not advertised to neighboring routers.
  3. Locally Originated: The BGP router prefers the routes that it has locally originated via a network or aggregate BGP subcommand, or through redistribution from an IGP.
  4. AS Path: This is one of the most important attributes. BGP prefers the path with the shortest AS Path.
  5. Origin: The origin attribute defines how BGP learned about a particular route. The values can be IGP, EGP, or Incomplete. BGP prefers IGP over EGP and EGP over Incomplete.
  6. MED (Multi-Exit Discriminator): The MED is a hint to the external neighbors about the preferred path into an AS when there are multiple entry points into the AS. A lower MED is preferred over a higher one.
  7. eBGP over iBGP Paths: If it comes to this step, BGP will prefer eBGP paths over iBGP paths.
  8. Shortest IGP Path to the BGP Next Hop: BGP prefers the path that the local router has the shortest IGP path to.
  9. Oldest Path: If all other attributes are the same, BGP prefers the oldest path.
  10. Router ID: If all else is equal, the BGP router with the lowest router ID is preferred.
  11. Neighbor Type: If the Router ID is the same, then BGP prefers the path through the neighbor with the lowest IP address.

Note that BGP attributes can be manipulated to influence path selection in a way that fulfills specific network requirements.