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
| eBGP | iBGP | |
|---|---|---|
| Neighbors | In another AS | In the same AS |
| Default TTL on Cisco | 1 (connected neighbor) | 255 |
| AS_PATH | Own AS is prepended | Unchanged |
| NEXT_HOP | Changes to its own IP | Unchanged (unless next-hop-self) |
| Administrative distance | 20 | 200 |
| Route forwarding | To every neighbor | Not 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.
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.
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.
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.
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).
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.
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
| State | What is happening |
|---|---|
| Idle | Not trying to connect (for example, after an error) |
| Connect | Waiting for the TCP connection to open |
| Active | The TCP connection failed; it tries again. Getting stuck here usually means a reachability or configuration problem |
| OpenSent | TCP established and OPEN sent; waiting for the neighbor's |
| OpenConfirm | OPEN received and accepted; waiting for a KEEPALIVE |
| Established | Session up: UPDATEs are exchanged |
| Message | Type | Purpose |
|---|---|---|
| OPEN | 1 | Introduce itself: version, AS, hold time, router ID and capabilities |
| UPDATE | 2 | Advertise and withdraw routes |
| NOTIFICATION | 3 | Report an error and close the session |
| KEEPALIVE | 4 | Confirm the OPEN and keep the session up |
| ROUTE-REFRESH | 5 | Ask the neighbor to resend its routes |
How Cisco picks the best path
- Highest weight (local only, Cisco-specific)
- Highest LOCAL_PREF (for the whole AS)
- Locally originated route
- Shortest AS_PATH
- Lowest ORIGIN: IGP, then EGP, then incomplete
- Lowest MED (among routes from the same neighboring AS)
- eBGP over iBGP
- Lowest IGP metric to the NEXT_HOP
- The oldest eBGP route
- 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
| Command | What it does or shows |
|---|---|
router bgp 65010 · neighbor 203.0.113.2 remote-as 64500 | Enables BGP in the AS and configures the neighbor (eBGP, because the AS is different). |
network 192.0.2.0 mask 255.255.255.0 | Advertises the prefix, if it exists exactly in the routing table. |
neighbor … default-originate | Sends the default route to that neighbor (on the provider). |
show ip bgp summary | The neighbors, their AS, messages, uptime and state or prefixes received. |
show ip bgp | The BGP table: best route (>), next hop, metric, LOCAL_PREF, weight and AS_PATH. |
show ip bgp neighbors … advertised-routes | What is advertised to a neighbor. |
show ip route bgp | The 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
- RFC 4271 · A Border Gateway Protocol 4 (BGP-4)
- RFC 5492 · Capabilities Advertisement with BGP-4
- RFC 6793 · BGP Support for Four-Octet Autonomous System (AS) Number Space
- RFC 6996 · Autonomous System (AS) Reservation for Private Use
- Cisco · IP Routing: BGP Configuration Guide
- Cisco · BGP Command Reference (neighbor default-originate, show ip bgp summary)
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.