Border Gateway Protocol (BGP) is the routing protocol that runs the internet. It is used to exchange routing information between different autonomous systems (AS).

Key concepts

  • AS (Autonomous System) — a network or group of networks under a single administrative domain, identified by an AS number (ASN)
  • eBGP — BGP between different autonomous systems (external)
  • iBGP — BGP within the same autonomous system (internal)
  • BGP peer/neighbour — a router you have a BGP session established with
  • Prefix — a network route being advertised (e.g. 10.0.0.0/24)

How BGP works

  1. Two routers form a TCP session on port 179
  2. They exchange their full routing tables (once)
  3. After that, only changes (updates) are sent
  4. BGP selects the best path using attributes

BGP path selection (simplified)

BGP prefers routes in this order:

  1. Highest Local Preference (iBGP)
  2. Shortest AS Path
  3. Lowest Origin type
  4. Lowest MED (Multi-Exit Discriminator)
  5. eBGP over iBGP
  6. Lowest IGP metric to next hop
  7. Oldest route / lowest router ID

Common BGP states

StateMeaning
IdleNot attempting connection
ConnectTCP connection in progress
ActiveTrying to establish TCP
OpenSentOPEN message sent
OpenConfirmWaiting for KEEPALIVE
EstablishedSession up, exchanging routes