BGP Reference

bgp routing networking

Border Gateway Protocol — the path-vector exterior gateway protocol (EGP) that routes between autonomous systems and powers the internet. Uses TCP port 179 for reliable peer communication.


Key Characteristics

PropertyValue
TypePath-Vector EGP
TransportTCP port 179
Admin Distance (eBGP)20
Admin Distance (iBGP)200
MetricPath attributes (not a single metric)
AuthenticationMD5 (TCP option 19)
MulticastNone — unicast TCP sessions
Current VersionBGP-4 (RFC 4271)
Address Family SupportIPv4, IPv6, VPNv4, VPNv6, EVPN, and more via MP-BGP (RFC 4760)

eBGP vs iBGP

PropertyeBGPiBGP
RelationshipPeers in different AS numbersPeers in the same AS number
Admin Distance20200
TTL1 (default — requires direct connection or ebgp-multihop)255
Next-Hop BehaviorNext-hop set to advertising router’s IPNext-hop preserved (not changed) — must be reachable via IGP
AS_PATH Loop PreventionDrops routes containing own ASN in AS_PATHN/A (same AS — AS_PATH can’t detect loops)
iBGP Split-HorizonN/ARoutes from one iBGP peer are NOT re-advertised to another iBGP peer
Full Mesh RequirementNoYes (or use Route Reflectors / Confederations)
LOCAL_PREFNot carried across eBGP (set on receipt)Carried between iBGP peers
MEDSent to eBGP peer (optional)Carried between iBGP peers

iBGP Split-Horizon Rule

The rule: A route learned from an iBGP peer is never advertised to another iBGP peer.

Why it exists: Within an AS, all routers share the same ASN, so AS_PATH cannot detect routing loops. Without this rule, iBGP routes could loop indefinitely between iBGP peers.

The consequence: Every iBGP speaker must receive every route directly from the originator — hence the full-mesh requirement.

Solutions to the Full-Mesh Problem

SolutionHow It WorksScalabilityTrade-off
Full MeshEvery iBGP router peers with every otherO(n^2) — breaks down past ~20 routersSimple but doesn’t scale
Route ReflectorsDesignated RR reflects routes to clients, bypassing split-horizonExcellent — hierarchical RR clustersSingle point of failure if not redundant
ConfederationsAS split into sub-ASes that use eBGP rules internallyGood for very large ASesComplex to configure and troubleshoot

Route Reflectors in Detail

ConceptDescription
Route Reflector (RR)An iBGP peer that is allowed to re-advertise iBGP routes to other iBGP peers
RR ClientA peer configured under the RR — receives reflected routes
Non-ClientA peer not configured as a client — normal iBGP full-mesh rules apply between non-clients
Cluster IDIdentifies the RR cluster — used for loop prevention (if a route’s CLUSTER_LIST contains the local cluster-id, it is dropped)
ORIGINATOR_IDSet by the RR to the Router ID of the route originator — prevents routes from being reflected back to the originator

Reflection rules:

  • Route from client → reflect to all clients and non-clients
  • Route from non-client → reflect to clients only
  • Route from eBGP → reflect to all clients and non-clients

BGP Message Types

MessagePurposeKey FieldsWhen Sent
OPENEstablish peering sessionBGP version, local ASN, Hold Time, Router ID, capabilities (MP-BGP, 4-byte ASN, route refresh)After TCP 3-way handshake
UPDATEAdvertise new routes or withdraw old onesWithdrawn Routes, Path Attributes, NLRI (prefixes)Whenever routing changes occur
KEEPALIVEMaintain session — confirms peer is alive(empty — just the header)Every 60s by default (1/3 of Hold Time)
NOTIFICATIONReport a fatal error and close the sessionError Code, Error Subcode, DataOn error — session tears down immediately

BGP Neighbor States

StateWhat’s HappeningCommon Stuck Reasons
IdleNo connection attempt. Waiting for a Start event.No route to peer, peer IP misconfigured, AS mismatch in config
ConnectTCP SYN sent, waiting for TCP connection to completeFirewall blocking TCP 179, interface down
ActiveTCP connection failed, retrying. Despite the name, this is a problem state.ACL/firewall blocking TCP 179 in one or both directions, wrong source IP
OpenSentTCP connected, OPEN message sent, waiting for peer’s OPENPeer configured with wrong ASN, capability mismatch
OpenConfirmOPEN received, parameters validated, waiting for KEEPALIVEHold time mismatch, authentication failure
EstablishedPeering up — UPDATE messages are exchangedN/A (this is the goal state)

Key insight: If a peer is bouncing between Idle and Active, the most common cause is TCP connectivity failure to port 179 — check firewalls, routing to the peer address, and that the source interface is correct.


Default Timers

TimerDefault ValuePurpose
Keepalive60 secondsInterval between KEEPALIVE messages
Hold Time180 seconds (3x Keepalive)If no KEEPALIVE or UPDATE received in this time, peer is declared dead
Connect Retry120 secondsTime to wait before retrying a failed TCP connection
Advertisement Interval (eBGP)30 secondsMinimum time between UPDATE messages to eBGP peers
Advertisement Interval (iBGP)0 seconds (Cisco IOS)Minimum time between UPDATE messages to iBGP peers
MRAI (Minimum Route Advertisement Interval)30s eBGP / 5s iBGPRate-limits UPDATE frequency per prefix (implementation varies)

Hold Time negotiation: During OPEN exchange, both sides propose a Hold Time. The lower value is used. A Hold Time of 0 disables keepalives (not recommended).


Path Attributes

Attribute Categories

CategoryMeaningMust Support?Must Forward?
Well-Known MandatoryEvery BGP speaker must recognize and include in every UPDATEYesYes
Well-Known DiscretionaryEvery BGP speaker must recognize, but may or may not includeYesYes
Optional TransitiveMay not be recognized, but must be forwarded to peersNoYes
Optional Non-TransitiveMay not be recognized, and may be droppedNoNo

Attribute Reference

AttributeCodeCategoryDescription
ORIGIN1Well-Known MandatoryHow the route was introduced: i (IGP), e (EGP), ? (incomplete/redistributed)
AS_PATH2Well-Known MandatoryOrdered list of AS numbers the route has traversed. Used for loop prevention and path selection.
NEXT_HOP3Well-Known MandatoryIP address of the next-hop to reach the prefix. eBGP sets this to self; iBGP preserves it.
LOCAL_PREF5Well-Known DiscretionaryPreference value shared within an AS. Higher = preferred. Default: 100. Only in iBGP.
ATOMIC_AGGREGATE6Well-Known DiscretionaryIndicates that the originator aggregated routes and some AS_PATH info was lost.
AGGREGATOR7Optional TransitiveRouter ID and ASN of the router that performed route aggregation.
COMMUNITY8Optional Transitive32-bit tag for grouping routes and applying policy. Format: ASN:Value.
MED4Optional Non-TransitiveMulti-Exit Discriminator — suggests preferred entry point into an AS. Lower = preferred. Compared only between routes from the same neighbor AS.
ORIGINATOR_ID9Optional Non-TransitiveSet by Route Reflector — Router ID of the iBGP route originator. Loop prevention.
CLUSTER_LIST10Optional Non-TransitiveList of Route Reflector Cluster IDs the route has passed through. Loop prevention.
WEIGHTN/ACisco proprietary (local)Local to the router — not advertised. Higher = preferred. Default: 0 (32768 for locally originated).

Best Path Selection Algorithm

BGP evaluates paths in this order — first match wins. All criteria are only compared if the previous criteria is a tie.

StepCriteriaPreferredNotes
0Valid next-hopReachableRoute is discarded entirely if next-hop is unreachable
1Highest WEIGHTHigherCisco-only, local to the router, not advertised
2Highest LOCAL_PREFHigherShared within the AS via iBGP. Default: 100.
3Locally originatedLocalPrefer routes originated locally (network, redistribute, aggregate)
4Shortest AS_PATHShorterFewer AS hops = preferred. Can be disabled with bgp bestpath as-path ignore.
5Lowest ORIGIN typeIGP (i) < EGP (e) < Incomplete (?)IGP is most preferred
6Lowest MEDLowerOnly compared between routes from the same neighbor AS (by default)
7eBGP over iBGPeBGPPrefer externally learned routes over internally learned
8Lowest IGP metric to next-hopLowerClosest exit point (hot-potato routing)
9Oldest eBGP routeOlderStability — prefer the route that has been around longest
10Lowest Router IDLowerTiebreaker — peer with lowest RID wins
11Lowest neighbor IPLowerFinal tiebreaker if multiple paths from the same router

Practical takeaway: In most enterprise environments, you control path selection with LOCAL_PREF (inbound preference within your AS) and AS_PATH prepending or MED (outbound preference signaled to neighbors).


Communities

Communities are 32-bit tags attached to routes for applying policy at scale. Format: ASN:Value (e.g., 65000:100).

Well-Known Communities

CommunityValueMeaning
NO_EXPORT65535:65281Do not advertise beyond the local AS (or confederation sub-AS)
NO_ADVERTISE65535:65282Do not advertise to any peer at all
NO_EXPORT_SUBCONFED65535:65283Do not advertise outside the local confederation sub-AS
NOPEER65535:65284Do not advertise to bilateral eBGP peers (RFC 3765)

Standard vs Extended vs Large

TypeSizeFormatUse Case
Standard32-bitASN:ValueGeneral policy tagging
Extended64-bitType:Admin:ValueVPNv4 Route Targets, Site of Origin
Large96-bitGlobal:Local1:Local24-byte ASN support (RFC 8092)

Address Families (MP-BGP)

Multiprotocol BGP (RFC 4760) extends BGP to carry routes for multiple protocols using Address Family Identifiers (AFI) and Subsequent AFI (SAFI).

AFI/SAFIDescriptionCommon Use
IPv4 UnicastStandard IPv4 routingDefault BGP operation
IPv6 UnicastIPv6 routingDual-stack environments
VPNv4 UnicastMPLS L3VPN IPv4 routesService provider VPNs, carries Route Distinguisher + Route Target
VPNv6 UnicastMPLS L3VPN IPv6 routesIPv6 over MPLS VPN
L2VPN EVPNEthernet VPNVXLAN fabrics, data center overlays
IPv4 MulticastMulticast RPF routesMulticast source routing

Next-Hop Behavior

This is one of the most common sources of confusion and broken routing with iBGP.

ScenarioNext-Hop Set ToGotcha
eBGP → localAdvertising peer’s interface IPMust be directly connected (or use ebgp-multihop)
eBGP → iBGP redistributionOriginal eBGP next-hop preservediBGP peers must be able to reach the eBGP next-hop via IGP
iBGP → iBGPUnchanged (original next-hop)Next-hop must be in IGP or the route is invalid
Fix: next-hop-selfChanged to advertising router’s IPCommon on iBGP peerings to ensure reachability

Rule of thumb: Always configure next-hop-self on iBGP peers unless you have a specific reason not to (e.g., the eBGP next-hop is redistributed into your IGP).


Troubleshooting

SymptomLikely CauseWhat to Check
Peer stuck in IdleNo route to peer IP, or BGP process not startedRouting table for peer IP, BGP config, neighbor statement
Peer stuck in ActiveTCP port 179 blocked or source interface unreachableFirewall rules (both directions), update-source config, ACLs
Peer stuck in OpenSentOPEN message rejected — ASN or capability mismatchRemote AS number in config, 2-byte vs 4-byte ASN, address-family activation
Peer flappingUnstable link, route oscillation, or hold timer too aggressiveInterface counters, hold/keepalive timers, BFD if enabled
Routes received but not in RIBNext-hop unreachable or filtered by inbound policyshow bgp to verify next-hop, check route-maps/prefix-lists, next-hop-self
Routes in RIB but not advertisedOutbound policy filtering, or iBGP split-horizonExport policy, verify full-mesh/RR config, check neighbor activate
Routes not in table despite Established peerAddress family not activated for this peerneighbor activate under the correct address-family
MED comparison unexpectedMED only compared between routes from same neighbor ASEnable bgp always-compare-med if cross-AS MED comparison needed
Asymmetric routingLOCAL_PREF or AS_PATH differences between inbound pathsCheck LOCAL_PREF on both paths, verify AS_PATH prepending