Skip to main content

BGP & Inter-AS Routing

Inside an autonomous system, OSPF finds the shortest paths on a map the operator fully controls. Between autonomous systems there is no shared map and no shared authority - just thousands of independent networks that must agree on how to reach each other. This is the job of BGP, the protocol that glues the internet together.

Routing between autonomous systems

Each AS wants to reach prefixes it does not own, and to advertise the prefixes it does. But no operator will hand its internal topology to a competitor, and reachability is entangled with business relationships - who pays whom to carry traffic. So inter-AS routing exchanges reachability and paths, not detailed link states, and lets each AS apply its own policy on top.

BGP as a path-vector protocol

BGP (Border Gateway Protocol) is a path-vector protocol - a distance-vector descendant where each advertisement carries not just a destination but the entire list of ASes the route passes through (the AS-PATH).

A route advertisement for a prefix therefore says, in effect: "I can reach 203.0.113.0/24, and the path to it traverses these autonomous systems." Carrying the full AS-PATH gives BGP two things distance-vector routing lacks:

  • Loop detection - if a router sees its own ASN already in the AS-PATH, it rejects the route, so routes cannot loop.
  • Policy input - the AS-PATH (and its length) is one of the attributes an AS weighs when choosing among competing routes.

eBGP and iBGP

BGP runs in two modes depending on whether the two speakers are in the same AS:

eBGPiBGP
PeersRouters in different ASesRouters within the same AS
PurposeLearn routes from neighbouring ASesDistribute externally-learned routes inside the AS
Runs acrossAS boundariesThe AS interior

A border router learns external prefixes via eBGP from its neighbours, then uses iBGP to share those routes with the other routers in its own AS, so the whole AS knows how to reach the outside world.

Policy and business relationships

The defining feature of BGP is that path selection is driven by policy, which reflects money and contracts, not raw distance. Autonomous systems relate to each other roughly as:

  • Provider - customer - the customer pays the provider for transit (access to the rest of the internet).
  • Peer - peer - two ASes exchange traffic between their own customers for free, bypassing a paid provider.

A classic rule that follows directly from these relationships: an AS advertises a route learned from one provider to its customers, but generally does not re-advertise it to another provider or peer - doing so would mean paying to carry traffic that earns it nothing.

Worked example: why the shorter AS-PATH doesn't always win

Suppose AS 65001 hears two candidate routes to reach 198.51.100.0/24:

Route ARoute B
AS-PATH65002 65005 (length 2)65003 65006 65007 65008 (length 4)
Local Preference100200
Learned viaeBGP peereBGP peer

Route A has the shorter AS-PATH, but BGP's decision process checks attributes in a fixed order, and Local Preference is checked before AS-PATH length. Local Preference is set locally by the AS's own policy (for example, "prefer routes through our paid transit provider" or "prefer this peering link because it's cheaper"), so AS 65001 picks Route B, the four-hop path, purely because its operator's policy assigned it a higher Local Preference. AS-PATH length only comes into play as a tiebreaker among routes that are otherwise equal on the higher-priority attributes - it never overrides policy.

A route leak can hijack traffic for an entire prefix

In February 2008, Pakistan Telecom tried to block YouTube for domestic users by advertising a more specific route for YouTube's address block internally. That route leaked out to Pakistan Telecom's upstream provider and from there to the rest of the internet. Because BGP (like all IP routing) uses longest-prefix match, every router that heard the leaked /24 preferred it over YouTube's own broader announcement, regardless of AS-PATH length or policy - a more specific prefix always wins the forwarding decision. Global traffic to YouTube was pulled toward Pakistan Telecom's network for about two hours, taking YouTube offline worldwide, because there was no automatic check that Pakistan Telecom was actually authorized to originate that prefix. This class of incident (an AS accidentally or maliciously advertises routes it has no business advertising) recurs regularly and is why route origin validation (RPKI) exists today: to let routers cryptographically verify that an AS is authorized to originate a given prefix before believing it.

caution

Unlike OSPF, BGP does not simply pick the shortest path. It picks the path that its policy prefers - which may be longer in AS hops - because economic relationships, not link counts, decide which routes an AS is willing to use and advertise. The internet's routes are shaped as much by contracts as by topology.