Loading learning content...
Every time you access a website hosted on a different continent, stream video from a content delivery network, or use a cloud service, your traffic traverses multiple autonomous systems—each operated by different organizations with their own policies and priorities. The Border Gateway Protocol (BGP) is the glue that binds these disparate networks into a cohesive, functioning Internet.
At the heart of BGP's operation lies the concept of the BGP session—a persistent, reliable connection between two BGP speakers that forms the foundation for all routing information exchange. Unlike interior gateway protocols that may use broadcast or multicast mechanisms, BGP relies on explicit, point-to-point sessions established over TCP. Understanding BGP sessions is fundamental to understanding how the Internet routes traffic at a global scale.
By the end of this page, you will understand the complete architecture of BGP session establishment, the role of TCP as BGP's transport, the distinction between eBGP and iBGP sessions, the BGP finite state machine, message types used in session management, and the operational considerations for maintaining stable BGP peerings in production networks.
BGP's choice of TCP as its transport protocol is a deliberate architectural decision that distinguishes it from most other routing protocols. While protocols like OSPF and IS-IS implement their own reliability mechanisms directly over IP, and RIP uses UDP with application-layer timers, BGP leverages TCP's mature, battle-tested reliability services.
The Rationale for TCP:
BGP operates in an environment where routing updates must be delivered reliably across potentially unreliable network paths. When a BGP router announces a new prefix or withdraws an existing one, that information must reach its peer without corruption, duplication, or loss. TCP provides this reliability without BGP needing to implement its own acknowledgment and retransmission logic.
Moreover, BGP sessions often traverse multiple router hops—particularly in eBGP scenarios where peers may be separated by intermediate networks. TCP's end-to-end reliability guarantees work regardless of the underlying network topology, making it ideal for inter-domain routing.
| Aspect | BGP over TCP | Why It Matters |
|---|---|---|
| Port | TCP Port 179 | Well-known port enables firewall configuration and security auditing |
| Reliability | TCP handles acknowledgments, retransmissions | BGP messages never lost in transit—critical for routing consistency |
| Ordering | TCP guarantees in-order delivery | Route updates applied in sequence—prevents transient routing anomalies |
| Flow Control | TCP windowing manages transmission rate | Prevents overwhelming peers during large routing table dumps |
| Session State | TCP connection state mirrors session state | Connection loss instantly signals session failure |
TCP Connection Establishment:
BGP session establishment begins with a standard TCP three-way handshake. One BGP speaker initiates a TCP connection to port 179 on its peer. The BGP implementation can be configured to either:
In practice, both peers typically attempt to connect simultaneously. BGP resolves this collision by selecting the connection initiated by the peer with the higher BGP identifier (router ID). The other connection is closed gracefully.
Once the TCP connection is established, BGP-level session establishment begins with the exchange of OPEN messages. The TCP connection remains established for the lifetime of the BGP session—which can persist for days, weeks, or even months in stable networks.
Unlike protocols that periodically re-establish connections, a healthy BGP session maintains its TCP connection indefinitely. This persistence reduces overhead and improves stability. However, it also means that when TCP connectivity is disrupted (even briefly), the entire BGP session may reset—potentially triggering widespread routing reconvergence.
BGP sessions are established between BGP peers (also called BGP neighbors). The nature of the peering relationship profoundly affects BGP's behavior, including route propagation rules, attribute handling, and operational requirements. Understanding peer relationships is essential for both network design and troubleshooting.
External BGP (eBGP) Sessions:
eBGP sessions connect BGP speakers in different Autonomous Systems (ASes). These sessions form the inter-domain routing fabric of the Internet. Key characteristics include:
Internal BGP (iBGP) Sessions:
iBGP sessions connect BGP speakers within the same Autonomous System. These sessions distribute external routes throughout the AS and enable consistent egress point selection. Key characteristics include:
The iBGP Full Mesh Requirement:
The split-horizon rule for iBGP (routes from one iBGP peer not advertised to other iBGP peers) creates a critical design requirement: every BGP speaker in an AS must have iBGP sessions with every other BGP speaker. This full mesh ensures that routing information is distributed completely.
For an AS with n BGP speakers, this requires n(n-1)/2 iBGP sessions. With 5 routers, you need 10 sessions. With 100 routers, you need 4,950 sessions. This O(n²) scaling becomes prohibitive in large networks.
Solutions to the Full Mesh Problem:
Both mechanisms will be explored in the policy routing page, as they fundamentally alter route propagation behavior.
The default TTL of 1 for eBGP sessions requires peers to be directly connected. When eBGP peers are separated by multiple hops (common in Internet Exchange Points or loopback-based peering), the 'ebgp-multihop' configuration increases the TTL. This configuration must be applied carefully, as it relaxes an important security control.
BGP session establishment follows a rigorous state machine defined in RFC 4271. Understanding this state machine is crucial for diagnosing session establishment failures and interpreting BGP status outputs.
The BGP Finite State Machine (FSM) defines six states that every BGP session transitions through:
1. Idle State
The initial state for all BGP sessions. In this state:
2. Connect State
The router is attempting to establish a TCP connection:
3. Active State
TCP connection attempt failed; trying again:
4. OpenSent State
TCP established; OPEN message sent; waiting for peer's OPEN:
5. OpenConfirm State
OPEN exchange complete; waiting for KEEPALIVE confirmation:
6. Established State
The session is fully operational:
Troubleshooting with the FSM:
Understanding where a session is stuck reveals the nature of the problem:
| State Stuck In | Likely Cause | Diagnostic Approach |
|---|---|---|
| Idle | Admin disabled, access-list blocking | Check configuration, route to peer |
| Connect/Active | TCP connectivity issue | Verify IP reachability, port 179 access, firewalls |
| OpenSent | Peer not responding with OPEN | Check peer configuration, version compatibility |
| OpenConfirm | Parameter mismatch in OPEN | Verify AS numbers, hold times, authentication |
Session Oscillation:
A session that repeatedly transitions between states (flapping) causes route instability affecting all downstream routers. BGP implementations include dampening mechanisms:
Commands like 'show ip bgp neighbor' (Cisco) or 'show bgp neighbor' (Juniper) display the current FSM state. A healthy session shows 'Established' with accumulating uptime. Sessions stuck in other states indicate specific categories of problems that require targeted troubleshooting.
BGP uses four message types to establish sessions, exchange routes, and maintain connectivity. Each message has a common header followed by message-specific fields.
Common BGP Header (19 bytes minimum):
+-------------------------------------------+
| Marker (16 bytes - all 1s for auth/sync) |
+-------------------------------------------+
| Length (2 bytes) | Type (1 byte) |
+-------------------------------------------+
| Message Body (variable) |
+-------------------------------------------+
The marker field was originally designed for authentication but is now always all 1s. The length field includes the header itself. The type field identifies one of four message types:
| Type | Name | Purpose | When Used |
|---|---|---|---|
| 1 | OPEN | Establishes session, negotiates parameters | Once during session establishment |
| 2 | UPDATE | Advertises or withdraws routes | Throughout session lifetime |
| 3 | NOTIFICATION | Reports errors, terminates session | On error or administrative close |
| 4 | KEEPALIVE | Maintains session liveness | Periodically (default: every 60s) |
1. OPEN Message
The OPEN message initiates the BGP session and contains critical parameters:
The Hold Time negotiation is critical: both peers send their preferred hold time, and the minimum of the two values is used. A hold time of 0 means keepalives are disabled (used only in special cases).
2. UPDATE Message
The UPDATE message carries routing information:
A single UPDATE can announce multiple prefixes (sharing the same attributes) and withdraw multiple other prefixes. BGP implementations optimize by batching related updates.
3. NOTIFICATION Message
The NOTIFICATION message reports errors and always terminates the session:
Common error codes include Message Header Error, OPEN Message Error, UPDATE Message Error, Hold Timer Expired, Finite State Machine Error, and Cease (administrative shutdown).
4. KEEPALIVE Message
The simplest BGP message—just the 19-byte header with type 4:
KEEPALIVEs serve as a heartbeat, detecting TCP connectivity issues that might not trigger immediate TCP disconnection.
The default hold time of 90 seconds and keepalive interval of 30 seconds (90/3) provide a balance between responsiveness and stability. Reducing the hold time detects failures faster but increases the risk of false positives during network congestion. Some high-frequency trading environments use BFD (Bidirectional Forwarding Detection) for sub-second failure detection rather than reducing BGP timers.
Let's trace through the complete sequence of establishing a BGP session between two routers—Router A (AS 65001, IP 10.0.0.1) and Router B (AS 65002, IP 10.0.0.2).
Phase 1: TCP Connection Establishment
Router A (10.0.0.1) Router B (10.0.0.2)
| |
|------- SYN (dst:179) ------->|
|<------ SYN-ACK ------------- |
|------- ACK ----------------->|
| |
| TCP Connection Established |
Both routers may initiate connections simultaneously. If both succeed, the router with the higher BGP identifier keeps the connection it initiated; the other is closed.
Phase 2: OPEN Message Exchange
Router A Router B
| |
|------- OPEN ----------------->|
| Version: 4 |
| My AS: 65001 |
| Hold Time: 90 |
| BGP ID: 1.1.1.1 |
| Capabilities: [...] |
| |
|<------ OPEN -----------------||
| Version: 4 |
| My AS: 65002 |
| Hold Time: 180 |
| BGP ID: 2.2.2.2 |
| Capabilities: [...] |
Each router validates the peer's OPEN message:
The negotiated hold time is min(90, 180) = 90 seconds.
Phase 3: KEEPALIVE Confirmation
Router A Router B
| |
|------- KEEPALIVE ------------>|
|<------ KEEPALIVE -------------||
| |
| Session Established! |
The KEEPALIVE messages confirm that both sides successfully processed the OPEN messages and are ready for UPDATE exchange.
Phase 4: Initial Route Exchange
Router A Router B
| |
|------- UPDATE --------------->|
| (Full BGP table from A) |
|<------ UPDATE ----------------||
| (Full BGP table from B) |
| |
| Steady State: Incremental |
| Updates and Periodic |
| KEEPALIVEs |
After establishment, each router sends its complete BGP table (subject to outbound policies). This initial exchange can take significant time for routers with large tables (hundreds of thousands of routes). Once complete, only incremental updates are exchanged.
BGP capabilities (RFC 5492) allow routers to negotiate optional features: 4-byte AS numbers, multiprotocol extensions (IPv6, VPNs), route refresh, graceful restart, and more. If a required capability is missing, the session may still establish but with reduced functionality. Capability mismatches can cause subtle operational problems.
Session Termination Scenarios:
BGP sessions terminate through one of several mechanisms:
| Termination Type | Mechanism | Impact |
|---|---|---|
| Administrative Shutdown | NOTIFICATION (Cease, Admin Shutdown) | Graceful; peer immediately reconverges |
| Hold Timer Expiry | NOTIFICATION (Hold Timer Expired) | Indicates connectivity loss; routes withdrawn |
| Error Condition | NOTIFICATION (appropriate error) | May require investigation; check error code |
| TCP Reset | TCP RST packet | May indicate firewall issue or peer crash |
| Graceful Restart | Peer failure with restart capability | Routes retained temporarily; session re-established |
Graceful Restart (RFC 4724):
Traditional BGP session loss causes immediate withdrawal of all routes learned from that peer—potentially causing significant traffic disruption. Graceful Restart addresses this:
Graceful Restart is critical for planned maintenance—restarting BGP processes without causing traffic loss.
Proper BGP session configuration is essential for security, stability, and optimal performance. This section covers key configuration parameters and best practices.
Essential Configuration Parameters:
1. Neighbor Specification
BGP requires explicit configuration of each peer:
router bgp 65001
neighbor 10.0.0.2 remote-as 65002 ! eBGP peer
neighbor 192.168.1.2 remote-as 65001 ! iBGP peer
2. Authentication (MD5)
BGP session authentication prevents unauthorized peers:
neighbor 10.0.0.2 password SECRET_KEY
MD5 authentication signs each TCP segment with a shared secret. While not cryptographically strong by modern standards, it remains widely used and provides protection against casual attacks and misconfigurations.
3. Source Address Binding
For iBGP and multihop eBGP, binding sessions to loopback addresses improves resilience:
neighbor 10.0.0.2 update-source Loopback0
neighbor 10.0.0.2 ebgp-multihop 2
Loopback-based sessions survive individual link failures as long as any path exists.
4. Timer Tuning
neighbor 10.0.0.2 timers 10 30 ! keepalive 10s, hold 30s
Shorter timers detect failures faster but increase false positive risk.
5. Maximum Prefix Protection
Prevents a peer from overwhelming your router:
neighbor 10.0.0.2 maximum-prefix 100000 80 restart 15
This configuration:
| Parameter | Default | Recommended Range | Purpose |
|---|---|---|---|
| Hold Time | 90 seconds | 15-180 seconds | Failure detection sensitivity |
| Keepalive Interval | 30 seconds | 5-60 seconds | Session heartbeat frequency |
| Connect Retry | 120 seconds | 30-120 seconds | Retry interval after failure |
| Advertisement Interval | 30s (eBGP), 0s (iBGP) | 5-30 seconds | Batching of updates |
| Maximum Prefix | Unlimited | 1.5x expected prefixes | Table overflow protection |
Production Best Practices:
Always Use Authentication: Even simple MD5 prevents accidental peering and basic attacks
Use Loopback Addresses for iBGP: Multiple physical paths = resilient sessions
Set Maximum Prefix Limits: Protect against misconfigurations and hijacking attempts
Configure Appropriate Timers: Balance failure detection speed against stability
Enable Logging and SNMP Traps: Monitor session state changes
Document Peering Configurations: Track AS numbers, IP addresses, and policies
Use Route Filtering: Never accept or advertise default routes accidentally
Consider BFD for Fast Failure Detection: Sub-second failure detection without aggressive BGP timers
BGP sessions carrying Internet routing are critical infrastructure. Beyond MD5 authentication, implement access control lists to permit only known peer addresses to TCP port 179. Consider RPKI for route origin validation. Never accept more prefixes than expected from a peer, and always filter both inbound and outbound routes.
Effective BGP session monitoring enables proactive maintenance and rapid problem resolution. This section covers diagnostic approaches for common session issues.
Key Metrics to Monitor:
Diagnostic Command Patterns (Cisco IOS):
! View all BGP neighbors and their states
show ip bgp summary
! Detailed information about a specific neighbor
show ip bgp neighbor 10.0.0.2
! View BGP table for specific prefix
show ip bgp 192.0.2.0/24
! Debug BGP session establishment (use carefully!)
debug ip bgp
Common Problems and Solutions:
| Symptom | Likely Cause | Diagnostic Steps | Solution |
|---|---|---|---|
| Session stuck in Idle | Admin shutdown or no route to peer | Check config, ping peer | Enable neighbor, verify routing |
| Session stuck in Active | TCP connection failing | Verify port 179 access, no ACL blocking | Fix firewall rules, verify IP connectivity |
| Session stuck in OpenSent | Peer not sending OPEN | Check peer configuration | Ensure peer has us configured correctly |
| Session stuck in OpenConfirm | Parameter mismatch | Compare OPEN parameters, auth | Fix AS number, hold time, password |
| Session flapping | Unstable link or timer mismatch | Check interface errors, timer config | Fix physical issues, tune timers |
| NOTIFICATION received | Protocol error or policy | Check error code in logs | Address specific error condition |
Understanding NOTIFICATION Error Codes:
NOTIFICATION messages provide diagnostic information through error codes:
| Error Code | Meaning | Common Subcodes |
|---|---|---|
| 1 | Message Header Error | Connection Not Synchronized, Bad Length |
| 2 | OPEN Message Error | Unsupported Version, Bad Peer AS, Bad BGP ID |
| 3 | UPDATE Message Error | Malformed Attribute, Invalid Origin, Invalid NH |
| 4 | Hold Timer Expired | (no subcodes) |
| 5 | Finite State Machine Error | Unexpected message in current state |
| 6 | Cease | Max Prefixes, Admin Shutdown, Peer Deconfigured |
Example: Diagnosing a Session Problem
Scenario: BGP session between R1 (AS 65001) and R2 (AS 65002) won't establish.
show ip bgp neighbor 10.0.0.2 → Shows "Active"telnet 10.0.0.2 179 → Connection refusedshow access-list → Found ACL blocking TCP 179Configure SNMP traps or syslog alerts for BGP session state changes. Tools like Nagios, Zabbix, or modern observability platforms can track session uptime, prefix counts, and automatically alert on anomalies. Catching problems before they cause traffic impact is always preferable to reactive troubleshooting.
BGP sessions form the foundation of all inter-domain routing communication. Understanding session mechanics is essential for designing, operating, and troubleshooting networks that participate in Internet routing.
What's Next:
With a solid understanding of BGP session mechanics, we'll explore how BGP advertises routes in the next page. You'll learn about UPDATE message structure, path attributes, route announcement and withdrawal, and how BGP efficiently propagates routing information across the Internet.
You now understand the complete architecture of BGP sessions—from TCP transport through the finite state machine to operational configuration and troubleshooting. This foundation is essential for understanding route advertisement, selection, and policy mechanisms covered in subsequent pages.