How Does BGP Exchange Autonomous System Routing Tables?
The Border Gateway Protocol is the core routing protocol that connects independent networks, known as autonomous systems, across the global internet. By establishing reliable transport sessions between border routers, BGP exchanges reachability information and policy-driven path attributes rather than raw link metrics. This mechanism allows thousands of autonomous systems to maintain a coherent view of global internet routes without relying on a central authority.
Autonomous Systems and BGP Sessions
The global internet is divided into tens of thousands of autonomous systems, each operated by an internet service provider, enterprise, or cloud network under a single administrative domain. Every autonomous system is identified by a unique Autonomous System Number (ASN) and owns specific blocks of IP address prefixes.
To exchange routing information, routers at the edges of these networks form BGP peering sessions. Unlike interior gateway protocols such as OSPF or IS-IS that discover neighbors automatically on local links, BGP peers must be explicitly configured. BGP runs over TCP on port 179, which provides reliable, ordered delivery of routing updates without requiring BGP itself to implement packet retransmission or fragmentation.
There are two primary types of BGP sessions:
- External BGP (eBGP): Runs between routers in different autonomous systems to exchange external reachability information.
- Internal BGP (iBGP): Runs between routers within the same autonomous system to distribute externally learned routes across the internal network.
Establishing a Peering Relationship
Before any routing tables are exchanged, two BGP speakers must
complete a finite state machine handshake over their TCP connection.
Once the TCP three-way handshake succeeds, each router sends an
OPEN message containing its BGP version, ASN, hold time,
and BGP identifier.
If both routers accept the parameters, they respond with
KEEPALIVE messages to confirm the session is active. From
that point forward, routers periodically exchange KEEPALIVE
messages to verify that the peer remains reachable. If a router fails to
receive a KEEPALIVE or UPDATE message before
the hold timer expires, it tears down the session and withdraws all
routes learned from that peer.
Exchanging Routing Tables with UPDATE Messages
When a BGP session first reaches the established state, the peers
exchange their entire relevant routing tables. After this initial
synchronization, BGP operates incrementally: routers only send
UPDATE messages when routes are added, modified, or
withdrawn.
Each UPDATE message can contain:
- Withdrawn Routes: A list of IP prefixes that are no longer reachable through the advertising router.
- Network Layer Reachability Information (NLRI): Newly advertised or updated IP prefixes.
- Path Attributes: Metadata describing the route,
such as the
AS_PATH,NEXT_HOP, andLOCAL_PREF.
The AS_PATH attribute is fundamental to BGP's operation.
As a route advertisement travels from one autonomous system to another,
each transit AS prepends its own ASN to the AS_PATH. This
creates an ordered list of autonomous systems that the traffic must
traverse to reach the destination prefix.
Loop Prevention and Path Selection
Because BGP operates across an arbitrary mesh of interconnected
networks, preventing routing loops is critical. When a router receives
an UPDATE message, it inspects the AS_PATH
attribute. If the router sees its own ASN already listed in the
AS_PATH, it immediately discards the route, ensuring that
routing loops cannot form between autonomous systems.
When a router learns multiple valid paths to the same destination prefix, it runs the BGP best-path selection algorithm. Rather than picking the shortest physical path, BGP evaluates attributes in a strict order of preference, typically prioritizing:
- Highest
LOCAL_PREF(an internal policy metric set by the network operator). - Shortest
AS_PATH(fewest autonomous systems traversed). - Lowest
ORIGINtype and Multi-Exit Discriminator (MED). - Preference for eBGP-learned routes over iBGP-learned routes.
- Lowest IGP metric to the
NEXT_HOPaddress.
Once the best path is selected, it is installed into the router's Routing Information Base (RIB) and Forwarding Information Base (FIB), and then advertised to other eligible BGP peers according to the network's routing policies.