Border Gateway Protocol (BGP)
Lesson Overview
Border Gateway Protocol (BGP) is the routing protocol used to exchange reachability information between autonomous systems. Unlike an IGP such as OSPF or EIGRP, BGP is designed around policy, path attributes, Internet-scale routing, and controlled advertisement rather than shortest-path calculation alone.
This lesson builds a CCNP-level foundation without jumping immediately into advanced policy design. You will learn how BGP sessions form, how eBGP and iBGP differ, how prefixes move from one AS to another, how the BGP table relates to the routing table, and how a router chooses a best path.
Objectives
- Explain BGP as a path-vector, policy-based inter-domain routing protocol.
- Describe autonomous systems, including public/private AS numbers and 4-byte AS numbers.
- Distinguish eBGP from iBGP neighbor relationships and default behavior.
- Build directly connected BGP peers and understand when multi-hop or update-source is required.
- Interpret BGP UPDATE advertisements, path attributes, and withdrawals.
- Read the BGP table and relate it to the IP routing table and forwarding table.
- Explain high-level best-path selection concepts and common path attributes.
- Configure and verify a two-AS, four-router BGP lab end to end.
- Troubleshoot session-establishment, next-hop, advertisement, and route-installation problems.
1. Introduction to Border Gateway Protocol
Border Gateway Protocol (BGP) is a path-vector routing protocol used to exchange routing information between autonomous systems and to control how traffic enters, leaves, and traverses large IP networks.
Unlike interior routing protocols such as OSPF, which primarily select routes according to an internal metric, BGP makes routing decisions using a collection of path attributes and routing policies. This makes BGP especially suitable for Internet routing, enterprise multihoming, service-provider networks, data centers, cloud connectivity, MPLS environments, and large-scale WAN architectures.
BGP is the routing protocol that makes large-scale inter-domain routing possible. It is widely used by:
- Internet Service Providers
- Large enterprises
- Cloud providers
- Data centers
- MPLS service-provider networks
- Enterprises connected to multiple ISPs
- Internet Exchange Points
- Global WAN environments
Unlike OSPF, which primarily determines the shortest internal path based on cost, BGP makes routing decisions using a combination of path attributes and administrative routing policy.
Key characteristics
- Path-vector protocol: every route carries the list of ASNs it has passed through (the AS-Path).
- Loop prevention: if a router sees its own ASN in a received AS-Path, it rejects the route.
- Runs over TCP port 179: TCP gives reliable delivery, so BGP needs no retransmission logic of its own.
- Manual neighbors: peers are configured by hand, with no automatic discovery. Neighbors need not be directly connected, only reachable by IP.
- Incremental updates: the full table is sent once at session start, then only changes are sent.
- Policy-driven: the best path is chosen by attributes and administrator policy, not just the lowest metric.
- Built to scale: the global table holds 1M+ prefixes, and BGP is designed for that.
1.1 BGP Is Policy Driven
IGPs usually answer “What is the shortest internal path?” BGP answers a different question: “Which reachable path should I prefer according to my routing policy?” Attributes such as Weight, Local Preference, AS_PATH, Origin, MED, and NEXT_HOP influence that decision.
|
CCNP point: A path with more physical bandwidth is not automatically preferred by BGP. The decision process evaluates BGP attributes and policy first. |
2. Why BGP Is Required
Border Gateway Protocol (BGP) is required when routing decisions must be made between different autonomous systems (ASes). While protocols such as OSPF, IS-IS, and EIGRP are designed primarily for routing inside an organization, BGP is designed to exchange routing information between large networks such as enterprises, Internet service providers, cloud providers, and content networks.
BGP is the routing protocol that makes large-scale Internet routing possible.
Why Interior Routing Protocols Are Not Enough
An Interior Gateway Protocol such as OSPF determines the best route mainly by using an internal metric.
However, Internet routing requires more than selecting the lowest-cost path. Organizations often need to choose routes based on:
- Business relationships
- ISP preference
- Routing policy
- Traffic engineering
- Path length
- Backup connectivity
- Security requirements
- Administrative decisions
BGP provides these capabilities.
2.1 Autonomous System
An Autonomous System (AS) is a collection of IP networks and routers that operate under a single administrative authority and follow a common routing policy.
Autonomous Systems are fundamental to BGP (Border Gateway Protocol) because BGP uses an Autonomous System Number (ASN) to identify each routing domain on the Internet or within large enterprise/service-provider networks.
Examples include:
Internet Service Providers (ISPs)
Large enterprises
Cloud providers
Content providers
Universities and government networks
Each autonomous system that participates in Internet BGP routing is normally identified by an Autonomous System Number (ASN).
How Do We Obtain an AS Number?
Public AS numbers are managed globally by IANA and allocated through the five Regional Internet Registries (RIRs).
The RIR responsible for your region assigns AS numbers to organizations according to its allocation policies.
The five RIRs are:
ARIN - North America
RIPE NCC - Europe, Middle East, and parts of Central Asia
APNIC - Asia-Pacific
LACNIC - Latin America and the Caribbean
AFRINIC - Africa
Therefore, organizations that require a public ASN typically request one through their appropriate RIR.
16-bit and 32-bit AS Numbers
Originally, BGP used 16-bit AS numbers.
A 16-bit field provides AS numbers in the range: 0-65535
As Internet growth increased the demand for AS numbers, BGP was extended to support 32-bit, or 4-byte, AS numbers.
The complete 32-bit ASN space extends up to: 4294967295. This provides billions of possible AS numbers.
Important AS Number Ranges
16-bit ASN Space
|
0 – Reserved
1 – 64495 Primarily globally assignable AS numbers (with some special-purpose exceptions)
64496 – 64511 Documentation and sample configurations
64512 – 65534 Private AS numbers
65535 Reserved |
For example, AS 23456 is a special-purpose value known as AS_TRANS, used for compatibility when four-byte ASNs interact with systems that support only older two-byte ASNs.
32-bit ASN Space
Additional private AS numbers are available in the range: 4200000000 – 4294967294
These ASNs are reserved for private use and should not be advertised across the public Internet.
IANA currently lists both private-use ranges as:
64512 – 65534
4200000000 – 4294967294
Public vs Private AS Numbers
The concept is similar to public and private IP addressing.
Public ASN
A public ASN is globally unique and is normally used when an organization exchanges routes with other autonomous systems on the Internet. Public ASNs must be properly allocated to the organization using them.
Private ASN
Private AS numbers are typically used inside private networks, laboratories, MPLS environments, or situations where the ASN does not need to appear in the global Internet routing table.
3. BGP Types - eBGP and iBGP in Detail
External BGP (eBGP) peers belong to different autonomous systems. Internal BGP (iBGP) peers belong to the same autonomous system. This distinction changes default TTL, administrative distance, AS_PATH handling, next-hop behavior, and internal propagation rules.
BGP relationships are primarily classified into two types:
Figure 3 - eBGP connects different autonomous systems; iBGP distributes BGP information inside an autonomous system.
|
Feature |
eBGP |
iBGP |
|
Peer ASN |
Different ASN |
Same ASN |
|
Cisco default AD |
20 |
200 |
|
Default TTL |
1 |
255 |
|
AS_PATH |
Local AS is added when advertising to another AS |
Local AS is not added merely for internal iBGP advertisement |
|
NEXT_HOP |
Normally changes to the advertising eBGP speaker |
Normally remains unchanged unless changed, e.g. `next-hop-self` |
|
Scaling rule |
No iBGP full-mesh rule |
Routes learned from one iBGP peer are not advertised to another iBGP peer by default; use full mesh, route reflection, or confederations |
|
Typical use |
Enterprise-to-ISP, ISP-to-ISP, inter-AS peering |
Distribute external routes within one AS |
|
Administrative distance: AD does not select the best path inside the BGP table. It matters when the router is deciding whether a BGP route should be installed in the IP routing table against the same prefix learned from another routing source. |
3.1 The iBGP Full-Mesh Rule
Because iBGP does not add the local AS to AS_PATH, the AS_PATH cannot by itself prevent an internal BGP loop. Therefore, a route learned from one iBGP peer is not advertised to another iBGP peer by default. A small iBGP deployment can use a full mesh; larger networks commonly use route reflectors or confederations.
|
Fundamental rule: Do not confuse “same AS” with “automatically neighbors.” BGP neighbors are explicitly configured. iBGP peers still require IP reachability and matching neighbor configuration. |
3.2 NEXT_HOP and next-hop-self
When R2 learns 172.16.20.0/24 from R3 using eBGP, the NEXT_HOP is 203.0.113.2. If R2 advertises that route to R1 using iBGP, R1 can receive the route while the NEXT_HOP remains 203.0.113.2. If R1 cannot reach that address, the path is unusable. The common solution at an edge router is next-hop-self toward the internal BGP peer.
R2 - set itself as the NEXT_HOP for routes sent to R1
|
router bgp 65001 neighbor 10.12.12.1 remote-as 65001 neighbor 10.12.12.1 next-hop-self |
4. BGP Message Types
BGP peers exchange several types of control messages after the underlying TCP connection is established. BGP uses: TCP Port 179. Each message performs a specific role in establishing, maintaining, updating, or terminating a BGP session.
|
Message |
Purpose |
|
OPEN |
Starts the BGP session and exchanges version, AS number, hold time, BGP identifier, and capabilities. |
|
UPDATE |
Advertises reachable prefixes (NLRI), carries path attributes, and withdraws unreachable prefixes. |
|
KEEPALIVE |
Maintains an established BGP session when no UPDATE is being sent. |
|
NOTIFICATION |
Reports a BGP error and normally closes the session. |
|
ROUTE-REFRESH |
Requests routes again after inbound policy changes when the capability is supported. |
4.1 BGP Message Exchange Overview
A simplified BGP session establishment and route exchange looks like:
If a serious protocol error occurs:
If routing policy changes and routes need to be reprocessed:
4.2 OPEN Message
The OPEN message is exchanged after the TCP session has been successfully established. It is used to begin BGP protocol negotiation.
The OPEN message tells the neighbor:
Who am I?
Which AS do I belong to?
What BGP version do I support?
What hold time am I proposing?
What BGP capabilities do I support?
1. OPEN Message Information
An OPEN message includes important information such as:
2. UPDATE Message
The UPDATE message is the most important BGP message for routing information exchange.
It is used to:
- Advertise new routes
- Advertise path attributes
- Withdraw existing routes
- Modify routing information
Information Carried in an UPDATE
A BGP UPDATE can contain:
3. KEEPALIVE Message
A KEEPALIVE message confirms that the BGP peer is still operational.
It is also used during initial session establishment after the OPEN message exchange.
Packet flow:
After the session reaches Established, KEEPALIVE messages continue periodically.
Purpose of KEEPALIVE
KEEPALIVE messages do not carry routing information.
KEEPALIVE messages are used to:
4. NOTIFICATION Message
A NOTIFICATION message indicates that a serious BGP error has occurred.
After sending or receiving certain NOTIFICATION messages, the BGP session is normally terminated.
Packet flow:
NOTIFICATION Purpose
It helps identify why a BGP session was terminated.
The message communicates:
5. ROUTE-REFRESH Message
The ROUTE-REFRESH message allows a router to request that a peer resend routing information without completely resetting the BGP session.
This is especially useful after:
- Route-map changes
- Prefix-list changes
- Community policy changes
- AS-path policy changes
- Inbound routing policy change
Route Refresh Process
Why ROUTE-REFRESH Is Important
Without route-refresh capability, an administrator might need to reset the BGP session to force routes to be resent.
A hard reset:
- Drops the TCP session
- Drops BGP adjacency
- Withdraws routes temporarily
- Forces full session establishment again
This can cause traffic disruption.
Route Refresh allows policy re-evaluation with much less operational impact.
5. BGP Finite State Machine (FSM)
The BGP Finite State Machine (FSM) defines the sequence of states a BGP router passes through while attempting to establish and maintain a neighbor relationship.
A BGP session does not immediately become operational after the neighbor is configured.
Instead, BGP moves through a series of states:
Figure 6 - BGP Neighbour state
Once the session reaches Established, BGP peers can exchange routing information using UPDATE messages.
1. IDLE State
The Idle state is the initial state of the BGP finite state machine. In this state, the router has no active BGP session with the configured neighbor.
When BGP starts, or when an existing BGP session fails, the neighbor relationship returns to the Idle state.
In the Idle state, BGP:
- Initializes resources required for the neighbor session.
- Resets relevant BGP timers.
- Starts the ConnectRetry timer.
- Prepares to establish a TCP connection to the neighbor.
- Does not exchange BGP routing information.
- Moves toward the Connect state when a connection attempt begins.
Important Point
If a BGP session encounters a serious error or fails during establishment, the router can return to the Idle state and restart the neighbor-establishment process.
Common Causes of Persistent Idle State
- Possible causes include:
- Neighbor administratively shutdown
- Incorrect BGP configuration
- Peer disabled
- Severe transport failure
- Maximum-prefix shutdown condition
- Authentication problem
- Resource issue
2. Connect State
The Connect state is next, where the router attempts to initiate a TCP connection with the BGP peer. If the TCP handshake succeeds, the session moves to the OpenSent state, during which the router sends an OPEN message and waits for a corresponding OPEN message from the neighbor.
TCP Connection in BGP
Before BGP messages are exchanged, TCP must establish successfully.
What happens in the CONNECT state?
- BGP starts the TCP connection toward the neighbor.
- The router listens for an incoming TCP connection from the peer.
- If the TCP session is established successfully, BGP sends an OPEN message.
- The BGP state then moves to OPENSENT.
- If the TCP connection fails, BGP may move to the ACTIVE state and retry the connection.
Common Problems in CONNECT State
If BGP stays in Connect, check:
- Interface status
- IP…
