LABS · PROTOCOLS · ONE STEP FURTHER

BGP: how a company and its provider exchange routes

The protocol that ties the Internet's autonomous systems together, message by message: the TCP session with TTL 1, the OPENs with their capabilities, the KEEPALIVEs and the UPDATEs with their attributes, between Canadá Logística and its provider.

Level: advanced · 20 minutes

Interactive simulation

The animation needs JavaScript. The full lesson is written out below.

Download the capture and open it in Wireshark to keep exploring.

What BGP is

BGP (Border Gateway Protocol, RFC 4271) exchanges routes between autonomous systems: networks with their own administration and their own AS number, such as a company, a provider or a cloud. It is the protocol that holds the Internet together.

It is a path-vector protocol: each route travels with the list of ASes it went through (AS_PATH) and other attributes, and each router chooses according to a policy, not just a cost. It does not discover neighbors: each session is configured by hand and runs over TCP 179, so BGP needs neither its own acknowledgments nor periodic refreshes.

eBGP and iBGP

eBGPiBGP
NeighborsIn another ASIn the same AS
Default TTL on Cisco1 (connected neighbor)255
AS_PATHOwn AS is prependedUnchanged
NEXT_HOPChanges to its own IPUnchanged (unless next-hop-self)
Administrative distance20200
Route forwardingTo every neighborNot to other iBGP peers: full mesh or route reflectors

How it works: from the TCP connection to the routes

Six steps: the TCP connection, the OPENs, the KEEPALIVEs that lead to Established, the default route, R1's block advertisement and the periodic keepalives.

  1. TCP to port 179, with TTL 1

    BGP sends no Hellos: each neighbor is configured by hand with neighbor remote-as. R1 opens a TCP connection to PE1's port 179 from a high port, with the usual three-way handshake. In eBGP, Cisco sends everything with TTL 1, because the neighbor must be directly connected (ebgp-multihop exists for other cases), and marks it with precedence 6 (CS6), like control traffic.

  2. OPEN: each side introduces itself

    Each side sends an OPEN with BGP version 4, its AS number, the hold time it proposes (180 s), its router ID and its capabilities: IPv4 unicast (MP-BGP), route refresh and 4-byte AS. Each one checks that the peer's AS is the one configured in remote-as; if it did not match, it would reply with a NOTIFICATION and close the session. The lower hold time of the two is used.

  3. KEEPALIVE: session Established

    Each side accepts the other's OPEN by replying with a KEEPALIVE: a message with no body, just the 19-byte header. When it arrives, the session moves to Established and R1 logs %BGP-5-ADJCHANGE: neighbor 203.0.113.2 Up. From here on they can exchange routes.

  4. UPDATE: the default route

    PE1 has neighbor default-originate toward R1, so it sends an UPDATE with 0.0.0.0/0 and its mandatory attributes: ORIGIN IGP, AS_PATH 64500 (the provider prepended its AS) and NEXT_HOP 203.0.113.2. R1 installs it as B* with administrative distance 20, eBGP's. With a single provider it does not need the full Internet table (close to a million IPv4 prefixes).

  5. UPDATE: R1 advertises its block

    R1 advertises 192.0.2.0/24 with network: the command only works if the exact prefix is in the routing table, which is why there is a static route to Null0. The UPDATE carries ORIGIN IGP, AS_PATH 65010, NEXT_HOP 203.0.113.1 and MED 0. The provider will propagate it to the Internet; in practice it would replace the private AS with its own, because private ASes are not advertised to the Internet.

  6. KEEPALIVE every 60 s

    If there are no new routes, BGP sends nothing but a KEEPALIVE every 60 s (a third of the 180 s hold time). If no message arrives from the neighbor within 180 s, the session closes, the learned routes are removed and R1 would lose its default route. Unlike OSPF or IS-IS, BGP does not refresh its routes periodically: the TCP connection guarantees they are not lost.

Session states

StateWhat is happening
IdleNot trying to connect (for example, after an error)
ConnectWaiting for the TCP connection to open
ActiveThe TCP connection failed; it tries again. Getting stuck here usually means a reachability or configuration problem
OpenSentTCP established and OPEN sent; waiting for the neighbor's
OpenConfirmOPEN received and accepted; waiting for a KEEPALIVE
EstablishedSession up: UPDATEs are exchanged
MessageTypePurpose
OPEN1Introduce itself: version, AS, hold time, router ID and capabilities
UPDATE2Advertise and withdraw routes
NOTIFICATION3Report an error and close the session
KEEPALIVE4Confirm the OPEN and keep the session up
ROUTE-REFRESH5Ask the neighbor to resend its routes

How Cisco picks the best path

  1. Highest weight (local only, Cisco-specific)
  2. Highest LOCAL_PREF (for the whole AS)
  3. Locally originated route
  4. Shortest AS_PATH
  5. Lowest ORIGIN: IGP, then EGP, then incomplete
  6. Lowest MED (among routes from the same neighboring AS)
  7. eBGP over iBGP
  8. Lowest IGP metric to the NEXT_HOP
  9. The oldest eBGP route
  10. Lowest neighbor router ID

With a single provider and one route per prefix, as in this lab, there is nothing to choose. These criteria matter when a company has two providers (multihoming) and wants to decide where traffic comes in and goes out.

The Cisco IOS XE commands

CommandWhat it does or shows
router bgp 65010 · neighbor 203.0.113.2 remote-as 64500Enables BGP in the AS and configures the neighbor (eBGP, because the AS is different).
network 192.0.2.0 mask 255.255.255.0Advertises the prefix, if it exists exactly in the routing table.
neighbor … default-originateSends the default route to that neighbor (on the provider).
show ip bgp summaryThe neighbors, their AS, messages, uptime and state or prefixes received.
show ip bgpThe BGP table: best route (>), next hop, metric, LOCAL_PREF, weight and AS_PATH.
show ip bgp neighbors … advertised-routesWhat is advertised to a neighbor.
show ip route bgpThe installed BGP routes: B, with distance 20 or 200.

BGP is not in the CCNA v2.0 blueprint: it is one step further toward CCNP Enterprise, whose ENCOR exam asks you to configure and verify eBGP between directly connected neighbors.

Frequently asked questions

Why does BGP use TCP?

Because TCP already guarantees delivery and order. That way BGP needs no acknowledgments of its own and doesn't resend its routes periodically: it only sends changes.

What happens if the ASes don't match?

When it receives an OPEN with an AS different from remote-as, the router replies with a NOTIFICATION (Bad Peer AS) and closes the session.

Why is the TTL 1?

Because in eBGP Cisco expects the neighbor to be directly connected. If it isn't (for example, between Loopbacks), ebgp-multihop is needed.

Why the route to Null0?

Because network only advertises a prefix that exists exactly in the routing table. The route to Null0 keeps it always present, even if internal subnets change.

Which AS can a company use?

With a single provider, a private one (64512-65534 or the private 4-byte ones). With two or more providers it needs a public AS, assigned by its regional registry (ARIN in Canada).

What you take away

  • BGP exchanges routes between autonomous systems over TCP 179.
  • Neighbors are configured by hand; in eBGP, Cisco uses TTL 1.
  • OPEN introduces each side; KEEPALIVE confirms it and keeps the session up.
  • Each UPDATE carries attributes: ORIGIN, AS_PATH and NEXT_HOP are mandatory.
  • AS_PATH prevents loops: a router drops routes containing its own AS.
  • eBGP has distance 20 and iBGP, 200.

NEXT STEP

From this lesson one step further

BGP is the gateway to CCNP Enterprise and to provider networks: you will see it in depth in The House of Routing's BGP master class, with iBGP, attributes and policies. We'll let you know when there is news.

Upcoming protocol lessons

Sources

Lesson prepared with AI assistance and checked against the sources cited. The bytes of every packet are generated according to the standard and verified with an independent tool.